当前位置: 首页>>代码示例>>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;未经允许,请勿转载。