use of com.koushikdutta.async.http.AsyncHttpRequest in project AndroidAsync by koush.
the class SpdyMiddleware method newSocket.
private void newSocket(GetSocketData data, final AsyncSpdyConnection connection, final ConnectCallback callback) {
final AsyncHttpRequest request = data.request;
data.protocol = connection.protocol.toString();
final AsyncHttpRequestBody requestBody = data.request.getBody();
// this causes app engine to shit a brick, but if it is missing,
// drive shits the bed
// if (requestBody != null) {
// if (requestBody.length() >= 0) {
// request.getHeaders().set("Content-Length", String.valueOf(requestBody.length()));
// }
// }
final ArrayList<Header> headers = new ArrayList<Header>();
headers.add(new Header(Header.TARGET_METHOD, request.getMethod()));
headers.add(new Header(Header.TARGET_PATH, requestPath(request.getUri())));
String host = request.getHeaders().get("Host");
if (Protocol.SPDY_3 == connection.protocol) {
headers.add(new Header(Header.VERSION, "HTTP/1.1"));
headers.add(new Header(Header.TARGET_HOST, host));
} else if (Protocol.HTTP_2 == connection.protocol) {
// Optional in HTTP/2
headers.add(new Header(Header.TARGET_AUTHORITY, host));
} else {
throw new AssertionError();
}
headers.add(new Header(Header.TARGET_SCHEME, request.getUri().getScheme()));
final Multimap mm = request.getHeaders().getMultiMap();
for (String key : mm.keySet()) {
if (SpdyTransport.isProhibitedHeader(connection.protocol, key))
continue;
for (String value : mm.get(key)) {
headers.add(new Header(key.toLowerCase(Locale.US), value));
}
}
request.logv("\n" + request);
final AsyncSpdyConnection.SpdySocket spdy = connection.newStream(headers, requestBody != null, true);
callback.onConnectCompleted(null, spdy);
}
use of com.koushikdutta.async.http.AsyncHttpRequest in project AndroidAsync by koush.
the class XHRPollingTransport method postMessage.
private void postMessage(String message) {
if (!message.startsWith("5"))
return;
AsyncHttpRequest request = new AsyncHttpPost(computedRequestUrl());
request.setBody(new StringBody(message));
client.executeString(request, null);
}
use of com.koushikdutta.async.http.AsyncHttpRequest in project AndroidAsync by koush.
the class AsyncProxyServer method onRequest.
@Override
protected void onRequest(HttpServerRequestCallback callback, AsyncHttpServerRequest request, final AsyncHttpServerResponse response) {
super.onRequest(callback, request, response);
if (callback != null)
return;
try {
Uri uri;
try {
uri = Uri.parse(request.getPath());
if (uri.getScheme() == null)
throw new Exception("no host or full uri provided");
} catch (Exception e) {
String host = request.getHeaders().get("Host");
int port = 80;
if (host != null) {
String[] splits = host.split(":", 2);
if (splits.length == 2) {
host = splits[0];
port = Integer.parseInt(splits[1]);
}
}
uri = Uri.parse("http://" + host + ":" + port + request.getPath());
}
proxyClient.execute(new AsyncHttpRequest(uri, request.getMethod(), request.getHeaders()), new HttpConnectCallback() {
@Override
public void onConnectCompleted(Exception ex, AsyncHttpResponse remoteResponse) {
if (ex != null) {
response.code(500);
response.send(ex.getMessage());
return;
}
response.proxy(remoteResponse);
}
});
} catch (Exception e) {
response.code(500);
response.send(e.getMessage());
}
}
use of com.koushikdutta.async.http.AsyncHttpRequest in project ion by koush.
the class IonRequestBuilder method getLoaderEmitter.
private <T> void getLoaderEmitter(final EmitterTransform<T> ret) {
Uri uri = prepareURI();
if (uri == null) {
ret.setComplete(new Exception("Invalid URI"));
return;
}
AsyncHttpRequest request = prepareRequest(uri);
ret.initialRequest = request;
getLoaderEmitter(ret, request);
}
use of com.koushikdutta.async.http.AsyncHttpRequest in project ion by koush.
the class IonRequestBuilder method prepareRequest.
private AsyncHttpRequest prepareRequest(Uri uri) {
AsyncHttpRequest request = ion.configure().getAsyncHttpRequestFactory().createAsyncHttpRequest(uri, method, headers);
request.setFollowRedirect(followRedirect);
request.setBody(body);
request.setLogging(ion.logtag, ion.logLevel);
if (logTag != null)
request.setLogging(logTag, logLevel);
request.enableProxy(proxyHost, proxyPort);
request.setTimeout(timeoutMilliseconds);
request.logd("preparing request");
return request;
}
Aggregations