/* * Copyright (c) 2019, 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. * * 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 * @bug 8185898 8163921 * @modules java.base/sun.net.www * @library /test/lib * @run main/othervm B8185898 * @summary setRequestProperty(key, null) results in HTTP header without colon in request
*/
/* * Test checks that MessageHeader with key != null and value == null is set correctly * and printed according to HTTP standard in the format <key>: <value>
* */ publicclass B8185898 {
static HttpServer server; staticfinal String RESPONSE_BODY = "Test response body"; staticfinal String H1 = "X-header1"; staticfinal String H2 = "X-header2"; staticfinal String VALUE = "This test value should appear"; staticint port; static URL url; staticvolatile Map<String, List<String>> headers;
staticclass Handler implements HttpHandler {
publicvoid handle(HttpExchange t) throws IOException {
InputStream is = t.getRequestBody();
InetSocketAddress rem = t.getRemoteAddress();
headers = t.getRequestHeaders(); // Get request headers on the server side
is.readAllBytes();
is.close();
OutputStream os = t.getResponseBody();
t.sendResponseHeaders(200, RESPONSE_BODY.length());
os.write(RESPONSE_BODY.getBytes(UTF_8));
t.close();
}
}
// Test message header with malformed message header and fake request line staticvoid testMessageHeader() { final String badHeader = "This is not a request line for HTTP/1.1"; final String fakeRequestLine = "This /is/a/fake/status/line HTTP/2.0"; final String expectedHeaders = fakeRequestLine + "\r\n"
+ H1 + ": " + VALUE + "\r\n"
+ H2 + ": " + VALUE + "\r\n"
+ badHeader + ":\r\n\r\n";
MessageHeader header = new MessageHeader();
header.add(H1, VALUE);
header.add(H2, VALUE);
header.add(badHeader, null);
header.prepend(fakeRequestLine, null);
ByteArrayOutputStream out = new ByteArrayOutputStream();
header.print(new PrintStream(out));
if (!out.toString().equals(expectedHeaders)) { thrownew AssertionError("FAILED: expected: "
+ expectedHeaders + "\nReceived: " + out.toString());
} else {
System.out.println("PASSED: ::print returned correct "
+ "status line and headers:\n" + out.toString());
}
}
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 und die Messung sind noch experimentell.