Java Code Examples for com.android.volley.Request#getHeaders()

The following examples show how to use com.android.volley.Request#getHeaders() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MockHttpStack.java    From volley with Apache License 2.0 6 votes vote down vote up
@Override
public HttpResponse executeRequest(Request<?> request, Map<String, String> additionalHeaders)
        throws IOException, AuthFailureError {
    if (mExceptionToThrow != null) {
        throw mExceptionToThrow;
    }
    mLastUrl = request.getUrl();
    mLastHeaders = new HashMap<>();
    if (request.getHeaders() != null) {
        mLastHeaders.putAll(request.getHeaders());
    }
    if (additionalHeaders != null) {
        mLastHeaders.putAll(additionalHeaders);
    }
    try {
        mLastPostBody = request.getBody();
    } catch (AuthFailureError e) {
        mLastPostBody = null;
    }
    return mResponseToReturn;
}
 
Example 2
Source File: MockHttpStack.java    From device-database with Apache License 2.0 6 votes vote down vote up
@Override
public HttpResponse performRequest(Request<?> request, Map<String, String> additionalHeaders)
        throws AuthFailureError {
    mLastUrl = request.getUrl();
    mLastHeaders = new HashMap<String, String>();
    if (request.getHeaders() != null) {
        mLastHeaders.putAll(request.getHeaders());
    }
    if (additionalHeaders != null) {
        mLastHeaders.putAll(additionalHeaders);
    }
    try {
        mLastPostBody = request.getBody();
    } catch (AuthFailureError e) {
        mLastPostBody = null;
    }
    return mResponseToReturn;
}
 
Example 3
Source File: MockHttpStack.java    From SaveVolley with Apache License 2.0 6 votes vote down vote up
@Override
public HttpResponse performRequest(Request<?> request, Map<String, String> additionalHeaders)
        throws IOException, AuthFailureError {
    if (mExceptionToThrow != null) {
        throw mExceptionToThrow;
    }
    mLastUrl = request.getUrl();
    mLastHeaders = new HashMap<String, String>();
    if (request.getHeaders() != null) {
        mLastHeaders.putAll(request.getHeaders());
    }
    if (additionalHeaders != null) {
        mLastHeaders.putAll(additionalHeaders);
    }
    try {
        mLastPostBody = request.getBody();
    } catch (AuthFailureError e) {
        mLastPostBody = null;
    }
    return mResponseToReturn;
}
 
Example 4
Source File: MockHttpStack.java    From android-project-wo2b with Apache License 2.0 6 votes vote down vote up
@Override
public HttpResponse performRequest(Request<?> request, Map<String, String> additionalHeaders)
        throws AuthFailureError {
    mLastUrl = request.getUrl();
    mLastHeaders = new HashMap<String, String>();
    if (request.getHeaders() != null) {
        mLastHeaders.putAll(request.getHeaders());
    }
    if (additionalHeaders != null) {
        mLastHeaders.putAll(additionalHeaders);
    }
    try {
        mLastPostBody = request.getBody();
    } catch (AuthFailureError e) {
        mLastPostBody = null;
    }
    return mResponseToReturn;
}
 
Example 5
Source File: MockHttpStack.java    From android-discourse with Apache License 2.0 6 votes vote down vote up
@Override
public HttpResponse performRequest(Request<?> request, Map<String, String> additionalHeaders) throws AuthFailureError {
    mLastUrl = request.getUrl();
    mLastHeaders = new HashMap<String, String>();
    if (request.getHeaders() != null) {
        mLastHeaders.putAll(request.getHeaders());
    }
    if (additionalHeaders != null) {
        mLastHeaders.putAll(additionalHeaders);
    }
    try {
        mLastPostBody = request.getPostBody();
    } catch (AuthFailureError e) {
        mLastPostBody = null;
    }
    return mResponseToReturn;
}
 
Example 6
Source File: MockHttpStack.java    From product-emm with Apache License 2.0 6 votes vote down vote up
@Override
public HttpResponse performRequest(Request<?> request, Map<String, String> additionalHeaders)
        throws IOException, AuthFailureError {
    if (mExceptionToThrow != null) {
        throw mExceptionToThrow;
    }
    mLastUrl = request.getUrl();
    mLastHeaders = new HashMap<String, String>();
    if (request.getHeaders() != null) {
        mLastHeaders.putAll(request.getHeaders());
    }
    if (additionalHeaders != null) {
        mLastHeaders.putAll(additionalHeaders);
    }
    try {
        mLastPostBody = request.getBody();
    } catch (AuthFailureError e) {
        mLastPostBody = null;
    }
    return mResponseToReturn;
}
 
Example 7
Source File: MockHttpStack.java    From product-emm with Apache License 2.0 6 votes vote down vote up
@Override
public HttpResponse performRequest(Request<?> request, Map<String, String> additionalHeaders)
        throws IOException, AuthFailureError {
    if (mExceptionToThrow != null) {
        throw mExceptionToThrow;
    }
    mLastUrl = request.getUrl();
    mLastHeaders = new HashMap<String, String>();
    if (request.getHeaders() != null) {
        mLastHeaders.putAll(request.getHeaders());
    }
    if (additionalHeaders != null) {
        mLastHeaders.putAll(additionalHeaders);
    }
    try {
        mLastPostBody = request.getBody();
    } catch (AuthFailureError e) {
        mLastPostBody = null;
    }
    return mResponseToReturn;
}
 
Example 8
Source File: MockVolleyHttpStack.java    From jus with Apache License 2.0 6 votes vote down vote up
@Override
public HttpResponse performRequest(Request<?> request, Map<String, String> additionalHeaders)
        throws IOException, AuthFailureError {
    if (mExceptionToThrow != null) {
        throw mExceptionToThrow;
    }
    mLastUrl = request.getUrl();
    mLastHeaders = new HashMap<String, String>();
    if (request.getHeaders() != null) {
        mLastHeaders.putAll(request.getHeaders());
    }
    if (additionalHeaders != null) {
        mLastHeaders.putAll(additionalHeaders);
    }
    try {
        mLastPostBody = request.getBody();
    } catch (AuthFailureError e) {
        mLastPostBody = null;
    }
    return mResponseToReturn;
}
 
Example 9
Source File: MockHttpStack.java    From CrossBow with Apache License 2.0 6 votes vote down vote up
@Override
public HttpResponse performRequest(Request<?> request, Map<String, String> additionalHeaders)
        throws AuthFailureError {
    mLastUrl = request.getUrl();
    mLastHeaders = new HashMap<String, String>();
    if (request.getHeaders() != null) {
        mLastHeaders.putAll(request.getHeaders());
    }
    if (additionalHeaders != null) {
        mLastHeaders.putAll(additionalHeaders);
    }
    try {
        mLastPostBody = request.getBody();
    } catch (AuthFailureError e) {
        mLastPostBody = null;
    }
    return mResponseToReturn;
}
 
Example 10
Source File: OkHttpStack.java    From openshop.io-android with MIT License 4 votes vote down vote up
@Override
public HttpResponse performRequest(Request<?> request, Map<String, String> additionalHeaders)
        throws IOException, AuthFailureError {

    OkHttpClient.Builder clientBuilder = new OkHttpClient.Builder();
    int timeoutMs = request.getTimeoutMs();

    clientBuilder.connectTimeout(timeoutMs, TimeUnit.MILLISECONDS);
    clientBuilder.readTimeout(timeoutMs, TimeUnit.MILLISECONDS);
    clientBuilder.writeTimeout(timeoutMs, TimeUnit.MILLISECONDS);

    okhttp3.Request.Builder okHttpRequestBuilder = new okhttp3.Request.Builder();
    okHttpRequestBuilder.url(request.getUrl());

    Map<String, String> headers = request.getHeaders();
    for (final Map.Entry<String, String> header : headers.entrySet()) {
        okHttpRequestBuilder.addHeader(header.getKey(), header.getValue());
    }
    for (final Map.Entry<String, String> additionalHeader : additionalHeaders.entrySet()) {
        okHttpRequestBuilder.addHeader(additionalHeader.getKey(), additionalHeader.getValue());
    }

    setConnectionParametersForRequest(okHttpRequestBuilder, request);

    OkHttpClient client = clientBuilder.build();
    okhttp3.Request okHttpRequest = okHttpRequestBuilder.build();
    Call okHttpCall = client.newCall(okHttpRequest);
    Response okHttpResponse = okHttpCall.execute();

    StatusLine responseStatus = new BasicStatusLine(parseProtocol(okHttpResponse.protocol()), okHttpResponse.code(), okHttpResponse.message());
    BasicHttpResponse response = new BasicHttpResponse(responseStatus);
    response.setEntity(entityFromOkHttpResponse(okHttpResponse));

    Headers responseHeaders = okHttpResponse.headers();
    for (int i = 0, len = responseHeaders.size(); i < len; i++) {
        final String name = responseHeaders.name(i), value = responseHeaders.value(i);
        if (name != null) {
            response.addHeader(new BasicHeader(name, value));
        }
    }

    return response;
}