mirror of
https://github.com/floci-io/floci.git
synced 2026-12-01 01:12:48 -05:00
test(apigatewayv2): drain the oversized HTTP fixture request (#5701)
Signed-off-by: Andre Kurait <akurait@amazon.com>
This commit is contained in:
1 parent
31d073fe60
commit
2ec88794b5
1 file changed
+17
+17
@@ -11,7 +11,9 @@ import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.OutputStream;
|
||||
import java.net.InetAddress;
|
||||
import java.net.InetSocketAddress;
|
||||
@@ -155,6 +157,21 @@ class WebSocketIntegrationInvokerHttpTargetTest {
|
||||
ServerSocket server = new ServerSocket(0, 1, InetAddress.getLoopbackAddress());
|
||||
Thread.ofVirtual().start(() -> {
|
||||
try (Socket socket = server.accept()) {
|
||||
socket.setSoTimeout(10_000);
|
||||
BufferedReader input = new BufferedReader(
|
||||
new InputStreamReader(socket.getInputStream(), StandardCharsets.ISO_8859_1));
|
||||
int contentLength = 0;
|
||||
String header;
|
||||
while ((header = input.readLine()) != null && !header.isEmpty()) {
|
||||
if (header.regionMatches(true, 0, "Content-Length:", 0, "Content-Length:".length())) {
|
||||
contentLength = Integer.parseInt(header.substring("Content-Length:".length()).trim());
|
||||
}
|
||||
}
|
||||
for (int i = 0; i < contentLength; i++) {
|
||||
if (input.read() == -1) {
|
||||
throw new IOException("Request ended before its body");
|
||||
}
|
||||
}
|
||||
OutputStream out = socket.getOutputStream();
|
||||
out.write(("HTTP/1.1 200 OK\r\nContent-Length: " + (10 * 1024 * 1024 + 1) + "\r\n\r\n")
|
||||
.getBytes(StandardCharsets.ISO_8859_1));
|
||||
|
||||
Reference in new issue
Block a user