ttomcat-1778514358873.zip-extract/apache-tomcat-11.0.18-src/test/org/apache/coyote/http2/TestLargeUpload.java

Path
ttomcat-1778514358873.zip-extract/apache-tomcat-11.0.18-src/test/org/apache/coyote/http2/TestLargeUpload.java
Status
scanned
Type
file
Name
TestLargeUpload.java
Extension
.java
Programming language
Java
Mime type
text/plain
File type
ASCII text, with CRLF line terminators
Tag

      
    
Rootfs path

      
    
Size
5854 (5.7 KB)
MD5
33eb76a97aa1e3879b02d35675baaa9f
SHA1
1886cac0290ea48bd892845b8eb901be9fa87511
SHA256
dbb33485076a14a37ce6764f3b8ddfc9a871c2050eb86a7eee7a0dd61cdb2b3f
SHA512

      
    
SHA1_git
9d1751dc25888f464066b9105e20b44e0df4fd7e
Is binary

      
    
Is text
True
Is archive

      
    
Is media

      
    
Is legal

      
    
Is manifest

      
    
Is readme

      
    
Is top level

      
    
Is key file

      
    
TestLargeUpload.java | 5.7 KB |

/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.coyote.http2; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.InputStream; import java.nio.ByteBuffer; import java.util.ArrayList; import java.util.Collection; import java.util.List; import java.util.concurrent.CountDownLatch; import jakarta.servlet.ServletException; import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpServletResponse; import org.junit.Assert; import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.Parameterized; import org.junit.runners.Parameterized.Parameter; import org.junit.runners.Parameterized.Parameters; import org.apache.catalina.Context; import org.apache.catalina.LifecycleException; import org.apache.catalina.startup.Tomcat; import org.apache.coyote.http11.AbstractHttp11Protocol; import org.apache.tomcat.util.net.TesterSupport; @RunWith(Parameterized.class) public class TestLargeUpload extends Http2TestBase { @Parameters(name = "{0}: {1} {2}]") public static Collection<Object[]> parameters() { Collection<Object[]> baseData = data(); List<Object[]> parameterSets = new ArrayList<>(); for (Object[] base : baseData) { parameterSets.add(new Object[] { base[0], base[1], "JSSE", Boolean.FALSE, "org.apache.tomcat.util.net.jsse.JSSEImplementation" }); parameterSets.add(new Object[] { base[0], base[1], "OpenSSL", Boolean.TRUE, "org.apache.tomcat.util.net.openssl.OpenSSLImplementation" }); parameterSets.add(new Object[] { base[0], base[1], "OpenSSL-FFM", Boolean.TRUE, "org.apache.tomcat.util.net.openssl.panama.OpenSSLImplementation" }); } return parameterSets; } @Parameter(2) public String connectorName; @Parameter(3) public boolean useOpenSSL; @Parameter(4) public String sslImplementationName; int bodySize = 13107; int bodyCount = 5; volatile int read = 0; CountDownLatch done = new CountDownLatch(1); @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, true, 3); buildTrailerHeaders(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)); } @Override protected void configureAndStartWebApplication() throws LifecycleException { Tomcat tomcat = getTomcatInstance(); // Retain '/simple' url-pattern since it enables code re-use Context ctxt = getProgrammaticRootContext(); Tomcat.addServlet(ctxt, "read", new DataReadServlet()); ctxt.addServletMappingDecoded("/simple", "read"); tomcat.start(); } private class DataReadServlet extends SimpleServlet { private static final long serialVersionUID = 1L; @Override protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { byte[] buf = new byte[8192]; InputStream is = req.getInputStream(); int n = is.read(buf); try { while (n > 0) { read += n; n = is.read(buf); } } finally { done.countDown(); } if (read != bodySize * bodyCount) { resp.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); } else { resp.setStatus(HttpServletResponse.SC_OK); } } } @Override public void setUp() throws Exception { super.setUp(); Tomcat tomcat = getTomcatInstance(); TesterSupport.configureSSLImplementation(tomcat, sslImplementationName, useOpenSSL); } }
Detected license expression
apache-2.0
Detected license expression (SPDX)
Apache-2.0
Percentage of license text
20.91
Copyrights

      
    
Holders

      
    
Authors

      
    
License detections License expression License expression SPDX
apache_2_0-4bde3f57-78aa-4201-96bf-531cba09e7de apache-2.0 Apache-2.0
URL Start line End line
http://www.apache.org/licenses/LICENSE-2.0 9 9