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

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

      
    
Rootfs path

      
    
Size
5086 (5.0 KB)
MD5
ca3354e4b11d092f6072ba402433f18f
SHA1
bbc05ea24de2ff4ac934f5fead4f9181bf7eb81a
SHA256
779d4de13d6e6cda7dac485e4b85aa1b4cfc0c339271ce00c51965eff23708f8
SHA512

      
    
SHA1_git
8d25bd7df5b1e58566923cdd31104c8c9d08c391
Is binary

      
    
Is text
True
Is archive

      
    
Is media

      
    
Is legal

      
    
Is manifest

      
    
Is readme

      
    
Is top level

      
    
Is key file

      
    
TestClientReadTimeout.java | 5.0 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.BufferedReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.io.OutputStream; import java.net.Socket; import java.net.SocketException; import java.nio.charset.StandardCharsets; 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.LifecycleException; import org.apache.catalina.core.StandardHost; import org.apache.catalina.startup.Tomcat; import org.apache.catalina.startup.TomcatBaseTest; public class TestClientReadTimeout extends TomcatBaseTest { static Tomcat tomcat; @Test public void testTimeoutGets408() throws IOException, LifecycleException { // Setup Tomcat instance Tomcat tomcat = getTomcatInstance(); // No file system docBase required Context ctx = getProgrammaticRootContext(); ((StandardHost) tomcat.getHost()).setErrorReportValveClass(null); Tomcat.addServlet(ctx, "TestServlet", new SyncServlet()); ctx.addServletMappingDecoded("/*", "TestServlet"); tomcat.start(); try (Socket socket = new Socket("localhost", getPort())) { String request = "GET /async HTTP/1.1 Host: localhost content-length: 101 "; OutputStream os = socket.getOutputStream(); os.write(request.getBytes(StandardCharsets.UTF_8)); InputStream is = socket.getInputStream(); BufferedReader reader = new BufferedReader(new InputStreamReader(is, StandardCharsets.UTF_8)); String opening = null; try { opening = reader.readLine(); } catch (SocketException e) { // Handled below. An exception here means opening will be null } if (tomcat.getConnector().getProtocolHandlerClassName().contains("Nio2")) { Assert.assertNull("NIO2 unexpectedly returned a response", opening); } else { Assert.assertNotNull("Didn't get back a response", opening); StringBuilder sb = new StringBuilder(opening); try { Assert.assertTrue( "expected status code " + HttpServletResponse.SC_REQUEST_TIMEOUT + " but got " + opening, opening.startsWith("HTTP/1.1 " + HttpServletResponse.SC_REQUEST_TIMEOUT)); boolean connectionClose = false; while (reader.ready()) { String line = reader.readLine(); if (line == null) { break; } sb.append(" ").append(line); if ("connection: close".equalsIgnoreCase(line)) { connectionClose = true; } Assert.assertFalse(line.contains("Exception Report")); Assert.assertFalse(line.contains("Status Report")); } Assert.assertTrue("No 'Connection: close' header seen", connectionClose); } catch (Throwable t) { Assert.fail("Response: " + sb); t.printStackTrace(); } } } } static final class SyncServlet extends HttpServlet { private static final long serialVersionUID = 1L; @Override protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { try { while (req.getInputStream().read() != -1) { // NO-OP - Any data read is ignored } resp.setStatus(200); resp.flushBuffer(); } catch (ClientAbortException e) { // resp.sendError(408); } } } }
Detected license expression
apache-2.0
Detected license expression (SPDX)
Apache-2.0
Percentage of license text
25.37
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