org.asynchttpclient.Response.hasResponseHeaders()方法的使用及代码示例

x33g5p2x  于2022-01-28 转载在 其他  
字(2.0k)|赞(0)|评价(0)|浏览(82)

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

Response.hasResponseHeaders介绍

[英]Return true if the response's headers has been computed by an AsyncHandler It will return false if the either AsyncHandler#onStatusReceived(HttpResponseStatus) or AsyncHandler#onHeadersReceived(HttpHeaders) returned AsyncHandler.State#ABORT
[中]返回true如果响应的头由AsyncHandler计算,那么如果AsyncHandler#onStatusReceived(HttpResponseStatus)或AsyncHandler#onHeadersReceived(HttpHeaders)返回AsyncHandler,则返回false。州#中止

代码示例

代码示例来源:origin: AsyncHttpClient/async-http-client

public boolean hasResponseHeaders() {
 return response.hasResponseHeaders();
}

代码示例来源:origin: AsyncHttpClient/async-http-client

/**
 * Converts async-http-client response to okhttp response.
 *
 * @param asyncHttpClientResponse async-http-client response
 * @return okhttp response.
 * @throws NullPointerException in case of null arguments
 */
private Response toOkhttpResponse(org.asynchttpclient.Response asyncHttpClientResponse) {
 // status code
 val rspBuilder = new Response.Builder()
     .request(request())
     .protocol(Protocol.HTTP_1_1)
     .code(asyncHttpClientResponse.getStatusCode())
     .message(asyncHttpClientResponse.getStatusText());
 // headers
 if (asyncHttpClientResponse.hasResponseHeaders()) {
  asyncHttpClientResponse.getHeaders().forEach(e -> rspBuilder.header(e.getKey(), e.getValue()));
 }
 // body
 if (asyncHttpClientResponse.hasResponseBody()) {
  val contentType = asyncHttpClientResponse.getContentType() == null
      ? null : MediaType.parse(asyncHttpClientResponse.getContentType());
  val okHttpBody = ResponseBody.create(contentType, asyncHttpClientResponse.getResponseBodyAsBytes());
  rspBuilder.body(okHttpBody);
 } else {
  rspBuilder.body(EMPTY_BODY);
 }
 return rspBuilder.build();
}

代码示例来源:origin: org.asynchttpclient/async-http-client-api

public boolean hasResponseHeaders() {
  return response.hasResponseHeaders();
}

相关文章