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

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

Introduction

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

Prototype

String EXPECT_DIRECTIVE

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

Click Source Link

Usage

From source file:ch.cyberduck.core.dav.DAVWriteFeature.java

@Override
public ResponseOutputStream<String> write(final Path file, final TransferStatus status)
        throws BackgroundException {
    final List<Header> headers = new ArrayList<Header>();
    if (status.isAppend()) {
        final HttpRange range = HttpRange.withStatus(status);
        // Content-Range entity-header is sent with a partial entity-body to specify where
        // in the full entity-body the partial body should be applied.
        final String header = String.format("bytes %d-%d/%d", range.getStart(), range.getEnd(),
                status.getOffset() + status.getLength());
        if (log.isDebugEnabled()) {
            log.debug(String.format("Add range header %s for file %s", header, file));
        }/*  w  w w  . j av  a2  s .  com*/
        headers.add(new BasicHeader(HttpHeaders.CONTENT_RANGE, header));
    }
    if (expect) {
        if (status.getLength() > 0L) {
            headers.add(new BasicHeader(HTTP.EXPECT_DIRECTIVE, HTTP.EXPECT_CONTINUE));
        }
    }
    return this.write(file, headers, status);
}

From source file:com.android.idtt.http.client.HttpRequest.java

public boolean expectContinue() {
    Header expect = getFirstHeader(HTTP.EXPECT_DIRECTIVE);
    return expect != null && HTTP.EXPECT_CONTINUE.equalsIgnoreCase(expect.getValue());
}

From source file:ch.cyberduck.core.s3.RequestEntityRestStorageService.java

@Override
protected HttpUriRequest setupConnection(final HTTP_METHOD method, final String bucketName,
        final String objectKey, final Map<String, String> requestParameters) throws S3ServiceException {
    final HttpUriRequest request = super.setupConnection(method, bucketName, objectKey, requestParameters);
    if (preferences.getBoolean("s3.upload.expect-continue")) {
        if ("PUT".equals(request.getMethod())) {
            // #7621
            final Jets3tProperties properties = getJetS3tProperties();
            if (!properties.getBoolProperty("s3service.disable-expect-continue", false)) {
                request.addHeader(HTTP.EXPECT_DIRECTIVE, HTTP.EXPECT_CONTINUE);
            }//  www .j  a va  2  s .  c  o m
        }
    }
    if (preferences.getBoolean("s3.bucket.requesterpays")) {
        // Only for AWS
        if (session.getHost().getHostname().endsWith(preferences.getProperty("s3.hostname.default"))) {
            // Downloading Objects in Requester Pays Buckets
            if ("GET".equals(request.getMethod()) || "POST".equals(request.getMethod())) {
                final Jets3tProperties properties = getJetS3tProperties();
                if (!properties.getBoolProperty("s3service.disable-request-payer", false)) {
                    // For GET and POST requests, include x-amz-request-payer : requester in the header
                    request.addHeader("x-amz-request-payer", "requester");
                }
            }
        }
    }
    return request;
}

From source file:net.kungfoo.grizzly.proxy.impl.ProxyAdapter.java

private static boolean isExpectContinue(Request request) {
    String expect = request.getHeader(HTTP.EXPECT_DIRECTIVE);
    return expect != null && HTTP.EXPECT_CONTINUE.equalsIgnoreCase(expect);

}

From source file:cn.isif.util_plus.http.client.HttpRequest.java

@Override
public boolean expectContinue() {
    Header expect = getFirstHeader(HTTP.EXPECT_DIRECTIVE);
    return expect != null && HTTP.EXPECT_CONTINUE.equalsIgnoreCase(expect.getValue());
}

From source file:com.apigee.sdk.apm.http.impl.client.cache.RequestProtocolCompliance.java

private void remove100ContinueHeaderIfExists(HttpRequest request) {
    boolean hasHeader = false;

    Header[] expectHeaders = request.getHeaders(HTTP.EXPECT_DIRECTIVE);
    List<HeaderElement> expectElementsThatAreNot100Continue = new ArrayList<HeaderElement>();

    for (Header h : expectHeaders) {
        for (HeaderElement elt : h.getElements()) {
            if (!(HTTP.EXPECT_CONTINUE.equalsIgnoreCase(elt.getName()))) {
                expectElementsThatAreNot100Continue.add(elt);
            } else {
                hasHeader = true;/*  w  w  w  . j  av  a  2  s.  com*/
            }
        }

        if (hasHeader) {
            request.removeHeader(h);
            for (HeaderElement elt : expectElementsThatAreNot100Continue) {
                BasicHeader newHeader = new BasicHeader(HTTP.EXPECT_DIRECTIVE, elt.getName());
                request.addHeader(newHeader);
            }
            return;
        } else {
            expectElementsThatAreNot100Continue = new ArrayList<HeaderElement>();
        }
    }
}

From source file:com.apigee.sdk.apm.http.impl.client.cache.RequestProtocolCompliance.java

private void add100ContinueHeaderIfMissing(HttpRequest request) {
    boolean hasHeader = false;

    for (Header h : request.getHeaders(HTTP.EXPECT_DIRECTIVE)) {
        for (HeaderElement elt : h.getElements()) {
            if (HTTP.EXPECT_CONTINUE.equalsIgnoreCase(elt.getName())) {
                hasHeader = true;/*from   w  ww. j  a v  a  2s  .c  o m*/
            }
        }
    }

    if (!hasHeader) {
        request.addHeader(HTTP.EXPECT_DIRECTIVE, HTTP.EXPECT_CONTINUE);
    }
}

From source file:com.google.oacurl.Fetch.java

private static void addHeadersToRequest(OAuthMessage request, List<Parameter> headers) {
    // HACK(phopkins): If someone added their own Expect header, then tell
    // Apache not to add its own. This is a bit hacky, but gets around that
    // the RequestExpectContinue class doesn't check for an existing header
    // before adding its own.
    ///*from  w  w  w  . jav a2 s .c  o m*/
    // Fix for: http://code.google.com/p/oacurl/issues/detail?id=1
    boolean hasExpect = false;
    for (Parameter param : headers) {
        if (param.getKey().equalsIgnoreCase(HTTP.EXPECT_DIRECTIVE)) {
            hasExpect = true;
            break;
        }
    }

    if (hasExpect) {
        HttpProtocolParams.setUseExpectContinue(SingleClient.HTTP_CLIENT_POOL.getHttpClient().getParams(),
                false);
    }

    request.getHeaders().addAll(headers);
}

From source file:ch.cyberduck.core.dav.DAVPath.java

@Override
public ResponseOutputStream<Void> write(final TransferStatus status) throws IOException {
    final Map<String, String> headers = new HashMap<String, String>();
    if (status.isResume()) {
        headers.put(HttpHeaders.CONTENT_RANGE,
                "bytes " + status.getCurrent() + "-" + (status.getLength() - 1) + "/" + status.getLength());
    }/*from   w w  w.j av a 2 s .c  o m*/
    if (Preferences.instance().getBoolean("webdav.expect-continue")) {
        headers.put(HTTP.EXPECT_DIRECTIVE, HTTP.EXPECT_CONTINUE);
    }
    try {
        return this.write(headers, status);
    } catch (HttpResponseException e) {
        if (e.getStatusCode() == HttpStatus.SC_EXPECTATION_FAILED) {
            // Retry with the Expect header removed
            headers.remove(HTTP.EXPECT_DIRECTIVE);
            return this.write(headers, status);
        } else {
            throw e;
        }
    }
}