fix double-escaped urls from proxy-usage

pull/1/head
sixcooler 11 years ago
parent 865ce6f974
commit add0e42804

@ -391,8 +391,19 @@ public class HTTPClient {
* @throws IOException * @throws IOException
*/ */
public void GET(final String uri) throws IOException { public void GET(final String uri) throws IOException {
GET(new MultiProtocolURL(uri));
}
/**
* This method GETs a page from the server.
* to be used for streaming out
* Please take care to call finish()!
*
* @param url the url to get
* @throws IOException
*/
public void GET(final MultiProtocolURL url) throws IOException {
if (this.currentRequest != null) throw new IOException("Client is in use!"); if (this.currentRequest != null) throw new IOException("Client is in use!");
final MultiProtocolURL url = new MultiProtocolURL(uri);
final String urix = url.toNormalform(true); final String urix = url.toNormalform(true);
HttpGet httpGet = null; HttpGet httpGet = null;
try { try {
@ -413,7 +424,17 @@ public class HTTPClient {
* @throws IOException * @throws IOException
*/ */
public HttpResponse HEADResponse(final String uri) throws IOException { public HttpResponse HEADResponse(final String uri) throws IOException {
final MultiProtocolURL url = new MultiProtocolURL(uri); return HEADResponse(new MultiProtocolURL(uri));
}
/**
* This method gets HEAD response
*
* @param url the url to Response from
* @return the HttpResponse
* @throws IOException
*/
public HttpResponse HEADResponse(final MultiProtocolURL url) throws IOException {
final HttpHead httpHead = new HttpHead(url.toNormalform(true)); final HttpHead httpHead = new HttpHead(url.toNormalform(true));
setHost(url.getHost()); // overwrite resolved IP, needed for shared web hosting DO NOT REMOVE, see http://en.wikipedia.org/wiki/Shared_web_hosting_service setHost(url.getHost()); // overwrite resolved IP, needed for shared web hosting DO NOT REMOVE, see http://en.wikipedia.org/wiki/Shared_web_hosting_service
execute(httpHead); execute(httpHead);
@ -433,8 +454,21 @@ public class HTTPClient {
* @throws IOException * @throws IOException
*/ */
public void POST(final String uri, final InputStream instream, final long length) throws IOException { public void POST(final String uri, final InputStream instream, final long length) throws IOException {
POST(new MultiProtocolURL(uri), instream, length);
}
/**
* This method POSTs a page from the server.
* to be used for streaming out
* Please take care to call finish()!
*
* @param url the url to post
* @param instream the input to post
* @param length the contentlength
* @throws IOException
*/
public void POST(final MultiProtocolURL url, final InputStream instream, final long length) throws IOException {
if (this.currentRequest != null) throw new IOException("Client is in use!"); if (this.currentRequest != null) throw new IOException("Client is in use!");
final MultiProtocolURL url = new MultiProtocolURL(uri);
final HttpPost httpPost = new HttpPost(url.toNormalform(true)); final HttpPost httpPost = new HttpPost(url.toNormalform(true));
String host = url.getHost(); String host = url.getHost();
if (host == null) host = Domains.LOCALHOST; if (host == null) host = Domains.LOCALHOST;

@ -108,13 +108,13 @@ public class ProxyHandler extends AbstractRemoteHandler implements Handler {
// send request // send request
try { try {
String queryString = request.getQueryString() != null ? "?" + request.getQueryString() : ""; String queryString = request.getQueryString() != null ? "?" + request.getQueryString() : "";
String url = request.getRequestURL().toString() + queryString; DigestURL digestURI = new DigestURL(request.getScheme(), request.getServerName(), request.getServerPort(), request.getPathInfo() + queryString);
if (request.getMethod().equals(HeaderFramework.METHOD_GET)) { if (request.getMethod().equals(HeaderFramework.METHOD_GET)) {
client.GET(url); client.GET(digestURI);
} else if (request.getMethod().equals(HeaderFramework.METHOD_POST)) { } else if (request.getMethod().equals(HeaderFramework.METHOD_POST)) {
client.POST(url, request.getInputStream(), request.getContentLength()); client.POST(digestURI, request.getInputStream(), request.getContentLength());
} else if (request.getMethod().equals(HeaderFramework.METHOD_HEAD)) { } else if (request.getMethod().equals(HeaderFramework.METHOD_HEAD)) {
client.HEADResponse(url); client.HEADResponse(digestURI);
} else { } else {
throw new ServletException("Unsupported Request Method"); throw new ServletException("Unsupported Request Method");
} }
@ -128,7 +128,6 @@ public class ProxyHandler extends AbstractRemoteHandler implements Handler {
cleanResponseHeader(clientresponse); cleanResponseHeader(clientresponse);
// TODO: is this fast, if not, use value from ProxyCacheHandler // TODO: is this fast, if not, use value from ProxyCacheHandler
DigestURL digestURI = new DigestURL(url);
ResponseHeader cachedResponseHeader = Cache.getResponseHeader(digestURI.hash()); ResponseHeader cachedResponseHeader = Cache.getResponseHeader(digestURI.hash());
// the cache does either not exist or is (supposed to be) stale // the cache does either not exist or is (supposed to be) stale
@ -137,7 +136,7 @@ public class ProxyHandler extends AbstractRemoteHandler implements Handler {
// delete the cache // delete the cache
ResponseHeader rh = Cache.getResponseHeader(digestURI.hash()); ResponseHeader rh = Cache.getResponseHeader(digestURI.hash());
if (rh != null && (sizeBeforeDelete = rh.getContentLength()) == 0) { if (rh != null && (sizeBeforeDelete = rh.getContentLength()) == 0) {
byte[] b = Cache.getContent(new DigestURL(url).hash()); byte[] b = Cache.getContent(digestURI.hash());
if (b != null) sizeBeforeDelete = b.length; if (b != null) sizeBeforeDelete = b.length;
} }
Cache.delete(digestURI.hash()); Cache.delete(digestURI.hash());

Loading…
Cancel
Save