本文整理汇总了Java中org.apache.http.HttpRequest.setHeader方法的典型用法代码示例。如果您正苦于以下问题:Java HttpRequest.setHeader方法的具体用法?Java HttpRequest.setHeader怎么用?Java HttpRequest.setHeader使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.http.HttpRequest
的用法示例。
在下文中一共展示了HttpRequest.setHeader方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: process
import org.apache.http.HttpRequest; //导入方法依赖的package包/类
public void process(final HttpRequest request, final HttpContext context)
throws HttpException, IOException {
if (request == null) {
throw new IllegalArgumentException
("HTTP request may not be null.");
}
if ((request instanceof HttpEntityEnclosingRequest) &&
!request.containsHeader(HTTP.DATE_HEADER)) {
String httpdate = DATE_GENERATOR.getCurrentDate();
request.setHeader(HTTP.DATE_HEADER, httpdate);
}
}
示例2: process
import org.apache.http.HttpRequest; //导入方法依赖的package包/类
public void process(final HttpRequest request, final HttpContext context)
throws HttpException, IOException {
if (request == null) {
throw new IllegalArgumentException("HTTP request may not be null");
}
String method = request.getRequestLine().getMethod();
if (method.equalsIgnoreCase("CONNECT")) {
request.setHeader(PROXY_CONN_DIRECTIVE, HTTP.CONN_KEEP_ALIVE);
return;
}
// Obtain the client connection (required)
HttpRoutedConnection conn = (HttpRoutedConnection) context.getAttribute(
ExecutionContext.HTTP_CONNECTION);
if (conn == null) {
this.log.debug("HTTP connection not set in the context");
return;
}
HttpRoute route = conn.getRoute();
if (route.getHopCount() == 1 || route.isTunnelled()) {
if (!request.containsHeader(HTTP.CONN_DIRECTIVE)) {
request.addHeader(HTTP.CONN_DIRECTIVE, HTTP.CONN_KEEP_ALIVE);
}
}
if (route.getHopCount() == 2 && !route.isTunnelled()) {
if (!request.containsHeader(PROXY_CONN_DIRECTIVE)) {
request.addHeader(PROXY_CONN_DIRECTIVE, HTTP.CONN_KEEP_ALIVE);
}
}
}
示例3: setXForwardedForHeader
import org.apache.http.HttpRequest; //导入方法依赖的package包/类
private void setXForwardedForHeader(HttpServletRequest servletRequest, HttpRequest proxyRequest) {
String headerName = "X-Forwarded-For";
String newHeader = servletRequest.getRemoteAddr();
String existingHeader = servletRequest.getHeader(headerName);
if (existingHeader != null) {
newHeader = existingHeader + ", " + newHeader;
}
proxyRequest.setHeader(headerName, newHeader);
}
示例4: process
import org.apache.http.HttpRequest; //导入方法依赖的package包/类
@Override
public void process(HttpRequest request, HttpContext context) {
request.setHeader(HttpHeaders.REQUEST_ID, nextRequestId.get());
request.setHeader(HttpHeaders.ROOT_REQUEST_ID, MdcFields.getRootRequestId());
request.setHeader(HttpHeaders.ORIGIN_REQUEST_ID, MdcFields.getRequestId());
}