Skip to content

Commit

Permalink
8061729: Update java/net tests to eliminate dependency on sun.net.www…
Browse files Browse the repository at this point in the history
….MessageHeader and some other internal APIs

8282017: sun/net/www/protocol/https/HttpsURLConnection/B6216082.java fails with "SocketException: Unexpected end of file from server"

Backport-of: 0f3d3ac32c9d163a5d91c6839d313111c72f1ad4
  • Loading branch information
GoeLin committed Sep 20, 2023
1 parent f908cee commit f3ee6ea
Show file tree
Hide file tree
Showing 11 changed files with 968 additions and 59 deletions.
25 changes: 15 additions & 10 deletions test/jdk/sun/net/www/http/HttpClient/ProxyFromCache.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2006, 2019, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2006, 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
Expand All @@ -25,14 +25,22 @@
* @test
* @bug 6498566
* @summary URL.openConnection(Proxy.NO_PROXY) may connect through a proxy.
* @modules java.base/sun.net.www
* @library /test/lib
* @run main/othervm ProxyFromCache
*/

import java.net.*;
import java.io.*;
import sun.net.www.MessageHeader;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.HttpURLConnection;
import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.net.Proxy;
import java.net.ServerSocket;
import java.net.Socket;
import java.net.URL;

import jdk.test.lib.net.HttpHeaderParser;
import jdk.test.lib.net.URIBuilder;

/* Creates a simple proxy and http server that just return 200 OK.
Expand Down Expand Up @@ -135,15 +143,12 @@ public void run() {
connectionCount++;
InputStream is = sock.getInputStream();
OutputStream os = sock.getOutputStream();

MessageHeader headers = new MessageHeader (is);
HttpHeaderParser httpHeaderParser = new HttpHeaderParser(is);
os.write(replyOK.getBytes("UTF-8"));

headers = new MessageHeader (is);
httpHeaderParser = new HttpHeaderParser(is);
// If we get here then we received a second request.
connectionCount++;
os.write(replyOK.getBytes("UTF-8"));

sock.close();
} catch (Exception e) {
//e.printStackTrace();
Expand Down
11 changes: 6 additions & 5 deletions test/jdk/sun/net/www/http/HttpClient/RequestURI.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2006, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2006, 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
Expand All @@ -25,13 +25,14 @@
* @test
* @bug 6469663
* @summary HTTP Request-URI contains fragment when connecting through proxy
* @modules java.base/sun.net.www
* @library /test/lib
* @run main/othervm RequestURI
*/

import java.net.*;
import java.io.*;
import sun.net.www.MessageHeader;

import jdk.test.lib.net.HttpHeaderParser;

// Create a Server listening on port 5001 to act as the proxy. Requests
// never need to be forwared from it. We are only interested in the
Expand Down Expand Up @@ -91,8 +92,8 @@ public void run() {
InputStream is = sock.getInputStream();
OutputStream os = sock.getOutputStream();

MessageHeader headers = new MessageHeader (is);
String requestLine = headers.getValue(0);
HttpHeaderParser headers = new HttpHeaderParser (is);
String requestLine = headers.getRequestDetails();

int first = requestLine.indexOf(' ');
int second = requestLine.lastIndexOf(' ');
Expand Down
32 changes: 22 additions & 10 deletions test/jdk/sun/net/www/protocol/http/CloseOptionHeader.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2004, 2019, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2004, 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
Expand All @@ -24,16 +24,23 @@
/**
* @test
* @bug 6189206
* @modules java.base/sun.net.www
* @library /test/lib
* @run main/othervm -Dhttp.keepAlive=false CloseOptionHeader
* @summary HTTP client should set "Connection: close" header in request when keepalive is disabled
*/

import java.net.*;
import java.util.*;
import java.io.*;
import sun.net.www.MessageHeader;
import java.io.BufferedOutputStream;
import java.io.InputStream;
import java.io.PrintStream;
import java.net.HttpURLConnection;
import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.net.ServerSocket;
import java.net.Socket;
import java.net.URL;
import java.util.List;

import jdk.test.lib.net.HttpHeaderParser;
import jdk.test.lib.net.URIBuilder;

public class CloseOptionHeader implements Runnable {
Expand All @@ -49,10 +56,15 @@ public void run() {

/* check the request to find close connection option header */
InputStream is = s.getInputStream ();
MessageHeader mh = new MessageHeader(is);
String connHeader = mh.findValue("Connection");
if (connHeader != null && connHeader.equalsIgnoreCase("close")) {
hasCloseHeader = true;
HttpHeaderParser mh = new HttpHeaderParser(is);
List <String> connHeader = mh.getHeaderValue("Connection");
if (connHeader != null) {
for(String value : connHeader) {
if (value.equalsIgnoreCase("close")) {
hasCloseHeader = true;
break;
}
}
}

PrintStream out = new PrintStream(
Expand Down
Loading

1 comment on commit f3ee6ea

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.