提交 20a5b2ef 编写于 作者: D dfuchs

8176751: Better URL connections

Reviewed-by: chegar, michaelm, rhalade, rpatil, vtewari
上级 127bf70f
...@@ -38,6 +38,7 @@ package com.sun.net.ssl.internal.www.protocol.https; ...@@ -38,6 +38,7 @@ package com.sun.net.ssl.internal.www.protocol.https;
import java.net.URL; import java.net.URL;
import java.net.Proxy; import java.net.Proxy;
import java.net.ProtocolException; import java.net.ProtocolException;
import java.net.MalformedURLException;
import java.io.*; import java.io.*;
import javax.net.ssl.*; import javax.net.ssl.*;
import java.security.Permission; import java.security.Permission;
...@@ -75,10 +76,18 @@ public class HttpsURLConnectionOldImpl ...@@ -75,10 +76,18 @@ public class HttpsURLConnectionOldImpl
this(u, null, handler); this(u, null, handler);
} }
static URL checkURL(URL u) throws IOException {
if (u != null) {
if (u.toExternalForm().indexOf('\n') > -1) {
throw new MalformedURLException("Illegal character in URL");
}
}
return u;
}
// For both copies of the file, uncomment one line and comment the other // For both copies of the file, uncomment one line and comment the other
// HttpsURLConnectionImpl(URL u, Handler handler) throws IOException { // HttpsURLConnectionImpl(URL u, Handler handler) throws IOException {
HttpsURLConnectionOldImpl(URL u, Proxy p, Handler handler) throws IOException { HttpsURLConnectionOldImpl(URL u, Proxy p, Handler handler) throws IOException {
super(u); super(checkURL(u));
delegate = new DelegateHttpsURLConnection(url, p, handler, this); delegate = new DelegateHttpsURLConnection(url, p, handler, this);
} }
......
...@@ -825,18 +825,36 @@ public class HttpURLConnection extends java.net.HttpURLConnection { ...@@ -825,18 +825,36 @@ public class HttpURLConnection extends java.net.HttpURLConnection {
this(u, null, handler); this(u, null, handler);
} }
public HttpURLConnection(URL u, String host, int port) { private static String checkHost(String h) throws IOException {
this(u, new Proxy(Proxy.Type.HTTP, InetSocketAddress.createUnresolved(host, port))); if (h != null) {
if (h.indexOf('\n') > -1) {
throw new MalformedURLException("Illegal character in host");
}
}
return h;
}
public HttpURLConnection(URL u, String host, int port) throws IOException {
this(u, new Proxy(Proxy.Type.HTTP,
InetSocketAddress.createUnresolved(checkHost(host), port)));
} }
/** this constructor is used by other protocol handlers such as ftp /** this constructor is used by other protocol handlers such as ftp
that want to use http to fetch urls on their behalf.*/ that want to use http to fetch urls on their behalf.*/
public HttpURLConnection(URL u, Proxy p) { public HttpURLConnection(URL u, Proxy p) throws IOException {
this(u, p, new Handler()); this(u, p, new Handler());
} }
protected HttpURLConnection(URL u, Proxy p, Handler handler) { private static URL checkURL(URL u) throws IOException {
super(u); if (u != null) {
if (u.toExternalForm().indexOf('\n') > -1) {
throw new MalformedURLException("Illegal character in URL");
}
}
return u;
}
protected HttpURLConnection(URL u, Proxy p, Handler handler)
throws IOException {
super(checkURL(u));
requests = new MessageHeader(); requests = new MessageHeader();
responses = new MessageHeader(); responses = new MessageHeader();
userHeaders = new MessageHeader(); userHeaders = new MessageHeader();
......
...@@ -38,6 +38,7 @@ package sun.net.www.protocol.https; ...@@ -38,6 +38,7 @@ package sun.net.www.protocol.https;
import java.net.URL; import java.net.URL;
import java.net.Proxy; import java.net.Proxy;
import java.net.ProtocolException; import java.net.ProtocolException;
import java.net.MalformedURLException;
import java.io.*; import java.io.*;
import javax.net.ssl.*; import javax.net.ssl.*;
import java.security.Permission; import java.security.Permission;
...@@ -79,10 +80,18 @@ public class HttpsURLConnectionImpl ...@@ -79,10 +80,18 @@ public class HttpsURLConnectionImpl
this(u, null, handler); this(u, null, handler);
} }
static URL checkURL(URL u) throws IOException {
if (u != null) {
if (u.toExternalForm().indexOf('\n') > -1) {
throw new MalformedURLException("Illegal character in URL");
}
}
return u;
}
// For both copies of the file, uncomment one line and comment the other // For both copies of the file, uncomment one line and comment the other
HttpsURLConnectionImpl(URL u, Proxy p, Handler handler) throws IOException { HttpsURLConnectionImpl(URL u, Proxy p, Handler handler) throws IOException {
// HttpsURLConnectionOldImpl(URL u, Proxy p, Handler handler) throws IOException { // HttpsURLConnectionOldImpl(URL u, Proxy p, Handler handler) throws IOException {
super(u); super(checkURL(u));
delegate = new DelegateHttpsURLConnection(url, p, handler, this); delegate = new DelegateHttpsURLConnection(url, p, handler, this);
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册