/* * 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 jakarta.servlet.http;
// No file system docBase required
StandardContext ctx = (StandardContext) tomcat.addContext("", null);
// Map the test Servlet
LargeBodyServlet largeBodyServlet = new LargeBodyServlet();
Tomcat.addServlet(ctx, "largeBodyServlet", largeBodyServlet);
ctx.addServletMappingDecoded("/", "largeBodyServlet");
tomcat.start();
Map<String,List<String>> resHeaders= new HashMap<>(); int rc = headUrl("http://localhost:" + getPort() + "/", new ByteChunk(),
resHeaders);
/* * Verifies that the same Content-Length is returned for both GET and HEAD * operations when a Servlet includes content from another Servlet
*/
@Test publicvoid testBug57602() throws Exception {
Tomcat tomcat = getTomcatInstance();
// No file system docBase required
StandardContext ctx = (StandardContext) tomcat.addContext("", null);
Bug57602ServletOuter outer = new Bug57602ServletOuter();
Tomcat.addServlet(ctx, "Bug57602ServletOuter", outer);
ctx.addServletMappingDecoded("/outer", "Bug57602ServletOuter");
Bug57602ServletInner inner = new Bug57602ServletInner();
Tomcat.addServlet(ctx, "Bug57602ServletInner", inner);
ctx.addServletMappingDecoded("/inner", "Bug57602ServletInner");
tomcat.start();
Map<String,List<String>> resHeaders= new CaseInsensitiveKeyMap<>();
String path = "http://localhost:" + getPort() + "/outer";
ByteChunk out = new ByteChunk();
// No file system docBase required
StandardContext ctx = (StandardContext) tomcat.addContext("", null);
Wrapper w = Tomcat.addServlet(ctx, "TestServlet", servlet); // Not all need/use this but it is simpler to set it for all
w.setAsyncSupported(true);
ctx.addServletMappingDecoded("/test", "TestServlet");
tomcat.start();
Map<String,List<String>> getHeaders = new CaseInsensitiveKeyMap<>();
String path = "http://localhost:" + getPort() + "/test";
ByteChunk out = new ByteChunk();
int rc = getUrl(path, out, getHeaders); Assert.assertEquals(HttpServletResponse.SC_OK, rc);
out.recycle();
/* * See org.apache.coyote.http2.TestHttpServlet for the HTTP/2 version of * this test. It was placed in that package because it needed access to * package private classes.
*/
Assert.assertTrue(client.getResponseLine(), client.isResponse200()); // Far from perfect but good enough
body = body.toLowerCase(Locale.ENGLISH); Assert.assertTrue(body.contains("a1")); Assert.assertTrue(body.contains("a2")); Assert.assertTrue(body.contains("a3")); // Sensitive headers (cookies, WWW-Authenticate) must not be reflected // (since RFC 7231) Assert.assertFalse(body.contains("cookie")); Assert.assertFalse(body.contains("authorization"));
@Override publicvoid onWritePossible() throws IOException { do { // Write up to 1k a time int bytesThisTime = Math.min(bytesToWrite, 1024);
sos.write(newbyte[bytesThisTime]);
bytesToWrite -= bytesThisTime;
} while (sos.isReady() && bytesToWrite > 0);
if (sos.isReady() && bytesToWrite == 0) {
ac.complete();
}
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung ist noch experimentell.