Skip to content

Commit 4d03ad6

Browse files
committedAug 27, 2018
Fix EchoHandler missing response ContentLength
1 parent e8f5d36 commit 4d03ad6

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed
 

‎client/src/test/java/org/asynchttpclient/test/EchoHandler.java

+10
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import javax.servlet.http.HttpServletRequest;
2525
import javax.servlet.http.HttpServletResponse;
2626
import java.io.IOException;
27+
import java.nio.charset.StandardCharsets;
2728
import java.util.Enumeration;
2829

2930
import static io.netty.handler.codec.http.HttpHeaderNames.CONTENT_LENGTH;
@@ -69,6 +70,15 @@ public void handle(String pathInContext, Request request, HttpServletRequest htt
6970
httpResponse.sendRedirect(httpRequest.getHeader("X-redirect"));
7071
return;
7172
}
73+
if (headerName.startsWith("X-fail")) {
74+
byte[] body = "custom error message".getBytes(StandardCharsets.US_ASCII);
75+
httpResponse.addHeader(CONTENT_LENGTH.toString(), String.valueOf(body.length));
76+
httpResponse.setStatus(HttpServletResponse.SC_EXPECTATION_FAILED);
77+
httpResponse.getOutputStream().write(body);
78+
httpResponse.getOutputStream().flush();
79+
httpResponse.getOutputStream().close();
80+
return;
81+
}
7282
httpResponse.addHeader("X-" + headerName, httpRequest.getHeader(headerName));
7383
}
7484

0 commit comments

Comments
 (0)
Please sign in to comment.