本文整理了Java中org.apache.http.HttpResponse.getAllHeaders()
方法的一些代码示例,展示了HttpResponse.getAllHeaders()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。HttpResponse.getAllHeaders()
方法的具体详情如下:
包路径:org.apache.http.HttpResponse
类名称:HttpResponse
方法名:getAllHeaders
暂无
代码示例来源:origin: spring-projects/spring-framework
@Override
public HttpHeaders getHeaders() {
if (this.headers == null) {
this.headers = new HttpHeaders();
for (Header header : this.httpResponse.getAllHeaders()) {
this.headers.add(header.getName(), header.getValue());
}
}
return this.headers;
}
代码示例来源:origin: spring-projects/spring-framework
@Override
public HttpHeaders getHeaders() {
if (this.headers == null) {
this.headers = new HttpHeaders();
for (Header header : this.httpResponse.getAllHeaders()) {
this.headers.add(header.getName(), header.getValue());
}
}
return this.headers;
}
代码示例来源:origin: org.springframework/spring-web
@Override
public HttpHeaders getHeaders() {
if (this.headers == null) {
this.headers = new HttpHeaders();
for (Header header : this.httpResponse.getAllHeaders()) {
this.headers.add(header.getName(), header.getValue());
}
}
return this.headers;
}
代码示例来源:origin: org.springframework/spring-web
@Override
public HttpHeaders getHeaders() {
if (this.headers == null) {
this.headers = new HttpHeaders();
for (Header header : this.httpResponse.getAllHeaders()) {
this.headers.add(header.getName(), header.getValue());
}
}
return this.headers;
}
代码示例来源:origin: wiztools/rest-client
static String getHTTPResponseTrace(HttpResponse response) {
StringBuilder sb = new StringBuilder();
sb.append(response.getStatusLine()).append('\n');
for (Header h : response.getAllHeaders()) {
sb.append(h.getName()).append(": ").append(h.getValue()).append('\n');
}
sb.append('\n');
HttpEntity e = response.getEntity();
if (e != null) {
appendHttpEntity(sb, e);
}
return sb.toString();
}
代码示例来源:origin: selenide/selenide
protected String getFileName(String fileToDownloadLocation, HttpResponse response) {
for (Header header : response.getAllHeaders()) {
Optional<String> fileName = httpHelper.getFileNameFromContentDisposition(header.getName(), header.getValue());
if (fileName.isPresent()) {
return fileName.get();
}
}
log.info("Cannot extract file name from http headers. Found headers: ");
for (Header header : response.getAllHeaders()) {
log.info(header.getName() + '=' + header.getValue());
}
String fullFileName = FilenameUtils.getName(fileToDownloadLocation);
return isBlank(fullFileName) ? downloader.randomFileName() : trimQuery(fullFileName);
}
代码示例来源:origin: rapidoid/rapidoid
private static HttpResp response(HttpResponse response) throws IOException {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
PrintWriter printer = new PrintWriter(baos);
printer.print(response.getStatusLine() + "");
printer.print("\n");
Map<String, String> headers = U.map();
for (Header hdr : response.getAllHeaders()) {
printer.print(hdr.getName());
printer.print(": ");
printer.print(hdr.getValue());
printer.print("\n");
headers.put(hdr.getName(), hdr.getValue());
}
printer.print("\n");
printer.flush();
HttpEntity entity = response.getEntity();
byte[] body = entity != null ? IO.loadBytes(response.getEntity().getContent()) : new byte[0];
baos.write(body);
byte[] raw = baos.toByteArray();
return new HttpResp(raw, response.getStatusLine().getStatusCode(), headers, body);
}
代码示例来源:origin: internetarchive/heritrix3
/**
* This method populates <code>curi</code> with response status and
* content type.
*
* @param curi
* CrawlURI to populate.
* @param response
* Method to get response status and headers from.
*/
protected void addResponseContent(HttpResponse response, CrawlURI curi) {
curi.setFetchStatus(response.getStatusLine().getStatusCode());
Header ct = response.getLastHeader("content-type");
curi.setContentType(ct == null ? null : ct.getValue());
for (Header h: response.getAllHeaders()) {
curi.putHttpResponseHeader(h.getName(), h.getValue());
}
}
代码示例来源:origin: jooby-project/jooby
public Response headers(final BiConsumer<String, String> headers)
throws Exception {
for (Header header : rsp.getAllHeaders()) {
headers.accept(header.getName(), header.getValue());
}
return this;
}
代码示例来源:origin: aws/aws-sdk-java
/**
* Creates and initializes an HttpResponse object suitable to be passed to an HTTP response
* handler object.
*
* @param request Marshalled request object.
* @param method The HTTP method that was invoked to get the response.
* @param context The HTTP context associated with the request and response.
* @return The new, initialized HttpResponse object ready to be passed to an HTTP response
* handler object.
* @throws IOException If there were any problems getting any response information from the
* HttpClient method object.
*/
public static HttpResponse createResponse(Request<?> request,
HttpRequestBase method,
org.apache.http.HttpResponse apacheHttpResponse,
HttpContext context) throws IOException {
HttpResponse httpResponse = new HttpResponse(request, method, context);
if (apacheHttpResponse.getEntity() != null) {
httpResponse.setContent(apacheHttpResponse.getEntity().getContent());
}
httpResponse.setStatusCode(apacheHttpResponse.getStatusLine().getStatusCode());
httpResponse.setStatusText(apacheHttpResponse.getStatusLine().getReasonPhrase());
for (Header header : apacheHttpResponse.getAllHeaders()) {
httpResponse.addHeader(header.getName(), header.getValue());
}
return httpResponse;
}
代码示例来源:origin: dreamhead/moco
private HttpResponse setupNormalResponse(final org.apache.http.HttpResponse remoteResponse) throws IOException {
HttpVersion httpVersion = HttpVersion.valueOf(remoteResponse.getProtocolVersion().toString());
HttpResponseStatus status = HttpResponseStatus.valueOf(remoteResponse.getStatusLine().getStatusCode());
FullHttpResponse response = new DefaultFullHttpResponse(httpVersion, status);
response.setStatus(status);
Header[] allHeaders = remoteResponse.getAllHeaders();
for (Header header : allHeaders) {
if (isResponseHeader(header)) {
response.headers().set(header.getName(), header.getValue());
}
}
HttpEntity entity = remoteResponse.getEntity();
if (entity != null) {
byte[] content = toByteArray(entity);
if (content.length > 0) {
ByteBuf buffer = Unpooled.copiedBuffer(content);
response.content().writeBytes(buffer);
}
}
return newResponse(response);
}
代码示例来源:origin: Kong/unirest-java
ObjectMapper objectMapper = (ObjectMapper) Options.getOption(Option.OBJECT_MAPPER);
Header[] allHeaders = response.getAllHeaders();
for (Header header : allHeaders) {
String headerName = header.getName();
List<String> list = headers.get(headerName);
if (list == null)
代码示例来源:origin: wiztools/rest-client
response.setStatusLine(http_res.getStatusLine().toString());
final Header[] responseHeaders = http_res.getAllHeaders();
for (Header header : responseHeaders) {
response.addHeader(header.getName(), header.getValue());
代码示例来源:origin: jamesagnew/hapi-fhir
@Override
public Map<String, List<String>> getAllHeaders() {
Map<String, List<String>> headers = new HashMap<>();
if (myResponse.getAllHeaders() != null) {
for (Header next : myResponse.getAllHeaders()) {
String name = next.getName().toLowerCase();
List<String> list = headers.get(name);
if (list == null) {
list = new ArrayList<>();
headers.put(name, list);
}
list.add(next.getValue());
}
}
return headers;
}
代码示例来源:origin: resteasy/Resteasy
public static CaseInsensitiveMap<String> extractHeaders(HttpResponse response)
{
final CaseInsensitiveMap<String> headers = new CaseInsensitiveMap<String>();
for (Header header : response.getAllHeaders())
{
headers.add(header.getName(), header.getValue());
}
return headers;
}
代码示例来源:origin: foxinmy/weixin4j
@Override
public HttpHeaders getHeaders() {
if (headers == null) {
headers = new HttpHeaders();
Header[] headers = httpResponse.getAllHeaders();
for (Header header : headers) {
this.headers.add(header.getName(), header.getValue());
}
}
return headers;
}
代码示例来源:origin: resteasy/Resteasy
private static void copyResponse(HttpResponse httpResponse, ClientResponse clientResponse)
{
clientResponse.setStatus(httpResponse.getStatusLine().getStatusCode());
CaseInsensitiveMap<String> headers = new CaseInsensitiveMap<String>();
for (Header header : httpResponse.getAllHeaders())
{
headers.add(header.getName(), header.getValue());
}
clientResponse.setHeaders(headers);
}
代码示例来源:origin: nodebox/nodebox
String body = EntityUtils.toString(entity);
HashMap<String, String> m = new HashMap<String, String>();
for (Header h : response.getAllHeaders()) {
m.put(h.getName(), h.getValue());
代码示例来源:origin: aws-amplify/aws-sdk-android
@Override
public HttpResponse execute(HttpRequest request) throws IOException {
HttpUriRequest httpRequest = createHttpRequest(request);
org.apache.http.HttpResponse httpResponse = httpClient.execute(httpRequest);
String statusText = httpResponse.getStatusLine().getReasonPhrase();
int statusCode = httpResponse.getStatusLine().getStatusCode();
InputStream content = null;
if (httpResponse.getEntity() != null) {
content = httpResponse.getEntity().getContent();
}
HttpResponse.Builder builder = HttpResponse.builder()
.statusCode(statusCode)
.statusText(statusText)
.content(content);
for (Header header : httpResponse.getAllHeaders()) {
builder.header(header.getName(), header.getValue());
}
return builder.build();
}
代码示例来源:origin: com.amazonaws/aws-java-sdk-core
/**
* Creates and initializes an HttpResponse object suitable to be passed to an HTTP response
* handler object.
*
* @param request Marshalled request object.
* @param method The HTTP method that was invoked to get the response.
* @param context The HTTP context associated with the request and response.
* @return The new, initialized HttpResponse object ready to be passed to an HTTP response
* handler object.
* @throws IOException If there were any problems getting any response information from the
* HttpClient method object.
*/
public static HttpResponse createResponse(Request<?> request,
HttpRequestBase method,
org.apache.http.HttpResponse apacheHttpResponse,
HttpContext context) throws IOException {
HttpResponse httpResponse = new HttpResponse(request, method, context);
if (apacheHttpResponse.getEntity() != null) {
httpResponse.setContent(apacheHttpResponse.getEntity().getContent());
}
httpResponse.setStatusCode(apacheHttpResponse.getStatusLine().getStatusCode());
httpResponse.setStatusText(apacheHttpResponse.getStatusLine().getReasonPhrase());
for (Header header : apacheHttpResponse.getAllHeaders()) {
httpResponse.addHeader(header.getName(), header.getValue());
}
return httpResponse;
}
内容来源于网络,如有侵权,请联系作者删除!