ttomcat-1778514358873.zip-extract/apache-tomcat-11.0.18-src/test/org/apache/catalina/connector/TestKeepAliveCount.java

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

      
    
Rootfs path

      
    
Size
5021 (4.9 KB)
MD5
ee31a0c2251aa9093a25de69b2bd940c
SHA1
20394d6e3b502c480db13e81f5ab103504ff624a
SHA256
09e4f950e59ad32d6efc5a28ab9f58d63d7f5746329b0548d3d5217bb72e10df
SHA512

      
    
SHA1_git
631bac701638f8415f4637a921faa0221b774d40
Is binary

      
    
Is text
True
Is archive

      
    
Is media

      
    
Is legal

      
    
Is manifest

      
    
Is readme

      
    
Is top level

      
    
Is key file

      
    
TestKeepAliveCount.java | 4.9 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.catalina.connector; import java.io.IOException; import jakarta.servlet.ServletException; import jakarta.servlet.http.HttpServlet; import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpServletResponse; import org.junit.Assert; import org.junit.Test; import org.apache.catalina.Context; import org.apache.catalina.startup.SimpleHttpClient; import org.apache.catalina.startup.Tomcat; import org.apache.catalina.startup.TomcatBaseTest; public class TestKeepAliveCount extends TomcatBaseTest { @Test public void testHttp10() throws Exception { TestKeepAliveClient client = new TestKeepAliveClient(); client.doHttp10Request(); } @Test public void testHttp11() throws Exception { TestKeepAliveClient client = new TestKeepAliveClient(); client.doHttp11Request(); } private class TestKeepAliveClient extends SimpleHttpClient { private boolean init; private synchronized void init() { if (init) { return; } Tomcat tomcat = getTomcatInstance(); Context root = tomcat.addContext("", TEMP_DIR); Tomcat.addServlet(root, "Simple", new SimpleServlet()); root.addServletMappingDecoded("/test", "Simple"); Assert.assertTrue(tomcat.getConnector().setProperty("maxKeepAliveRequests", "5")); Assert.assertTrue(tomcat.getConnector().setProperty("connectionTimeout", "20000")); Assert.assertTrue(tomcat.getConnector().setProperty("keepAliveTimeout", "50000")); init = true; } private void doHttp10Request() throws Exception { Tomcat tomcat = getTomcatInstance(); init(); tomcat.start(); setPort(tomcat.getConnector().getLocalPort()); // Open connection connect(); // Send request in two parts String[] request = new String[1]; // @formatter:off request[0] = "GET /test HTTP/1.0" + CRLF + CRLF; // @formatter:on setRequest(request); processRequest(false); // blocks until response has been read boolean passed = (this.readLine() == null); // Close the connection disconnect(); reset(); tomcat.stop(); Assert.assertTrue(passed); } private void doHttp11Request() throws Exception { Tomcat tomcat = getTomcatInstance(); init(); tomcat.start(); setPort(tomcat.getConnector().getLocalPort()); // Open connection connect(); // Send request in two parts String[] request = new String[1]; // @formatter:off request[0] = "GET /test HTTP/1.1" + CRLF + "Host: localhost" + CRLF + "Connection: Keep-Alive" + CRLF + "Keep-Alive: 300"+ CRLF + CRLF; // @formatter:on setRequest(request); for (int i = 0; i < 5; i++) { processRequest(false); // blocks until response has been read Assert.assertTrue(getResponseLine() != null && getResponseLine().startsWith("HTTP/1.1 200 ")); } boolean passed = (this.readLine() == null); // Close the connection disconnect(); reset(); tomcat.stop(); Assert.assertTrue(passed); } @Override public boolean isResponseBodyOK() { return true; } } private static class SimpleServlet extends HttpServlet { private static final long serialVersionUID = 1L; @Override protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { resp.setContentLength(0); resp.flushBuffer(); } } }
Detected license expression
apache-2.0
Detected license expression (SPDX)
Apache-2.0
Percentage of license text
26.15
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