Search in sources :

Example 1 with Multimap

use of com.koushikdutta.async.http.Multimap in project AndroidAsync by koush.

the class BodyTests method testNullValue.

@Test
public void testNullValue() throws Exception {
    Multimap mm = new Multimap();
    mm.add("hello", null);
    UrlEncodedFormBody body = new UrlEncodedFormBody(mm);
    int length = body.length();
}
Also used : Multimap(com.koushikdutta.async.http.Multimap) UrlEncodedFormBody(com.koushikdutta.async.http.body.UrlEncodedFormBody) Test(org.junit.Test)

Example 2 with Multimap

use of com.koushikdutta.async.http.Multimap in project ion by koush.

the class HttpTests method testCookie.

public void testCookie() throws Exception {
    Ion ion = Ion.getDefault(getContext());
    ion.getCookieMiddleware().clear();
    ion.build(getContext()).load("http://google.com").asString().get();
    for (HttpCookie cookie : ion.getCookieMiddleware().getCookieStore().get(URI.create("http://www.google.com"))) {
        Log.i("CookieTest", cookie.getName() + ": " + cookie.getValue());
    }
    assertTrue(ion.getCookieMiddleware().getCookieManager().get(URI.create("http://www.google.com/test/path"), new Multimap()).size() > 0);
    CookieMiddleware deserialize = new CookieMiddleware(ion);
    assertTrue(deserialize.getCookieManager().get(URI.create("http://www.google.com/test/path"), new Multimap()).size() > 0);
}
Also used : Multimap(com.koushikdutta.async.http.Multimap) CookieMiddleware(com.koushikdutta.ion.cookie.CookieMiddleware) Ion(com.koushikdutta.ion.Ion) HttpCookie(java.net.HttpCookie)

Example 3 with Multimap

use of com.koushikdutta.async.http.Multimap 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);
}
Also used : Multimap(com.koushikdutta.async.http.Multimap) ArrayList(java.util.ArrayList) AsyncHttpRequestBody(com.koushikdutta.async.http.body.AsyncHttpRequestBody) AsyncHttpRequest(com.koushikdutta.async.http.AsyncHttpRequest)

Example 4 with Multimap

use of com.koushikdutta.async.http.Multimap in project ion by koush.

the class IonRequestBuilder method setBodyParameter.

@Override
public IonRequestBuilder setBodyParameter(String name, String value) {
    if (bodyParameters == null) {
        bodyParameters = new Multimap();
        setBody(new UrlEncodedFormBody(bodyParameters));
    }
    if (value != null)
        bodyParameters.add(name, value);
    return this;
}
Also used : Multimap(com.koushikdutta.async.http.Multimap) UrlEncodedFormBody(com.koushikdutta.async.http.body.UrlEncodedFormBody)

Example 5 with Multimap

use of com.koushikdutta.async.http.Multimap in project ion by koush.

the class IonRequestBuilder method setBodyParameters.

public IonRequestBuilder setBodyParameters(Map<String, List<String>> params) {
    if (bodyParameters == null) {
        bodyParameters = new Multimap();
        setBody(new UrlEncodedFormBody(bodyParameters));
    }
    bodyParameters.putAll(params);
    return this;
}
Also used : Multimap(com.koushikdutta.async.http.Multimap) UrlEncodedFormBody(com.koushikdutta.async.http.body.UrlEncodedFormBody)

Aggregations

Multimap (com.koushikdutta.async.http.Multimap)6 UrlEncodedFormBody (com.koushikdutta.async.http.body.UrlEncodedFormBody)3 AsyncHttpRequestBody (com.koushikdutta.async.http.body.AsyncHttpRequestBody)2 AsyncHttpRequest (com.koushikdutta.async.http.AsyncHttpRequest)1 Ion (com.koushikdutta.ion.Ion)1 CookieMiddleware (com.koushikdutta.ion.cookie.CookieMiddleware)1 HttpCookie (java.net.HttpCookie)1 ArrayList (java.util.ArrayList)1 Test (org.junit.Test)1