/* * Copyright (c) 2022, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions.
*/
/* * @test * @summary Tests that when the httpclient sends a 100 Expect Continue header and receives * a response code of 417 Expectation Failed, that the client does not hang * indefinitely and closes the connection. * @bug 8286171 * @modules java.base/sun.net.www.http * java.net.http/jdk.internal.net.http.common * java.net.http/jdk.internal.net.http.frame * java.net.http/jdk.internal.net.http.hpack * jdk.httpserver * @library /test/lib http2/server * @compile HttpServerAdapters.java * @run testng/othervm ExpectContinueTest
*/
// Due to limitations of the above Http1 Server, a manual approach is taken to test the hanging with the // httpclient using Http1 so that the correct response header can be returned for the test case
http1HangServer = new Http1HangServer(saHang);
hangUri = URI.create("http://" + http1HangServer.ia.getCanonicalHostName() + ":" + http1HangServer.port + "/http1/hang");
@Override publicvoid handle(HttpTestExchange exchange) throws IOException { // Http1 server has already sent 100 response at this point but not Http2 server if (exchange.getExchangeVersion().equals(HttpClient.Version.HTTP_2)) { // Send 100 Headers, tell client that we're ready for body
exchange.sendResponseHeaders(100, 0);
}
// Read body from client and acknowledge with 200 try (InputStream is = exchange.getRequestBody();
OutputStream os = exchange.getResponseBody()) {
is.readAllBytes();
exchange.sendResponseHeaders(200, 0);
}
}
}
while (!closed) { try { // Not using try with resources here as we expect the client to close resources when // 417 is received
client = ss.accept();
InputStream is = client.getInputStream();
OutputStream os = client.getOutputStream();
BufferedReader reader = new BufferedReader(new InputStreamReader(is));
Writer w = new OutputStreamWriter(os, UTF_8);
PrintWriter pw = new PrintWriter(w);
StringBuilder response = new StringBuilder();
String line = null;
StringBuilder reqBuilder = new StringBuilder(); while (!(line = reader.readLine()).isEmpty()) {
reqBuilder.append(line + "\r\n");
}
String req = reqBuilder.toString();
System.err.println("Http1HangServer received: " + req);
StringTokenizer tokenizer = new StringTokenizer(req);
String method = tokenizer.nextToken();
String path = tokenizer.nextToken();
String version = tokenizer.nextToken();
boolean validRequest = method.equals("POST") && path.equals("/http1/hang")
&& version.equals("HTTP/1.1"); // If correct request, send 417 reply. Otherwise, wait for correct one if (validRequest) {
closed = true;
response.append("HTTP/1.1 417 Expectation Failed\r\n")
.append("Content-Length: ")
.append(0)
.append("\r\n\r\n");
pw.print(response);
pw.flush();
¤ 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.0.4Bemerkung:
¤
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.