org.apache.http.HttpRequest.getHeaders()方法的使用及代码示例

x33g5p2x  于2022-01-19 转载在 其他  
字(8.1k)|赞(0)|评价(0)|浏览(139)

本文整理了Java中org.apache.http.HttpRequest.getHeaders()方法的一些代码示例,展示了HttpRequest.getHeaders()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。HttpRequest.getHeaders()方法的具体详情如下:
包路径:org.apache.http.HttpRequest
类名称:HttpRequest
方法名:getHeaders

HttpRequest.getHeaders介绍

暂无

代码示例

代码示例来源:origin: rest-assured/rest-assured

public void process( final HttpRequest req,
      final HttpContext context ) throws HttpException, IOException {
    
    // set the Accept-Encoding header:
    String encoding = getContentEncoding();            
    if ( !req.containsHeader( ACCEPT_ENC_HDR ) )
      req.addHeader( ACCEPT_ENC_HDR, encoding );
    else {
      StringBuilder values = new StringBuilder();
      for ( Header h : req.getHeaders( ACCEPT_ENC_HDR ) )
        values.append( h.getValue() ).append( "," );
      String encList = (!values.toString().contains( encoding )) ? values
          .append( encoding ).toString()
          : values.toString().substring( 0, values.lastIndexOf( "," ) );
          
      req.setHeader( ACCEPT_ENC_HDR, encList );
    }
    //TODO compress request and add content-encoding header.
  }
}

代码示例来源:origin: marytts/marytts

IOException {
try {
  Header[] tmp = request.getHeaders("Host");
  Address serverAddressAtClient = getServerAddressAtClient(tmp[0].getValue());
  String uri = request.getRequestLine().getUri();

代码示例来源:origin: marytts/marytts

IOException {
try {
  Header[] tmp = request.getHeaders("Host");
  Address serverAddressAtClient = getServerAddressAtClient(tmp[0].getValue());
  String uri = request.getRequestLine().getUri();

代码示例来源:origin: com.jayway.restassured/rest-assured

public void process( final HttpRequest req,
      final HttpContext context ) throws HttpException, IOException {
    
    // set the Accept-Encoding header:
    String encoding = getContentEncoding();            
    if ( !req.containsHeader( ACCEPT_ENC_HDR ) )
      req.addHeader( ACCEPT_ENC_HDR, encoding );
    else {
      StringBuilder values = new StringBuilder();
      for ( Header h : req.getHeaders( ACCEPT_ENC_HDR ) )
        values.append( h.getValue() ).append( "," );
      String encList = (!values.toString().contains( encoding )) ? values
          .append( encoding ).toString()
          : values.toString().substring( 0, values.lastIndexOf( "," ) );
          
      req.setHeader( ACCEPT_ENC_HDR, encList );
    }
    //TODO compress request and add content-encoding header.
  }
}

代码示例来源:origin: apache/axis2-java

public Header[] getHeaders(String name) {
  return this.request.getHeaders(name);
}

代码示例来源:origin: at.bestsolution.efxclipse.eclipse/org.apache.httpcomponents.httpclient

private boolean hasValidDateField(final HttpRequest request, final String headerName) {
    for(final Header h : request.getHeaders(headerName)) {
      final Date date = DateUtils.parseDate(h.getValue());
      return date != null;
    }
    return false;
  }
}

代码示例来源:origin: disney/groovity

@Override
  public List<String> getHeaders(String headerName) {
    Header[] headers = httpRequest.getHeaders(headerName);
    List<String> headerValues = new ArrayList<String>(headers.length);
    for (int i = 0; i < headers.length; i++) {
      headerValues.add(headers[i].getValue());
    }
    if(this.host!=null && headerValues.isEmpty() && headerName.equalsIgnoreCase("host")){
      headerValues.add(host);
    }
    return headerValues;
  }
}

代码示例来源:origin: org.apache.httpcomponents/com.springsource.org.apache.httpcomponents.httpclient-cache

private boolean hasValidDateField(HttpRequest request, String headerName) {
    for(Header h : request.getHeaders(headerName)) {
      try {
        DateUtils.parseDate(h.getValue());
        return true;
      } catch (DateParseException dpe) {
        // ignore malformed dates
      }
    }
    return false;
  }
}

代码示例来源:origin: org.apache.httpcomponents/com.springsource.org.apache.httpcomponents.httpclient-cache

private boolean mayCallBackend(HttpRequest request) {
  for (Header h: request.getHeaders(HeaderConstants.CACHE_CONTROL)) {
    for (HeaderElement elt : h.getElements()) {
      if ("only-if-cached".equals(elt.getName())) {
        return false;
      }
    }
  }
  return true;
}

代码示例来源:origin: org.yamj/api-common

@SuppressWarnings("unused")
protected void prepareRequest(HttpHost target, HttpRequest request) throws ClientProtocolException {
  if (userAgentSelector != null) {
    final Header[] headers = request.getHeaders(HTTP.USER_AGENT);
    if (headers == null || headers.length == 0) {
      request.setHeader(HTTP.USER_AGENT, userAgentSelector.getUserAgent());
    }
  }
}

代码示例来源:origin: aliyun/HiTSDB-Client

private void tryCloseConnection(HttpRequest request) {
  Header[] headers = request.getHeaders("Connection");
  if (headers != null && headers.length > 0) {
    for (Header h : headers) {
      request.removeHeader(h);
    }
  }
  request.addHeader("Connection", "close");
}

代码示例来源:origin: sentilo/sentilo

private String extractHeader(final HttpHeader header) {
 LOGGER.debug("extractHeader: {}", header.toString());
 final Header[] requestHeaders = httpRequest.getHeaders(header.toString());
 return SentiloUtils.arrayIsEmpty(requestHeaders) ? null : requestHeaders[0].getValue();
}

代码示例来源:origin: at.bestsolution.efxclipse.eclipse/org.apache.httpcomponents.httpclient

private RequestProtocolError requestContainsNoCacheDirectiveWithFieldName(final HttpRequest request) {
    for(final Header h : request.getHeaders(HeaderConstants.CACHE_CONTROL)) {
      for(final HeaderElement elt : h.getElements()) {
        if (HeaderConstants.CACHE_CONTROL_NO_CACHE.equalsIgnoreCase(elt.getName())
          && elt.getValue() != null) {
          return RequestProtocolError.NO_CACHE_DIRECTIVE_WITH_FIELD_NAME;
        }
      }
    }
    return null;
  }
}

代码示例来源:origin: org.apache.httpcomponents/com.springsource.org.apache.httpcomponents.httpclient-cache

private RequestProtocolError requestContainsNoCacheDirectiveWithFieldName(HttpRequest request) {
    for(Header h : request.getHeaders(HeaderConstants.CACHE_CONTROL)) {
      for(HeaderElement elt : h.getElements()) {
        if (HeaderConstants.CACHE_CONTROL_NO_CACHE.equalsIgnoreCase(elt.getName())
          && elt.getValue() != null) {
          return RequestProtocolError.NO_CACHE_DIRECTIVE_WITH_FIELD_NAME;
        }
      }
    }
    return null;
  }
}

代码示例来源:origin: org.apache.httpcomponents/com.springsource.org.apache.httpcomponents.httpclient-cache

private void add100ContinueHeaderIfMissing(HttpRequest request) {
  boolean hasHeader = false;
  for (Header h : request.getHeaders(HTTP.EXPECT_DIRECTIVE)) {
    for (HeaderElement elt : h.getElements()) {
      if (HTTP.EXPECT_CONTINUE.equalsIgnoreCase(elt.getName())) {
        hasHeader = true;
      }
    }
  }
  if (!hasHeader) {
    request.addHeader(HTTP.EXPECT_DIRECTIVE, HTTP.EXPECT_CONTINUE);
  }
}

代码示例来源:origin: at.bestsolution.efxclipse.eclipse/org.apache.httpcomponents.httpclient

private void add100ContinueHeaderIfMissing(final HttpRequest request) {
  boolean hasHeader = false;
  for (final Header h : request.getHeaders(HTTP.EXPECT_DIRECTIVE)) {
    for (final HeaderElement elt : h.getElements()) {
      if (HTTP.EXPECT_CONTINUE.equalsIgnoreCase(elt.getName())) {
        hasHeader = true;
      }
    }
  }
  if (!hasHeader) {
    request.addHeader(HTTP.EXPECT_DIRECTIVE, HTTP.EXPECT_CONTINUE);
  }
}

代码示例来源:origin: com.intuit.karate/karate-apache

public static void logHeaders(StringBuilder sb, int id, char prefix, org.apache.http.HttpRequest request, HttpRequest actual) {
  for (String key : sortKeys(request.getAllHeaders())) {
    Header[] headers = request.getHeaders(key);
    logHeaderLine(sb, id, prefix, key, headers);
    for (Header header : headers) {
      actual.addHeader(header.getName(), header.getValue());
    }
  }
}

代码示例来源:origin: com.truward.brikar/brikar-client

private static void setOriginatingRequestVector(HttpRequest request) {
  final Header[] existingRequestVectorHeaders = request.getHeaders(TrackingHttpHeaderNames.REQUEST_VECTOR);
  if (existingRequestVectorHeaders.length > 0) {
   return;
  }

  final String sourceRequestVector = MDC.get(LogUtil.REQUEST_VECTOR);

  // set originating request ID for the outgoing request
  if (sourceRequestVector != null) {
   final String nestedRequestVector = TrackingHttpHeaderNames.getNestedRequestVector(sourceRequestVector);
   request.setHeader(TrackingHttpHeaderNames.REQUEST_VECTOR, nestedRequestVector);
  }
 }
}

代码示例来源:origin: at.bestsolution.efxclipse.eclipse/org.apache.httpcomponents.httpclient

public boolean mayReturnStaleIfError(final HttpRequest request,
    final HttpCacheEntry entry, final Date now) {
  final long stalenessSecs = getStalenessSecs(entry, now);
  return mayReturnStaleIfError(request.getHeaders(HeaderConstants.CACHE_CONTROL),
                 stalenessSecs)
      || mayReturnStaleIfError(entry.getHeaders(HeaderConstants.CACHE_CONTROL),
                   stalenessSecs);
}

代码示例来源:origin: org.apache.httpcomponents/com.springsource.org.apache.httpcomponents.httpclient-cache

public boolean mayReturnStaleIfError(HttpRequest request,
    HttpCacheEntry entry, Date now) {
  long stalenessSecs = getStalenessSecs(entry, now);
  return mayReturnStaleIfError(request.getHeaders(HeaderConstants.CACHE_CONTROL),
                 stalenessSecs)
      || mayReturnStaleIfError(entry.getHeaders(HeaderConstants.CACHE_CONTROL),
                   stalenessSecs);
}

相关文章