Search in sources :

Example 1 with RequestFilter

use of org.asynchttpclient.filter.RequestFilter in project async-http-client by AsyncHttpClient.

the class DefaultAsyncHttpClient method preProcessRequest.

/**
     * Configure and execute the associated {@link RequestFilter}. This class
     * may decorate the {@link Request} and {@link AsyncHandler}
     *
     * @param fc {@link FilterContext}
     * @return {@link FilterContext}
     */
private <T> FilterContext<T> preProcessRequest(FilterContext<T> fc) throws FilterException {
    for (RequestFilter asyncFilter : config.getRequestFilters()) {
        fc = asyncFilter.filter(fc);
        assertNotNull(fc, "filterContext");
    }
    Request request = fc.getRequest();
    if (fc.getAsyncHandler() instanceof ResumableAsyncHandler) {
        request = ResumableAsyncHandler.class.cast(fc.getAsyncHandler()).adjustRequestRange(request);
    }
    if (request.getRangeOffset() != 0) {
        RequestBuilder builder = new RequestBuilder(request);
        builder.setHeader("Range", "bytes=" + request.getRangeOffset() + "-");
        request = builder.build();
    }
    fc = new FilterContext.FilterContextBuilder<>(fc).request(request).build();
    return fc;
}
Also used : ResumableAsyncHandler(org.asynchttpclient.handler.resumable.ResumableAsyncHandler) RequestFilter(org.asynchttpclient.filter.RequestFilter) FilterContext(org.asynchttpclient.filter.FilterContext)

Aggregations

FilterContext (org.asynchttpclient.filter.FilterContext)1 RequestFilter (org.asynchttpclient.filter.RequestFilter)1 ResumableAsyncHandler (org.asynchttpclient.handler.resumable.ResumableAsyncHandler)1