Search in sources :

Example 6 with AbstractHttp11Protocol

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));
}
Also used : ByteArrayOutputStream(java.io.ByteArrayOutputStream) ByteBuffer(java.nio.ByteBuffer) AbstractHttp11Protocol(org.apache.coyote.http11.AbstractHttp11Protocol) Test(org.junit.Test)

Example 7 with AbstractHttp11Protocol

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;
            }
    }
}
Also used : ByteBuffer(java.nio.ByteBuffer) AbstractHttp11Protocol(org.apache.coyote.http11.AbstractHttp11Protocol)

Example 8 with AbstractHttp11Protocol

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()));
        }
    }
}
Also used : ProtocolHandler(org.apache.coyote.ProtocolHandler) Compression(org.springframework.boot.web.server.Compression) AbstractHttp11Protocol(org.apache.coyote.http11.AbstractHttp11Protocol)

Example 9 with AbstractHttp11Protocol

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;
}
Also used : SpringApplication(org.springframework.boot.SpringApplication) TomcatEmbeddedServletContainerFactory(org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainerFactory) SpringBootApplication(org.springframework.boot.autoconfigure.SpringBootApplication) AbstractHttp11Protocol(org.apache.coyote.http11.AbstractHttp11Protocol) Bean(org.springframework.context.annotation.Bean) TomcatConnectorCustomizer(org.springframework.boot.context.embedded.tomcat.TomcatConnectorCustomizer) TomcatEmbeddedServletContainerFactory(org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainerFactory) AbstractHttp11Protocol(org.apache.coyote.http11.AbstractHttp11Protocol) Bean(org.springframework.context.annotation.Bean)

Example 10 with AbstractHttp11Protocol

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;
}
Also used : SpringApplication(org.springframework.boot.SpringApplication) TomcatEmbeddedServletContainerFactory(org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainerFactory) SpringBootApplication(org.springframework.boot.autoconfigure.SpringBootApplication) AbstractHttp11Protocol(org.apache.coyote.http11.AbstractHttp11Protocol) Bean(org.springframework.context.annotation.Bean) TomcatConnectorCustomizer(org.springframework.boot.context.embedded.tomcat.TomcatConnectorCustomizer) TomcatEmbeddedServletContainerFactory(org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainerFactory) AbstractHttp11Protocol(org.apache.coyote.http11.AbstractHttp11Protocol) Bean(org.springframework.context.annotation.Bean)

Aggregations

AbstractHttp11Protocol (org.apache.coyote.http11.AbstractHttp11Protocol)16 ProtocolHandler (org.apache.coyote.ProtocolHandler)7 ByteBuffer (java.nio.ByteBuffer)5 Connector (org.apache.catalina.connector.Connector)4 TomcatConnectorCustomizer (org.springframework.boot.context.embedded.tomcat.TomcatConnectorCustomizer)3 TomcatEmbeddedServletContainerFactory (org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainerFactory)3 Bean (org.springframework.context.annotation.Bean)3 IOException (java.io.IOException)2 SpringApplication (org.springframework.boot.SpringApplication)2 SpringBootApplication (org.springframework.boot.autoconfigure.SpringBootApplication)2 MultipartConfigElement (jakarta.servlet.MultipartConfigElement)1 ServletContext (jakarta.servlet.ServletContext)1 ServletException (jakarta.servlet.ServletException)1 Dynamic (jakarta.servlet.ServletRegistration.Dynamic)1 HttpServlet (jakarta.servlet.http.HttpServlet)1 HttpServletRequest (jakarta.servlet.http.HttpServletRequest)1 HttpServletResponse (jakarta.servlet.http.HttpServletResponse)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 File (java.io.File)1 SocketException (java.net.SocketException)1