Search in sources :

Example 1 with CaseInsensitiveEmptyHeaders

use of org.odk.collect.android.openrosa.CaseInsensitiveEmptyHeaders in project collect by opendatakit.

the class StubOpenRosaServer method executeHeadRequest.

@NonNull
@Override
public HttpHeadResult executeHeadRequest(@NonNull URI uri, @Nullable HttpCredentialsInterface credentials) throws Exception {
    if (alwaysReturnError) {
        return new HttpHeadResult(500, new CaseInsensitiveEmptyHeaders());
    }
    if (!uri.getHost().equals(HOST)) {
        return new HttpHeadResult(410, new CaseInsensitiveEmptyHeaders());
    } else if (credentialsIncorrect(credentials)) {
        return new HttpHeadResult(401, new CaseInsensitiveEmptyHeaders());
    } else if (uri.getPath().equals(OpenRosaConstants.SUBMISSION)) {
        HashMap<String, String> headers = getStandardHeaders();
        headers.put("x-openrosa-accept-content-length", "10485760");
        return new HttpHeadResult(204, new MapHeaders(headers));
    } else {
        return new HttpHeadResult(404, new CaseInsensitiveEmptyHeaders());
    }
}
Also used : CaseInsensitiveEmptyHeaders(org.odk.collect.android.openrosa.CaseInsensitiveEmptyHeaders) HttpHeadResult(org.odk.collect.android.openrosa.HttpHeadResult) NonNull(androidx.annotation.NonNull)

Example 2 with CaseInsensitiveEmptyHeaders

use of org.odk.collect.android.openrosa.CaseInsensitiveEmptyHeaders in project collect by opendatakit.

the class OkHttpConnection method executeHeadRequest.

@NonNull
@Override
public HttpHeadResult executeHeadRequest(@NonNull URI uri, @Nullable HttpCredentialsInterface credentials) throws Exception {
    OpenRosaServerClient httpClient = clientFactory.get(uri.getScheme(), userAgent, credentials);
    Request request = new Request.Builder().url(uri.toURL()).head().build();
    Timber.i("Issuing HEAD request to: %s", uri.toString());
    Response response = httpClient.makeRequest(request, new Date());
    int statusCode = response.code();
    CaseInsensitiveHeaders responseHeaders = new CaseInsensitiveEmptyHeaders();
    if (statusCode == HttpURLConnection.HTTP_NO_CONTENT) {
        responseHeaders = new OkHttpCaseInsensitiveHeaders(response.headers());
    }
    discardEntityBytes(response);
    return new HttpHeadResult(statusCode, responseHeaders);
}
Also used : Response(okhttp3.Response) OpenRosaServerClient(org.odk.collect.android.openrosa.OpenRosaServerClient) CaseInsensitiveHeaders(org.odk.collect.android.openrosa.CaseInsensitiveHeaders) CaseInsensitiveEmptyHeaders(org.odk.collect.android.openrosa.CaseInsensitiveEmptyHeaders) Request(okhttp3.Request) HttpHeadResult(org.odk.collect.android.openrosa.HttpHeadResult) Date(java.util.Date) NonNull(androidx.annotation.NonNull)

Aggregations

NonNull (androidx.annotation.NonNull)2 CaseInsensitiveEmptyHeaders (org.odk.collect.android.openrosa.CaseInsensitiveEmptyHeaders)2 HttpHeadResult (org.odk.collect.android.openrosa.HttpHeadResult)2 Date (java.util.Date)1 Request (okhttp3.Request)1 Response (okhttp3.Response)1 CaseInsensitiveHeaders (org.odk.collect.android.openrosa.CaseInsensitiveHeaders)1 OpenRosaServerClient (org.odk.collect.android.openrosa.OpenRosaServerClient)1