當前位置: 首頁>>代碼示例>>Java>>正文


Java HttpEntityEnclosingRequest.setHeader方法代碼示例

本文整理匯總了Java中org.apache.http.HttpEntityEnclosingRequest.setHeader方法的典型用法代碼示例。如果您正苦於以下問題:Java HttpEntityEnclosingRequest.setHeader方法的具體用法?Java HttpEntityEnclosingRequest.setHeader怎麽用?Java HttpEntityEnclosingRequest.setHeader使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.apache.http.HttpEntityEnclosingRequest的用法示例。


在下文中一共展示了HttpEntityEnclosingRequest.setHeader方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: consumesBodyOf100ContinueResponseIfItArrives

import org.apache.http.HttpEntityEnclosingRequest; //導入方法依賴的package包/類
@Test
public void consumesBodyOf100ContinueResponseIfItArrives() throws Exception {
    final HttpEntityEnclosingRequest req = new BasicHttpEntityEnclosingRequest("POST", "/", HttpVersion.HTTP_1_1);
    final int nbytes = 128;
    req.setHeader("Content-Length","" + nbytes);
    req.setHeader("Content-Type", "application/octet-stream");
    final HttpEntity postBody = new ByteArrayEntity(HttpTestUtils.getRandomBytes(nbytes));
    req.setEntity(postBody);
    final HttpRequestWrapper wrapper = HttpRequestWrapper.wrap(req);

    final HttpResponse resp = new BasicHttpResponse(HttpVersion.HTTP_1_1, HttpStatus.SC_CONTINUE, "Continue");
    final Flag closed = new Flag();
    final ByteArrayInputStream bais = makeTrackableBody(nbytes, closed);
    resp.setEntity(new InputStreamEntity(bais, -1));

    try {
        impl.ensureProtocolCompliance(wrapper, resp);
    } catch (final ClientProtocolException expected) {
    }
    assertTrue(closed.set || bais.read() == -1);
}
 
開發者ID:MyPureCloud,項目名稱:purecloud-iot,代碼行數:22,代碼來源:TestResponseProtocolCompliance.java

示例2: testInvalidatesUrisInContentLocationHeadersOnPUTs

import org.apache.http.HttpEntityEnclosingRequest; //導入方法依賴的package包/類
@Test
public void testInvalidatesUrisInContentLocationHeadersOnPUTs() throws Exception {
    final HttpEntityEnclosingRequest putRequest = new BasicHttpEntityEnclosingRequest("PUT","/",HTTP_1_1);
    putRequest.setEntity(HttpTestUtils.makeBody(128));
    putRequest.setHeader("Content-Length","128");

    final String contentLocation = "http://foo.example.com/content";
    putRequest.setHeader("Content-Location", contentLocation);

    final String theUri = "http://foo.example.com:80/";
    cacheEntryHasVariantMap(new HashMap<String,String>());

    cacheReturnsEntryForUri(theUri);

    impl.flushInvalidatedCacheEntries(host, putRequest);

    verify(mockEntry).getVariantMap();
    verify(mockStorage).getEntry(theUri);
    verify(mockStorage).removeEntry(theUri);
    verify(mockStorage).removeEntry("http://foo.example.com:80/content");
}
 
開發者ID:MyPureCloud,項目名稱:purecloud-iot,代碼行數:22,代碼來源:TestCacheInvalidator.java

示例3: testInvalidatesUrisInLocationHeadersOnPUTs

import org.apache.http.HttpEntityEnclosingRequest; //導入方法依賴的package包/類
@Test
public void testInvalidatesUrisInLocationHeadersOnPUTs() throws Exception {
    final HttpEntityEnclosingRequest putRequest = new BasicHttpEntityEnclosingRequest("PUT","/",HTTP_1_1);
    putRequest.setEntity(HttpTestUtils.makeBody(128));
    putRequest.setHeader("Content-Length","128");

    final String contentLocation = "http://foo.example.com/content";
    putRequest.setHeader("Location",contentLocation);

    final String theUri = "http://foo.example.com:80/";
    cacheEntryHasVariantMap(new HashMap<String,String>());

    cacheReturnsEntryForUri(theUri);

    impl.flushInvalidatedCacheEntries(host, putRequest);

    verify(mockEntry).getVariantMap();
    verify(mockStorage).getEntry(theUri);
    verify(mockStorage).removeEntry(theUri);
    verify(mockStorage).removeEntry(cacheKeyGenerator.canonicalizeUri(contentLocation));
}
 
開發者ID:MyPureCloud,項目名稱:purecloud-iot,代碼行數:22,代碼來源:TestCacheInvalidator.java

示例4: testInvalidatesRelativeUrisInContentLocationHeadersOnPUTs

import org.apache.http.HttpEntityEnclosingRequest; //導入方法依賴的package包/類
@Test
public void testInvalidatesRelativeUrisInContentLocationHeadersOnPUTs() throws Exception {
    final HttpEntityEnclosingRequest putRequest = new BasicHttpEntityEnclosingRequest("PUT","/",HTTP_1_1);
    putRequest.setEntity(HttpTestUtils.makeBody(128));
    putRequest.setHeader("Content-Length","128");

    final String relativePath = "/content";
    putRequest.setHeader("Content-Location",relativePath);

    final String theUri = "http://foo.example.com:80/";
    cacheEntryHasVariantMap(new HashMap<String,String>());

    cacheReturnsEntryForUri(theUri);

    impl.flushInvalidatedCacheEntries(host, putRequest);

    verify(mockEntry).getVariantMap();
    verify(mockStorage).getEntry(theUri);
    verify(mockStorage).removeEntry(theUri);
    verify(mockStorage).removeEntry("http://foo.example.com:80/content");
}
 
開發者ID:MyPureCloud,項目名稱:purecloud-iot,代碼行數:22,代碼來源:TestCacheInvalidator.java

示例5: testDoesNotInvalidateUrisInContentLocationHeadersOnPUTsToDifferentHosts

import org.apache.http.HttpEntityEnclosingRequest; //導入方法依賴的package包/類
@Test
public void testDoesNotInvalidateUrisInContentLocationHeadersOnPUTsToDifferentHosts() throws Exception {
    final HttpEntityEnclosingRequest putRequest = new BasicHttpEntityEnclosingRequest("PUT","/",HTTP_1_1);
    putRequest.setEntity(HttpTestUtils.makeBody(128));
    putRequest.setHeader("Content-Length","128");

    final String contentLocation = "http://bar.example.com/content";
    putRequest.setHeader("Content-Location",contentLocation);

    final String theUri = "http://foo.example.com:80/";
    cacheEntryHasVariantMap(new HashMap<String,String>());

    cacheReturnsEntryForUri(theUri);

    impl.flushInvalidatedCacheEntries(host, putRequest);

    verify(mockEntry).getVariantMap();
    verify(mockStorage).getEntry(theUri);
    verify(mockStorage).removeEntry(theUri);
}
 
開發者ID:MyPureCloud,項目名稱:purecloud-iot,代碼行數:21,代碼來源:TestCacheInvalidator.java

示例6: addCustomeHeads

import org.apache.http.HttpEntityEnclosingRequest; //導入方法依賴的package包/類
protected static void addCustomeHeads(Map<String, String> heads, HttpEntityEnclosingRequest request) {
    if (null == heads ) return;

    for (Map.Entry<String, String> entry : heads.entrySet()){
        request.setHeader(entry.getKey(), entry.getValue());
    }
}
 
開發者ID:AschPlatform,項目名稱:asch-java,代碼行數:8,代碼來源:REST.java

示例7: shouldAdaptContentEncodingHeaders

import org.apache.http.HttpEntityEnclosingRequest; //導入方法依賴的package包/類
@Test
public void shouldAdaptContentEncodingHeaders() throws Exception {
    final HttpEntityEnclosingRequest request = new BasicHttpEntityEnclosingRequest("GET", "http://example.com");
    request.setEntity(new ByteArrayEntity(new byte[2]));

    request.setHeader(HTTP.CONTENT_ENCODING, "some-encoding");

    unit.process(request, context);

    final List<Header> headers = asList(request.getHeaders(HTTP.CONTENT_ENCODING));
    assertThat(headers, hasSize(1));
    assertThat(headers, hasItem(allOf(
            hasFeature(BasicHeader::getName, is(HTTP.CONTENT_ENCODING)),
            hasFeature(BasicHeader::getValue, is("gzip")))));
}
 
開發者ID:zalando-stups,項目名稱:put-it-to-rest,代碼行數:16,代碼來源:GzippingHttpRequestInterceptorTest.java

示例8: shouldRemoveContentLengthHeaders

import org.apache.http.HttpEntityEnclosingRequest; //導入方法依賴的package包/類
@Test
public void shouldRemoveContentLengthHeaders() throws Exception {
    final HttpEntityEnclosingRequest request = new BasicHttpEntityEnclosingRequest("GET", "http://example.com");
    request.setEntity(new ByteArrayEntity(new byte[2]));

    request.setHeader(HTTP.CONTENT_LEN, "2");

    unit.process(request, context);

    final List<Header> headers = asList(request.getHeaders(HTTP.CONTENT_LEN));
    assertThat(headers, hasSize(0));
}
 
開發者ID:zalando-stups,項目名稱:put-it-to-rest,代碼行數:13,代碼來源:GzippingHttpRequestInterceptorTest.java

示例9: shouldAdaptTransferEncodingHeaders

import org.apache.http.HttpEntityEnclosingRequest; //導入方法依賴的package包/類
@Test
public void shouldAdaptTransferEncodingHeaders() throws Exception {
    final HttpEntityEnclosingRequest request = new BasicHttpEntityEnclosingRequest("GET", "http://example.com");
    request.setEntity(new ByteArrayEntity(new byte[2]));

    request.setHeader(HTTP.TRANSFER_ENCODING, "some-encoding");

    unit.process(request, context);

    final List<Header> headers = asList(request.getHeaders(HTTP.TRANSFER_ENCODING));
    assertThat(headers, hasSize(1));
    assertThat(headers, hasItem(allOf(
            hasFeature(BasicHeader::getName, is(HTTP.TRANSFER_ENCODING)),
            hasFeature(BasicHeader::getValue, is(HTTP.CHUNK_CODING)))));
}
 
開發者ID:zalando-stups,項目名稱:put-it-to-rest,代碼行數:16,代碼來源:GzippingHttpRequestInterceptorTest.java

示例10: testDoesNotModifyContentLengthOnRequests

import org.apache.http.HttpEntityEnclosingRequest; //導入方法依賴的package包/類
@Test
public void testDoesNotModifyContentLengthOnRequests()
        throws Exception {
    final HttpEntityEnclosingRequest post =
        new BasicHttpEntityEnclosingRequest("POST", "/", HttpVersion.HTTP_1_1);
    post.setEntity(HttpTestUtils.makeBody(128));
    post.setHeader("Content-Length","128");
    request = HttpRequestWrapper.wrap(post);
    testDoesNotModifyHeaderOnRequests("Content-Length");
}
 
開發者ID:MyPureCloud,項目名稱:purecloud-iot,代碼行數:11,代碼來源:TestProtocolRecommendations.java

示例11: testDoesNotModifyContentMD5OnRequests

import org.apache.http.HttpEntityEnclosingRequest; //導入方法依賴的package包/類
@Test
public void testDoesNotModifyContentMD5OnRequests()
        throws Exception {
    final HttpEntityEnclosingRequest post =
        new BasicHttpEntityEnclosingRequest("POST", "/", HttpVersion.HTTP_1_1);
    post.setEntity(HttpTestUtils.makeBody(128));
    post.setHeader("Content-Length","128");
    post.setHeader("Content-MD5","Q2hlY2sgSW50ZWdyaXR5IQ==");
    request = HttpRequestWrapper.wrap(post);
    testDoesNotModifyHeaderOnRequests("Content-MD5");
}
 
開發者ID:MyPureCloud,項目名稱:purecloud-iot,代碼行數:12,代碼來源:TestProtocolRecommendations.java

示例12: testDoesNotModifyContentRangeOnRequests

import org.apache.http.HttpEntityEnclosingRequest; //導入方法依賴的package包/類
@Test
public void testDoesNotModifyContentRangeOnRequests()
        throws Exception {
    final HttpEntityEnclosingRequest put =
        new BasicHttpEntityEnclosingRequest("PUT", "/", HttpVersion.HTTP_1_1);
    put.setEntity(HttpTestUtils.makeBody(128));
    put.setHeader("Content-Length","128");
    put.setHeader("Content-Range","bytes 0-127/256");
    request = HttpRequestWrapper.wrap(put);
    testDoesNotModifyHeaderOnRequests("Content-Range");
}
 
開發者ID:MyPureCloud,項目名稱:purecloud-iot,代碼行數:12,代碼來源:TestProtocolRecommendations.java

示例13: testDoesNotModifyContentTypeOnRequests

import org.apache.http.HttpEntityEnclosingRequest; //導入方法依賴的package包/類
@Test
public void testDoesNotModifyContentTypeOnRequests()
        throws Exception {
    final HttpEntityEnclosingRequest post =
        new BasicHttpEntityEnclosingRequest("POST", "/", HttpVersion.HTTP_1_1);
    post.setEntity(HttpTestUtils.makeBody(128));
    post.setHeader("Content-Length","128");
    post.setHeader("Content-Type","application/octet-stream");
    request = HttpRequestWrapper.wrap(post);
    testDoesNotModifyHeaderOnRequests("Content-Type");
}
 
開發者ID:MyPureCloud,項目名稱:purecloud-iot,代碼行數:12,代碼來源:TestProtocolRecommendations.java

示例14: testPUTWithIfMatchWeakETagIsNotAllowed

import org.apache.http.HttpEntityEnclosingRequest; //導入方法依賴的package包/類
@Test
public void testPUTWithIfMatchWeakETagIsNotAllowed() throws Exception {
    final HttpEntityEnclosingRequest put = new BasicHttpEntityEnclosingRequest("PUT", "/", HttpVersion.HTTP_1_1);
    put.setEntity(HttpTestUtils.makeBody(128));
    put.setHeader("Content-Length", "128");
    put.setHeader("If-Match", "W/\"etag\"");
    request = HttpRequestWrapper.wrap(put);

    testRequestWithWeakETagValidatorIsNotAllowed("If-Match");
}
 
開發者ID:MyPureCloud,項目名稱:purecloud-iot,代碼行數:11,代碼來源:TestProtocolRequirements.java

示例15: testPUTWithIfNoneMatchWeakETagIsNotAllowed

import org.apache.http.HttpEntityEnclosingRequest; //導入方法依賴的package包/類
@Test
public void testPUTWithIfNoneMatchWeakETagIsNotAllowed() throws Exception {
    final HttpEntityEnclosingRequest put = new BasicHttpEntityEnclosingRequest("PUT", "/", HttpVersion.HTTP_1_1);
    put.setEntity(HttpTestUtils.makeBody(128));
    put.setHeader("Content-Length", "128");
    put.setHeader("If-None-Match", "W/\"etag\"");
    request = HttpRequestWrapper.wrap(put);

    testRequestWithWeakETagValidatorIsNotAllowed("If-None-Match");
}
 
開發者ID:MyPureCloud,項目名稱:purecloud-iot,代碼行數:11,代碼來源:TestProtocolRequirements.java


注:本文中的org.apache.http.HttpEntityEnclosingRequest.setHeader方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。