本文整理匯總了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);
}
示例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");
}
示例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));
}
示例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");
}
示例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);
}
示例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());
}
}
示例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")))));
}
示例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));
}
示例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)))));
}
示例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");
}
示例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");
}
示例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");
}
示例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");
}
示例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");
}
示例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");
}