From 3cbc9361884771b904074ba829cb457ea736e1bd Mon Sep 17 00:00:00 2001 From: megacz Date: Fri, 30 Jan 2004 07:36:13 +0000 Subject: [PATCH] 2003/09/24 06:10:54 darcs-hash:20040130073613-2ba56-1524ac27d91cbe606df14ed6722a99929a6ef1a3.gz --- src/org/xwt/HTTP.java | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/src/org/xwt/HTTP.java b/src/org/xwt/HTTP.java index ce94de2..19fc41c 100644 --- a/src/org/xwt/HTTP.java +++ b/src/org/xwt/HTTP.java @@ -73,16 +73,16 @@ public class HTTP { } /** Performs an HTTP GET request */ - public HTTPInputStream GET() throws IOException { return makeRequest(null, null); } + public InputStream GET() throws IOException { return makeRequest(null, null); } /** Performs an HTTP POST request; content is appended to the headers (so it should include a blank line to delimit the beginning of the body) */ - public HTTPInputStream POST(String contentType, String content) throws IOException { return makeRequest(contentType, content); } + public InputStream POST(String contentType, String content) throws IOException { return makeRequest(contentType, content); } /** * This method isn't synchronized; however, only one thread can be in the inner synchronized block at a time, and the rest of * the method is protected by in-order one-at-a-time semaphore lock-steps */ - private HTTPInputStream makeRequest(String contentType, String content) throws IOException { + private InputStream makeRequest(String contentType, String content) throws IOException { // Step 1: send the request and establish a semaphore to stop any requests that pipeline after us Semaphore blockOn = null; @@ -135,7 +135,8 @@ public class HTTP { if (h.get("HTTP").equals("1.0") && h.get("content-length") == null) throw new HTTPException("XWT does not support HTTP/1.0 servers which fail to return the Content-Length header"); int cl = h.get("content-length") == null ? -1 : Integer.parseInt(h.get("content-length").toString()); - HTTPInputStream ret = new HTTPInputStream(in, cl, releaseMe); + InputStream ret = new HTTPInputStream(in, cl, releaseMe); + if ("gzip".equals(h.get("content-encoding"))) ret = new java.util.zip.GZIPInputStream(ret); doRelease = false; return ret; @@ -176,6 +177,17 @@ public class HTTP { } catch (UnknownHostException uhe) { } if (Platform.detectProxy() == null) throw new HTTPException("could not resolve hostname \"" + host + "\" and no proxy configured"); + if (Log.on) Log.log(this, " could not resolve host " + host + "; using xmlrpc.xwt.org to ensure security"); + try { + JS.Array args = new JS.Array(); + args.addElement(host); + Object ret = new XMLRPC("http://xmlrpc.xwt.org/RPC2/", "dns.resolve").call(args); + if (ret == null || !(ret instanceof String)) throw new Exception(" xmlrpc.xwt.org returned non-String: " + ret); + resolvedHosts.put(host, ret); + return; + } catch (Throwable e) { + throw new HTTPException("exception while attempting to use xmlrpc.xwt.org to resolve " + host + ": " + e); + } } @@ -367,6 +379,7 @@ public class HTTP { } pw.print("User-Agent: XWT\r\n"); + pw.print("Accept-encoding: gzip\r\n"); pw.print("Host: " + (host + (port == 80 ? "" : (":" + port))) + "\r\n"); if (proxied) pw.print("X-RequestOrigin: " + Main.originHost + "\r\n"); @@ -467,7 +480,7 @@ public class HTTP { private int contentLength = 0; public int getContentLength() { return contentLength; } - HTTPInputStream(InputStream in, int length, Semaphore releaseMe) { + HTTPInputStream(InputStream in, int length, Semaphore releaseMe) throws IOException { super(in); this.releaseMe = releaseMe; this.contentLength = length; -- 1.7.10.4