本文整理了Java中org.apache.hc.core5.http.HttpRequest.getMethod()
方法的一些代码示例,展示了HttpRequest.getMethod()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。HttpRequest.getMethod()
方法的具体详情如下:
包路径:org.apache.hc.core5.http.HttpRequest
类名称:HttpRequest
方法名:getMethod
[英]Returns method of this request message.
[中]返回此请求消息的方法。
代码示例来源:origin: apache/httpcomponents-client
private boolean isGet(final HttpRequest request) {
return request.getMethod().equals(HeaderConstants.GET_METHOD);
}
代码示例来源:origin: apache/httpcomponents-client
static boolean requestIsGet(final HttpRequest req) {
return req.getMethod().equals((HeaderConstants.GET_METHOD));
}
代码示例来源:origin: apache/httpcomponents-client
static boolean requestShouldNotBeCached(final HttpRequest req) {
final String method = req.getMethod();
return notGetOrHeadRequest(method);
}
代码示例来源:origin: apache/httpcomponents-client
private boolean responseShouldContainEntity(final HttpRequest request, final HttpCacheEntry cacheEntry) {
return request.getMethod().equals(HeaderConstants.GET_METHOD) && cacheEntry.getResource() != null;
}
代码示例来源:origin: apache/httpcomponents-client
boolean clientRequestsOurOptions(final HttpRequest request) {
if (!HeaderConstants.OPTIONS_METHOD.equals(request.getMethod())) {
return false;
}
if (!"*".equals(request.getRequestUri())) {
return false;
}
final Header h = request.getFirstHeader(HeaderConstants.MAX_FORWARDS);
if (!"0".equals(h != null ? h.getValue() : null)) {
return false;
}
return true;
}
代码示例来源:origin: apache/httpcomponents-client
private void decrementOPTIONSMaxForwardsIfGreaterThen0(final HttpRequest request) {
if (!HeaderConstants.OPTIONS_METHOD.equals(request.getMethod())) {
return;
}
final Header maxForwards = request.getFirstHeader(HeaderConstants.MAX_FORWARDS);
if (maxForwards == null) {
return;
}
request.removeHeaders(HeaderConstants.MAX_FORWARDS);
final int currentMaxForwards = Integer.parseInt(maxForwards.getValue());
request.setHeader(HeaderConstants.MAX_FORWARDS, Integer.toString(currentMaxForwards - 1));
}
代码示例来源:origin: apache/httpcomponents-client
private void ensure200ForOPTIONSRequestWithNoBodyHasContentLengthZero(final HttpRequest request,
final HttpResponse response) {
if (!request.getMethod().equalsIgnoreCase(HeaderConstants.OPTIONS_METHOD)) {
return;
}
if (response.getCode() != HttpStatus.SC_OK) {
return;
}
if (response.getFirstHeader(HttpHeaders.CONTENT_LENGTH) == null) {
response.addHeader(HttpHeaders.CONTENT_LENGTH, "0");
}
}
代码示例来源:origin: apache/httpcomponents-client
@Override
public void flushCacheEntriesFor(final HttpHost host, final HttpRequest request) {
if (log.isDebugEnabled()) {
log.debug("Flush cache entries: " + host + "; " + new RequestLine(request));
}
if (!StandardMethods.isSafe(request.getMethod())) {
final String cacheKey = cacheKeyGenerator.generateKey(host, request);
try {
storage.removeEntry(cacheKey);
} catch (final ResourceIOException ex) {
if (log.isWarnEnabled()) {
log.warn("I/O error removing cache entry with key " + cacheKey);
}
}
}
}
代码示例来源:origin: apache/httpcomponents-client
@Override
public void flushCacheEntriesInvalidatedByExchange(final HttpHost host, final HttpRequest request, final HttpResponse response) {
if (log.isDebugEnabled()) {
log.debug("Flush cache entries invalidated by exchange: " + host + "; " + new RequestLine(request) + " -> " + new StatusLine(response));
}
if (!StandardMethods.isSafe(request.getMethod())) {
cacheInvalidator.flushCacheEntriesInvalidatedByExchange(host, request, response, cacheKeyGenerator, storage);
}
}
代码示例来源:origin: apache/httpcomponents-client
private RequestProtocolError requestHasWeakETagAndRange(final HttpRequest request) {
// TODO: Should these be looking at all the headers marked as Range?
final String method = request.getMethod();
if (!(HeaderConstants.GET_METHOD.equals(method))) {
return null;
}
final Header range = request.getFirstHeader(HeaderConstants.RANGE);
if (range == null) {
return null;
}
final Header ifRange = request.getFirstHeader(HeaderConstants.IF_RANGE);
if (ifRange == null) {
return null;
}
final String val = ifRange.getValue();
if (val.startsWith("W/")) {
return RequestProtocolError.WEAK_ETAG_AND_RANGE_ERROR;
}
return null;
}
代码示例来源:origin: apache/httpcomponents-client
private RequestProtocolError requestHasWeekETagForPUTOrDELETEIfMatch(final HttpRequest request) {
// TODO: Should these be looking at all the headers marked as If-Match/If-None-Match?
final String method = request.getMethod();
if (!(HeaderConstants.PUT_METHOD.equals(method) || HeaderConstants.DELETE_METHOD.equals(method))) {
return null;
}
final Header ifMatch = request.getFirstHeader(HeaderConstants.IF_MATCH);
if (ifMatch != null) {
final String val = ifMatch.getValue();
if (val.startsWith("W/")) {
return RequestProtocolError.WEAK_ETAG_ON_PUTDELETE_METHOD_ERROR;
}
} else {
final Header ifNoneMatch = request.getFirstHeader(HeaderConstants.IF_NONE_MATCH);
if (ifNoneMatch == null) {
return null;
}
final String val2 = ifNoneMatch.getValue();
if (val2.startsWith("W/")) {
return RequestProtocolError.WEAK_ETAG_ON_PUTDELETE_METHOD_ERROR;
}
}
return null;
}
代码示例来源:origin: apache/httpcomponents-client
final String method = request.getMethod();
代码示例来源:origin: apache/httpcomponents-client
final ResponseChannel responseChannel,
final HttpContext context) throws HttpException, IOException {
final String method = request.getMethod();
if (!"GET".equalsIgnoreCase(method) &&
!"HEAD".equalsIgnoreCase(method) &&
代码示例来源:origin: apache/httpcomponents-client
@Override
public Cancellable flushCacheEntriesInvalidatedByExchange(
final HttpHost host, final HttpRequest request, final HttpResponse response, final FutureCallback<Boolean> callback) {
if (log.isDebugEnabled()) {
log.debug("Flush cache entries invalidated by exchange: " + host + "; " + new RequestLine(request) + " -> " + new StatusLine(response));
}
if (!StandardMethods.isSafe(request.getMethod())) {
return cacheInvalidator.flushCacheEntriesInvalidatedByExchange(host, request, response, cacheKeyGenerator, storage, callback);
}
callback.completed(Boolean.TRUE);
return Operations.nonCancellable();
}
代码示例来源:origin: apache/httpcomponents-client
final ResponseChannel responseChannel,
final HttpContext context) throws HttpException, IOException {
final String method = request.getMethod();
if (!"GET".equalsIgnoreCase(method) &&
!"HEAD".equalsIgnoreCase(method) &&
代码示例来源:origin: apache/httpcomponents-client
log.debug("Flush cache entries: " + host + "; " + new RequestLine(request));
if (!StandardMethods.isSafe(request.getMethod())) {
final String cacheKey = cacheKeyGenerator.generateKey(host, request);
return storage.removeEntry(cacheKey, new FutureCallback<Boolean>() {
代码示例来源:origin: apache/httpcomponents-client
@Test
public void testBuildUnconditionalRequestUsesGETMethod()
throws Exception {
final HttpRequest result = impl.buildUnconditionalRequest(request);
Assert.assertEquals("GET", result.getMethod());
}
代码示例来源:origin: apache/httpcomponents-client
public static boolean equivalent(final HttpRequest r1, final HttpRequest r2) {
return equivalent(r1.getVersion(), r2.getVersion()) &&
LangUtils.equals(r1.getMethod(), r2.getMethod()) &&
LangUtils.equals(r1.getRequestUri(), r2.getRequestUri()) &&
isEndToEndHeaderSubset(r1, r2);
}
代码示例来源:origin: apache/httpcomponents-client
@Test
public void testBuildConditionalRequestWithETag() {
final String theMethod = "GET";
final String theUri = "/theuri";
final String theETag = "this is my eTag";
final HttpRequest basicRequest = new BasicHttpRequest(theMethod, theUri);
basicRequest.addHeader("Accept-Encoding", "gzip");
final HttpRequest requestWrapper = RequestCopier.INSTANCE.copy(basicRequest);
final Header[] headers = new Header[] {
new BasicHeader("Date", DateUtils.formatDate(new Date())),
new BasicHeader("Last-Modified", DateUtils.formatDate(new Date())),
new BasicHeader("ETag", theETag) };
final HttpCacheEntry cacheEntry = HttpTestUtils.makeCacheEntry(headers);
final HttpRequest newRequest = impl.buildConditionalRequest(requestWrapper, cacheEntry);
Assert.assertNotSame(basicRequest, newRequest);
Assert.assertEquals(theMethod, newRequest.getMethod());
Assert.assertEquals(theUri, newRequest.getRequestUri());
Assert.assertEquals(3, newRequest.getHeaders().length);
Assert.assertEquals("Accept-Encoding", newRequest.getHeaders()[0].getName());
Assert.assertEquals("gzip", newRequest.getHeaders()[0].getValue());
Assert.assertEquals("If-None-Match", newRequest.getHeaders()[1].getName());
Assert.assertEquals(theETag, newRequest.getHeaders()[1].getValue());
}
代码示例来源:origin: apache/httpcomponents-client
@Test
public void testBuildConditionalRequestWithLastModified() {
final String theMethod = "GET";
final String theUri = "/theuri";
final String lastModified = "this is my last modified date";
final HttpRequest basicRequest = new BasicHttpRequest(theMethod, theUri);
basicRequest.addHeader("Accept-Encoding", "gzip");
final HttpRequest requestWrapper = RequestCopier.INSTANCE.copy(basicRequest);
final Header[] headers = new Header[] {
new BasicHeader("Date", DateUtils.formatDate(new Date())),
new BasicHeader("Last-Modified", lastModified) };
final HttpCacheEntry cacheEntry = HttpTestUtils.makeCacheEntry(headers);
final HttpRequest newRequest = impl.buildConditionalRequest(requestWrapper, cacheEntry);
Assert.assertNotSame(basicRequest, newRequest);
Assert.assertEquals(theMethod, newRequest.getMethod());
Assert.assertEquals(theUri, newRequest.getRequestUri());
Assert.assertEquals(2, newRequest.getHeaders().length);
Assert.assertEquals("Accept-Encoding", newRequest.getHeaders()[0].getName());
Assert.assertEquals("gzip", newRequest.getHeaders()[0].getValue());
Assert.assertEquals("If-Modified-Since", newRequest.getHeaders()[1].getName());
Assert.assertEquals(lastModified, newRequest.getHeaders()[1].getValue());
}
内容来源于网络,如有侵权,请联系作者删除!