}
/** 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;
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;
} 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);
+ }
}
}
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");
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;
int i = super.read();
if (i == -1) throw new HTTPException("encountered end of stream while reading chunk length");
- // FIXME: handle chunking extensions
+ // FEATURE: handle chunking extensions
if (i == '\r') {
super.read(); // LF
break;
try {
org.xwt.js.JS.Array arr = new org.xwt.js.JS.Array();
arr.addElement(((JS.Exn)e).getObject());
- // FIXME
- //XWT.recursivePrintObject.call();
} catch (Exception e2) {
Log.log(Platform.class, e);
}
Message.Q.add(new Message() {
public void perform() {
Box b = new Box();
- /* FIXME
- Template.getTemplate("org.xwt.builtin.proxy_authorization", null).apply(b, null, null, null, 0, 0, null);
+ Template t = Template.getTemplate((Res)Main.builtin.get("org/xwt/builtin/proxy_authorization.xwt"));
+ t.apply(b, null, null);
b.put("realm", realm);
b.put("proxyIP", proxyIP);
- */
}
});
// ProxyAutoConfigRootScope ////////////////////////////////////////////////////////////////////
- public static class ProxyAutoConfigRootScope extends JS.Scope {
+ public static class ProxyAutoConfigRootScope extends JS.GlobalScope {
public ProxyAutoConfigRootScope() { super(null); }
- // FIXME: needs "standard objects"
-
public Object get(Object name) {
if (name.equals("isPlainHostName")) return isPlainHostName;
else if (name.equals("dnsDomainIs")) return dnsDomainIs;