本文整理汇总了Java中org.apache.http.Header.getName方法的典型用法代码示例。如果您正苦于以下问题:Java Header.getName方法的具体用法?Java Header.getName怎么用?Java Header.getName使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.http.Header
的用法示例。
在下文中一共展示了Header.getName方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: doFormatHeader
import org.apache.http.Header; //导入方法依赖的package包/类
/**
* Actually formats a header.
* Called from {@link #formatHeader}.
*
* @param buffer the empty buffer into which to format,
* never <code>null</code>
* @param header the header to format, never <code>null</code>
*/
protected void doFormatHeader(final CharArrayBuffer buffer,
final Header header) {
final String name = header.getName();
final String value = header.getValue();
int len = name.length() + 2;
if (value != null) {
len += value.length();
}
buffer.ensureCapacity(len);
buffer.append(name);
buffer.append(": ");
if (value != null) {
buffer.append(value);
}
}
示例2: doSendRequest
import org.apache.http.Header; //导入方法依赖的package包/类
@Override
protected HttpResponse doSendRequest(final HttpRequest request, final HttpClientConnection conn, final HttpContext context) throws IOException, HttpException {
synchronized(listener) {
listener.log(TranscriptListener.Type.request, request.getRequestLine().toString());
for(Header header : request.getAllHeaders()) {
switch(header.getName()) {
case HttpHeaders.AUTHORIZATION:
case "X-Auth-Key":
case "X-Auth-Token":
listener.log(TranscriptListener.Type.request, String.format("%s: %s", header.getName(),
StringUtils.repeat("*", Integer.min(8, StringUtils.length(header.getValue())))));
break;
default:
listener.log(TranscriptListener.Type.request, header.toString());
break;
}
}
}
return super.doSendRequest(request, conn, context);
}
示例3: toFeignResponse
import org.apache.http.Header; //导入方法依赖的package包/类
Response toFeignResponse(HttpResponse httpResponse) throws IOException {
StatusLine statusLine = httpResponse.getStatusLine();
int statusCode = statusLine.getStatusCode();
String reason = statusLine.getReasonPhrase();
Map<String, Collection<String>> headers = new HashMap<String, Collection<String>>();
for (Header header : httpResponse.getAllHeaders()) {
String name = header.getName();
String value = header.getValue();
Collection<String> headerValues = headers.get(name);
if (headerValues == null) {
headerValues = new ArrayList<String>();
headers.put(name, headerValues);
}
headerValues.add(value);
}
return Response.builder()
.status(statusCode)
.reason(reason)
.headers(headers)
.body(toFeignBody(httpResponse))
.build();
}
示例4: a
import org.apache.http.Header; //导入方法依赖的package包/类
private static boolean a(HttpResponse httpResponse) {
String str = null;
String str2 = a;
if (httpResponse != null) {
Header[] allHeaders = httpResponse.getAllHeaders();
if (allHeaders != null && allHeaders.length > 0) {
for (Header header : allHeaders) {
if (header != null) {
String name = header.getName();
if (name != null && name.equalsIgnoreCase(str2)) {
str = header.getValue();
break;
}
}
}
}
}
return Boolean.valueOf(str).booleanValue();
}
示例5: transformRequest
import org.apache.http.Header; //导入方法依赖的package包/类
private static Request transformRequest(HttpRequest request) {
Request.Builder builder = new Request.Builder();
RequestLine requestLine = request.getRequestLine();
String method = requestLine.getMethod();
builder.url(requestLine.getUri());
String contentType = null;
for (Header header : request.getAllHeaders()) {
String name = header.getName();
if ("Content-Type".equalsIgnoreCase(name)) {
contentType = header.getValue();
} else {
builder.header(name, header.getValue());
}
}
RequestBody body = null;
if (request instanceof HttpEntityEnclosingRequest) {
HttpEntity entity = ((HttpEntityEnclosingRequest) request).getEntity();
if (entity != null) {
// Wrap the entity in a custom Body which takes care of the content, length, and type.
body = new HttpEntityBody(entity, contentType);
Header encoding = entity.getContentEncoding();
if (encoding != null) {
builder.header(encoding.getName(), encoding.getValue());
}
} else {
body = Util.EMPTY_REQUEST;
}
}
builder.method(method, body);
return builder.build();
}
示例6: testHeaders
import org.apache.http.Header; //导入方法依赖的package包/类
/**
* End to end test for headers. We test it explicitly against a real http client as there are different ways
* to set/add headers to the {@link org.apache.http.client.HttpClient}.
* Exercises the test http server ability to send back whatever headers it received.
*/
public void testHeaders() throws IOException {
for (String method : getHttpMethods()) {
final Set<String> standardHeaders = new HashSet<>(Arrays.asList("Connection", "Host", "User-agent", "Date"));
if (method.equals("HEAD") == false) {
standardHeaders.add("Content-length");
}
final Header[] requestHeaders = RestClientTestUtil.randomHeaders(getRandom(), "Header");
final int statusCode = randomStatusCode(getRandom());
Response esResponse;
try {
esResponse = restClient.performRequest(method, "/" + statusCode, Collections.<String, String>emptyMap(), requestHeaders);
} catch(ResponseException e) {
esResponse = e.getResponse();
}
assertEquals(method, esResponse.getRequestLine().getMethod());
assertEquals(statusCode, esResponse.getStatusLine().getStatusCode());
assertEquals(pathPrefix + "/" + statusCode, esResponse.getRequestLine().getUri());
assertHeaders(defaultHeaders, requestHeaders, esResponse.getHeaders(), standardHeaders);
for (final Header responseHeader : esResponse.getHeaders()) {
String name = responseHeader.getName();
if (name.startsWith("Header") == false) {
assertTrue("unknown header was returned " + name, standardHeaders.remove(name));
}
}
assertTrue("some expected standard headers weren't returned: " + standardHeaders, standardHeaders.isEmpty());
}
}
示例7: cookieToString
import org.apache.http.Header; //导入方法依赖的package包/类
/**
* Makes a printable version of the cookie header.
*/
private String cookieToString(Header cookieHeader)
{
if (cookieHeader == null)
{
return "null";
}
else
{
return cookieHeader.getName() + ": " + cookieHeader.getValue();
}
}
示例8: valueOf
import org.apache.http.Header; //导入方法依赖的package包/类
/**
* Determines the WARC record type given the <code>WARC-Type</code> header.
*
* @param header the header.
* @return the record type.
*/
public static Type valueOf(final Header header) {
if (! header.getName().equals(WarcHeader.Name.WARC_TYPE.value)) throw new IllegalArgumentException("Wrong header type " + header.getName());
final String type = header.getValue();
if (type.equals(RESPONSE.value))
return RESPONSE;
if (type.equals(REQUEST.value))
return REQUEST;
if (type.equals(WARCINFO.value))
return WARCINFO;
throw new IllegalArgumentException("Unrecognized type " + type);
}
示例9: apply
import org.apache.http.Header; //导入方法依赖的package包/类
@Override
public ClientResponse apply(final ClientRequest clientRequest) throws ProcessingException {
final HttpUriRequest request = this.toUriHttpRequest(clientRequest);
final Map<String, String> clientHeadersSnapshot = writeOutBoundHeaders(clientRequest.getHeaders(), request);
try {
final CloseableHttpResponse response;
response = client.execute(new HttpHost(request.getURI().getHost(), request.getURI().getPort(), request.getURI().getScheme()), request, new BasicHttpContext(context));
HeaderUtils.checkHeaderChanges(clientHeadersSnapshot, clientRequest.getHeaders(), this.getClass().getName());
final Response.StatusType status = response.getStatusLine().getReasonPhrase() == null
? Statuses.from(response.getStatusLine().getStatusCode())
: Statuses.from(response.getStatusLine().getStatusCode(), response.getStatusLine().getReasonPhrase());
final ClientResponse responseContext = new ClientResponse(status, clientRequest);
final List<URI> redirectLocations = context.getRedirectLocations();
if(redirectLocations != null && !redirectLocations.isEmpty()) {
responseContext.setResolvedRequestUri(redirectLocations.get(redirectLocations.size() - 1));
}
final Header[] respHeaders = response.getAllHeaders();
final MultivaluedMap<String, String> headers = responseContext.getHeaders();
for(final Header header : respHeaders) {
final String headerName = header.getName();
List<String> list = headers.get(headerName);
if(list == null) {
list = new ArrayList<>();
}
list.add(header.getValue());
headers.put(headerName, list);
}
final HttpEntity entity = response.getEntity();
if(entity != null) {
if(headers.get(HttpHeaders.CONTENT_LENGTH) == null) {
headers.add(HttpHeaders.CONTENT_LENGTH, String.valueOf(entity.getContentLength()));
}
final Header contentEncoding = entity.getContentEncoding();
if(headers.get(HttpHeaders.CONTENT_ENCODING) == null && contentEncoding != null) {
headers.add(HttpHeaders.CONTENT_ENCODING, contentEncoding.getValue());
}
}
responseContext.setEntityStream(this.toInputStream(response));
return responseContext;
}
catch(final Exception e) {
throw new ProcessingException(e);
}
}