use of org.apache.coyote.http11.AbstractHttp11Protocol in project tomcat by apache.
the class TestLargeUpload method testLargePostRequest.
@Test
public void testLargePostRequest() throws Exception {
http2Connect(true);
((AbstractHttp11Protocol<?>) http2Protocol.getHttp11Protocol()).setAllowedTrailerHeaders(TRAILER_HEADER_NAME);
byte[] headersFrameHeader = new byte[9];
ByteBuffer headersPayload = ByteBuffer.allocate(128);
byte[] dataFrameHeader = new byte[9];
ByteBuffer dataPayload = ByteBuffer.allocate(bodySize);
byte[] trailerFrameHeader = new byte[9];
ByteBuffer trailerPayload = ByteBuffer.allocate(256);
buildPostRequest(headersFrameHeader, headersPayload, false, dataFrameHeader, dataPayload, null, trailerFrameHeader, trailerPayload, 3);
// Write the headers
writeFrame(headersFrameHeader, headersPayload);
// Body
ByteArrayOutputStream baos = new ByteArrayOutputStream();
for (int i = 0; i < bodyCount; i++) {
baos.write(dataFrameHeader);
baos.write(dataPayload.array(), dataPayload.arrayOffset(), dataPayload.limit());
}
os.write(baos.toByteArray());
os.flush();
// Trailers
writeFrame(trailerFrameHeader, trailerPayload);
done.await();
Assert.assertEquals(Integer.valueOf(bodySize * bodyCount), Integer.valueOf(read));
}
use of org.apache.coyote.http11.AbstractHttp11Protocol in project tomcat by apache.
the class TestHttp2Limits method doTestPostWithTrailerHeaders.
private void doTestPostWithTrailerHeaders(int maxTrailerCount, int maxTrailerSize, FailureMode failMode) throws Exception {
enableHttp2();
configureAndStartWebApplication();
((AbstractHttp11Protocol<?>) http2Protocol.getHttp11Protocol()).setAllowedTrailerHeaders(TRAILER_HEADER_NAME);
http2Protocol.setMaxTrailerCount(maxTrailerCount);
((AbstractHttp11Protocol<?>) http2Protocol.getHttp11Protocol()).setMaxTrailerSize(maxTrailerSize);
// Disable overhead protection for window update as it breaks some tests
http2Protocol.setOverheadWindowUpdateThreshold(0);
openClientConnection();
doHttpUpgrade();
sendClientPreface();
validateHttp2InitialResponse();
byte[] headersFrameHeader = new byte[9];
ByteBuffer headersPayload = ByteBuffer.allocate(128);
byte[] dataFrameHeader = new byte[9];
ByteBuffer dataPayload = ByteBuffer.allocate(256);
byte[] trailerFrameHeader = new byte[9];
ByteBuffer trailerPayload = ByteBuffer.allocate(256);
buildPostRequest(headersFrameHeader, headersPayload, false, dataFrameHeader, dataPayload, null, trailerFrameHeader, trailerPayload, 3);
// Write the headers
writeFrame(headersFrameHeader, headersPayload);
// Body
writeFrame(dataFrameHeader, dataPayload);
// Trailers
writeFrame(trailerFrameHeader, trailerPayload);
switch(failMode) {
case NONE:
{
parser.readFrame(true);
parser.readFrame(true);
parser.readFrame(true);
parser.readFrame(true);
String len = Integer.toString(256 + TRAILER_HEADER_VALUE.length());
Assert.assertEquals("0-WindowSize-[256]\n" + "3-WindowSize-[256]\n" + "3-HeadersStart\n" + "3-Header-[:status]-[200]\n" + "3-Header-[content-length]-[" + len + "]\n" + "3-Header-[date]-[" + DEFAULT_DATE + "]\n" + "3-HeadersEnd\n" + "3-Body-" + len + "\n" + "3-EndOfStream\n", output.getTrace());
break;
}
case STREAM_RESET:
{
// NIO2 can sometimes send window updates depending timing
skipWindowSizeFrames();
// the enhance your calm reset
if ("3-RST-[5]\n".equals(output.getTrace())) {
output.clearTrace();
parser.readFrame(true);
}
Assert.assertEquals("3-RST-[11]\n", output.getTrace());
break;
}
case CONNECTION_RESET:
{
// NIO2 can sometimes send window updates depending timing
skipWindowSizeFrames();
// This message uses i18n and needs to be used in a regular
// expression (since we don't know the connection ID). Generate the
// string as a regular expression and then replace '[' and ']' with
// the escaped values.
String limitMessage = sm.getString("http2Parser.headerLimitSize", "\\p{XDigit}++", "3");
limitMessage = limitMessage.replace("[", "\\[").replace("]", "\\]");
MatcherAssert.assertThat(output.getTrace(), RegexMatcher.matchesRegex("0-Goaway-\\[3\\]-\\[11\\]-\\[" + limitMessage + "\\]"));
break;
}
}
}
use of org.apache.coyote.http11.AbstractHttp11Protocol in project spring-boot by spring-projects.
the class TomcatServletWebServerFactory method customizeCompression.
private void customizeCompression(Connector connector) {
ProtocolHandler handler = connector.getProtocolHandler();
if (handler instanceof AbstractHttp11Protocol) {
AbstractHttp11Protocol<?> protocol = (AbstractHttp11Protocol<?>) handler;
Compression compression = getCompression();
protocol.setCompression("on");
protocol.setCompressionMinSize(compression.getMinResponseSize());
protocol.setCompressableMimeType(StringUtils.arrayToCommaDelimitedString(compression.getMimeTypes()));
if (getCompression().getExcludedUserAgents() != null) {
protocol.setNoCompressionUserAgents(StringUtils.arrayToCommaDelimitedString(getCompression().getExcludedUserAgents()));
}
}
}
use of org.apache.coyote.http11.AbstractHttp11Protocol in project spring-boot-examples by ityouknow.
the class FileUploadWebApplication method tomcatEmbedded.
// Tomcat large file upload connection reset
@Bean
public TomcatEmbeddedServletContainerFactory tomcatEmbedded() {
TomcatEmbeddedServletContainerFactory tomcat = new TomcatEmbeddedServletContainerFactory();
tomcat.addConnectorCustomizers((TomcatConnectorCustomizer) connector -> {
if ((connector.getProtocolHandler() instanceof AbstractHttp11Protocol<?>)) {
((AbstractHttp11Protocol<?>) connector.getProtocolHandler()).setMaxSwallowSize(-1);
}
});
return tomcat;
}
use of org.apache.coyote.http11.AbstractHttp11Protocol in project spring-boot-examples by ityouknow.
the class FastDFSApplication method tomcatEmbedded.
// Tomcat large file upload connection reset
@Bean
public TomcatEmbeddedServletContainerFactory tomcatEmbedded() {
TomcatEmbeddedServletContainerFactory tomcat = new TomcatEmbeddedServletContainerFactory();
tomcat.addConnectorCustomizers((TomcatConnectorCustomizer) connector -> {
if ((connector.getProtocolHandler() instanceof AbstractHttp11Protocol<?>)) {
((AbstractHttp11Protocol<?>) connector.getProtocolHandler()).setMaxSwallowSize(-1);
}
});
return tomcat;
}
Aggregations