Example usage for org.apache.http.protocol HTTP TRANSFER_ENCODING

List of usage examples for org.apache.http.protocol HTTP TRANSFER_ENCODING

Introduction

In this page you can find the example usage for org.apache.http.protocol HTTP TRANSFER_ENCODING.

Prototype

String TRANSFER_ENCODING

To view the source code for org.apache.http.protocol HTTP TRANSFER_ENCODING.

Click Source Link

Usage

From source file:net.oneandone.sushi.fs.webdav.methods.Put.java

@Override
protected void setContentHeader() {
    setRequestHeader(HTTP.TRANSFER_ENCODING, HTTP.CHUNK_CODING);
}

From source file:com.microsoft.exchange.impl.SoapHttpRequestHeaderInterceptor.java

@Override
public void process(HttpRequest request, HttpContext context) throws HttpException, IOException {
    if (request.containsHeader(HTTP.TRANSFER_ENCODING)) {
        request.removeHeaders(HTTP.TRANSFER_ENCODING);
    }/*  w  w  w.  j a  va  2  s . c  o  m*/
    if (request.containsHeader(HTTP.CONTENT_LEN)) {
        request.removeHeaders(HTTP.CONTENT_LEN);
    }
}

From source file:org.muhia.app.psi.integ.config.interceptors.RemoveHttpHeadersInterceptor.java

@Override
public void process(HttpRequest request, HttpContext context) throws HttpException, IOException {
    if (request instanceof HttpEntityEnclosingRequest) {
        if (request.containsHeader(HTTP.TRANSFER_ENCODING)) {
            request.removeHeaders(HTTP.TRANSFER_ENCODING);
        }//w  ww  .  j a  v  a 2 s  . c o  m
        if (request.containsHeader(HTTP.CONTENT_LEN)) {
            request.removeHeaders(HTTP.CONTENT_LEN);
        }
    }
}

From source file:com.subgraph.vega.internal.http.proxy.ResponseContentCustom.java

public void process(final HttpResponse response, final HttpContext context) throws HttpException, IOException {
    if (response == null) {
        throw new IllegalArgumentException("HTTP response may not be null");
    }//from ww  w  .ja  v a  2s.  c  o m

    ProtocolVersion ver = response.getStatusLine().getProtocolVersion();
    HttpEntity entity = response.getEntity();

    if (entity != null) {
        long len = entity.getContentLength();

        if (entity.isChunked() && !ver.lessEquals(HttpVersion.HTTP_1_0)) {
            response.removeHeaders(HTTP.CONTENT_LEN);
            response.setHeader(HTTP.TRANSFER_ENCODING, HTTP.CHUNK_CODING);
        } else if (len >= 0) {
            response.removeHeaders(HTTP.TRANSFER_ENCODING);
            response.setHeader(HTTP.CONTENT_LEN, Long.toString(entity.getContentLength()));
        }

        // Specify a content type if known
        if (entity.getContentType() != null && !response.containsHeader(HTTP.CONTENT_TYPE)) {
            response.addHeader(entity.getContentType());
        }

        // Specify a content encoding if known
        if (entity.getContentEncoding() != null && !response.containsHeader(HTTP.CONTENT_ENCODING)) {
            response.addHeader(entity.getContentEncoding());
        }
    } else {
        int status = response.getStatusLine().getStatusCode();
        if (status != HttpStatus.SC_NO_CONTENT && status != HttpStatus.SC_NOT_MODIFIED
                && status != HttpStatus.SC_RESET_CONTENT) {
            response.setHeader(HTTP.CONTENT_LEN, "0");
        }
    }
}

From source file:com.grendelscan.commons.http.apache_overrides.client.CustomRequestContent.java

@Override
public void process(final HttpRequest request, final HttpContext context) throws HttpException, IOException {
    if (request == null) {
        throw new IllegalArgumentException("HTTP request may not be null");
    }//  w w  w  .j a  v a  2s  . c o m
    if (request instanceof HttpEntityEnclosingRequest) {
        if (request.containsHeader(HTTP.TRANSFER_ENCODING)) {
            request.removeHeaders(HTTP.TRANSFER_ENCODING);
        }
        if (request.containsHeader(HTTP.CONTENT_LEN)) {
            request.removeHeaders(HTTP.CONTENT_LEN);
        }
        ProtocolVersion ver = request.getRequestLine().getProtocolVersion();
        HttpEntity entity = ((HttpEntityEnclosingRequest) request).getEntity();
        if (entity == null) {
            request.addHeader(HTTP.CONTENT_LEN, "0");
            return;
        }
        // Must specify a transfer encoding or a content length
        if (entity.isChunked() || entity.getContentLength() < 0) {
            if (ver.lessEquals(HttpVersion.HTTP_1_0)) {
                throw new ProtocolException("Chunked transfer encoding not allowed for " + ver);
            }
            request.addHeader(HTTP.TRANSFER_ENCODING, HTTP.CHUNK_CODING);
        } else {
            request.addHeader(HTTP.CONTENT_LEN, Long.toString(entity.getContentLength()));
        }
        // Specify a content type if known
        if (entity.getContentType() != null && !request.containsHeader(HTTP.CONTENT_TYPE)) {
            request.addHeader(entity.getContentType());
        }
        // Specify a content encoding if known
        if (entity.getContentEncoding() != null && !request.containsHeader(HTTP.CONTENT_ENCODING)) {
            request.addHeader(entity.getContentEncoding());
        }
    }
}

From source file:com.huoqiu.framework.rest.HttpComponentsClientHttpRequest.java

@Override
public ClientHttpResponse executeInternal(HttpHeaders headers, byte[] bufferedOutput) throws IOException {
    for (Map.Entry<String, List<String>> entry : headers.entrySet()) {
        String headerName = entry.getKey();
        if (!headerName.equalsIgnoreCase(HTTP.CONTENT_LEN)
                && !headerName.equalsIgnoreCase(HTTP.TRANSFER_ENCODING)) {
            for (String headerValue : entry.getValue()) {
                this.httpRequest.addHeader(headerName, headerValue);
            }/*from  w  w w  .  j ava2  s.com*/
        }
    }
    if (this.httpRequest instanceof HttpEntityEnclosingRequest) {
        HttpEntityEnclosingRequest entityEnclosingReq = (HttpEntityEnclosingRequest) this.httpRequest;
        HttpEntity requestEntity = new ByteArrayEntity(bufferedOutput);
        entityEnclosingReq.setEntity(requestEntity);
    }
    HttpResponse httpResponse = httpClient.execute(this.httpRequest, this.httpContext);
    return new HttpComponentsClientHttpResponse(httpResponse);
}

From source file:ch.cyberduck.core.onedrive.OneDriveCommonsHttpRequestExecutor.java

protected Upload doUpload(final URL url, final Set<RequestHeader> headers,
        final HttpEntityEnclosingRequestBase request) {
    for (RequestHeader header : headers) {
        if (header.getKey().equals(HTTP.TRANSFER_ENCODING)) {
            continue;
        }/* w w  w  .j a v  a 2  s . c  om*/
        if (header.getKey().equals(HTTP.CONTENT_LEN)) {
            continue;
        }
        request.addHeader(new BasicHeader(header.getKey(), header.getValue()));
    }
    final CountDownLatch entry = new CountDownLatch(1);
    final DelayedHttpEntity entity = new DelayedHttpEntity(entry) {
        @Override
        public long getContentLength() {
            for (RequestHeader header : headers) {
                if (header.getKey().equals(HTTP.CONTENT_LEN)) {
                    return Long.valueOf(header.getValue());
                }
            }
            // Content-Encoding: chunked
            return -1L;
        }
    };
    request.setEntity(entity);
    final DefaultThreadPool executor = new DefaultThreadPool(String.format("http-%s", url), 1);
    final Future<CloseableHttpResponse> future = executor.execute(new Callable<CloseableHttpResponse>() {
        @Override
        public CloseableHttpResponse call() throws Exception {
            return client.execute(request);
        }
    });
    return new Upload() {
        @Override
        public Response getResponse() throws IOException {
            final CloseableHttpResponse response;
            try {
                response = future.get();
            } catch (InterruptedException e) {
                throw new IOException(e);
            } catch (ExecutionException e) {
                throw new IOException(e.getCause());
            } finally {
                executor.shutdown(false);
            }
            return new CommonsHttpResponse(response);
        }

        @Override
        public OutputStream getOutputStream() {
            try {
                // Await execution of HTTP request to make stream available
                entry.await();
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
            return entity.getStream();
        }
    };
}

From source file:org.greencheek.spring.rest.SSLCachingHttpComponentsClientHttpRequest.java

protected ClientHttpResponse executeInternal(HttpHeaders headers, byte[] bufferedOutput) throws IOException {
    for (Map.Entry<String, List<String>> entry : headers.entrySet()) {
        String headerName = entry.getKey();
        if (!headerName.equalsIgnoreCase(HTTP.CONTENT_LEN)
                && !headerName.equalsIgnoreCase(HTTP.TRANSFER_ENCODING)) {
            for (String headerValue : entry.getValue()) {
                this.httpRequest.addHeader(headerName, headerValue);
            }/*ww w  . j a  va2 s.  c  om*/
        }
    }
    if (this.httpRequest instanceof HttpEntityEnclosingRequest) {
        HttpEntityEnclosingRequest entityEnclosingRequest = (HttpEntityEnclosingRequest) this.httpRequest;
        HttpEntity requestEntity = new ByteArrayEntity(bufferedOutput);
        entityEnclosingRequest.setEntity(requestEntity);
    }

    setSSLPrinciple(this.httpContext);
    HttpResponse httpResponse = this.httpClient.execute(this.httpRequest, this.httpContext);
    saveSSLPrinciple(this.httpContext);
    return new SSLCachingHttpComponentsClientHttpResponse(httpResponse, this.httpContext);
}

From source file:com.subgraph.vega.internal.http.requests.HttpMessageBuilder.java

protected void setHeadersEntity() {
    if (entity != null) {
        if (entity.isChunked() || entity.getContentLength() < 0) {
            setHeader(HTTP.TRANSFER_ENCODING, HTTP.CHUNK_CODING);
            removeHeaders(HTTP.CONTENT_LEN);
        } else {/*from   ww w. j  a v  a 2 s .  c  om*/
            setHeader(HTTP.CONTENT_LEN, Long.toString(entity.getContentLength()));
            removeHeaders(HTTP.TRANSFER_ENCODING);
        }

        if (entity.getContentType() != null) {
            final Header h = entity.getContentType();
            setHeader(h.getName(), h.getValue());
        }

        if (entity.getContentEncoding() != null) {
            final Header h = entity.getContentEncoding();
            setHeader(h.getName(), h.getValue());
        }
    } else {
        removeHeaders(HTTP.CONTENT_LEN);
        removeHeaders(HTTP.TRANSFER_ENCODING);
    }
}