io.netty.handler.codec.http.HttpResponse.getStatus()方法的使用及代码示例

x33g5p2x  于2022-01-20 转载在 其他  
字(8.8k)|赞(0)|评价(0)|浏览(106)

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

HttpResponse.getStatus介绍

暂无

代码示例

代码示例来源:origin: JZ-Darkal/AndroidHttpCapture

/**
 * Returns true if the specified response is an HTTP redirect response, i.e. a 300, 301, 302, 303, or 307.
 *
 * @param httpResponse HTTP response
 * @return true if the response is a redirect, otherwise false
 */
public static boolean isRedirect(HttpResponse httpResponse) {
  switch (httpResponse.getStatus().code()) {
    case 300:
    case 301:
    case 302:
    case 303:
    case 307:
      return true;
    default:
      return false;
  }
}

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

@Override
public void filterResponse(HttpResponse response, HttpMessageContents contents, HttpMessageInfo messageInfo) {
 if (!active) return;
 responses.add(new Response(messageInfo.getUrl(),
   response.getStatus().code(),
   response.getStatus().reasonPhrase(),
   toMap(response.headers()),
   contents.getContentType(),
   contents.getTextContents()
 ));
 if (response.getStatus().code() < 200 || response.getStatus().code() >= 300) return;
 String fileName = getFileName(response);
 if (fileName == null) return;
 File file = downloader.prepareTargetFile(config, fileName);
 try {
  FileUtils.writeByteArrayToFile(file, contents.getBinaryContents());
  downloadedFiles.add(file);
 }
 catch (IOException e) {
  log.log(Level.SEVERE, "Failed to save downloaded file to " + file.getAbsolutePath() +
    " for url " + messageInfo.getUrl(), e);
 }
}

代码示例来源:origin: JZ-Darkal/AndroidHttpCapture

protected void captureResponse(HttpResponse httpResponse) {
  HarResponse response = new HarResponse(httpResponse.getStatus().code(), httpResponse.getStatus().reasonPhrase(), httpResponse.getProtocolVersion().text());
  harEntry.setResponse(response);
  captureResponseHeaderSize(httpResponse);
  captureResponseMimeType(httpResponse);
  if (dataToCapture.contains(CaptureType.RESPONSE_COOKIES)) {
    captureResponseCookies(httpResponse);
  }
  if (dataToCapture.contains(CaptureType.RESPONSE_HEADERS)) {
    captureResponseHeaders(httpResponse);
  }
  if (BrowserMobHttpUtil.isRedirect(httpResponse)) {
    captureRedirectUrl(httpResponse);
  }
}

代码示例来源:origin: JZ-Darkal/AndroidHttpCapture

protected void captureResponseHeaderSize(HttpResponse httpResponse) {
  String statusLine = httpResponse.getProtocolVersion().toString() + ' ' + httpResponse.getStatus().toString();
  // +2 => CRLF after status line, +4 => header/data separation
  long responseHeadersSize = statusLine.length() + 6;
  HttpHeaders headers = httpResponse.headers();
  responseHeadersSize += BrowserMobHttpUtil.getHeaderSize(headers);
  harEntry.getResponse().setHeadersSize(responseHeadersSize);
}

代码示例来源:origin: linkedin/flashback

public RecordedHttpResponseBuilder(HttpResponse nettyHttpResponse) {
 super(nettyHttpResponse);
 _status = nettyHttpResponse.getStatus().code();
}

代码示例来源:origin: SpigotMC/BungeeCord

@Override
protected void channelRead0(ChannelHandlerContext ctx, HttpObject msg) throws Exception
{
  if ( msg instanceof HttpResponse )
  {
    HttpResponse response = (HttpResponse) msg;
    int responseCode = response.getStatus().code();
    if ( responseCode == HttpResponseStatus.NO_CONTENT.code() )
    {
      done( ctx );
      return;
    }
    if ( responseCode != HttpResponseStatus.OK.code() )
    {
      throw new IllegalStateException( "Expected HTTP response 200 OK, got " + response.getStatus() );
    }
  }
  if ( msg instanceof HttpContent )
  {
    HttpContent content = (HttpContent) msg;
    buffer.append( content.content().toString( Charset.forName( "UTF-8" ) ) );
    if ( msg instanceof LastHttpContent )
    {
      done( ctx );
    }
  }
}

代码示例来源:origin: codeabovelab/haven-platform

@Override
@SuppressWarnings("deprecation")
public int getRawStatusCode() throws IOException {
  return this.nettyResponse.getStatus().code();
}

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

/**
 * Return the response status code
 * 
 * @return the response status code
 */
public int getStatusCode() {
  return response.getStatus().code();
}

代码示例来源:origin: org.wso2.carbon.mss/org.wso2.carbon.mss

private boolean isUserError(HttpResponse response) {
  int code = response.getStatus().code();
  return code == HttpResponseStatus.BAD_REQUEST.code() || code == HttpResponseStatus.NOT_FOUND.code() ||
      code == HttpResponseStatus.METHOD_NOT_ALLOWED.code();
}

代码示例来源:origin: codeabovelab/haven-platform

@Override
@SuppressWarnings("deprecation")
public String getStatusText() throws IOException {
  return this.nettyResponse.getStatus().reasonPhrase();
}

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

/**
 * Return the response status text
 * 
 * @return the response status text
 */
public String getStatusText() {
  return response.getStatus().reasonPhrase();
}

代码示例来源:origin: HotelsDotCom/styx

@Override
public void write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise) throws Exception {
  if (msg instanceof HttpResponse) {
    responses.get(((HttpResponse) msg).getStatus()).mark();
  }
  super.write(ctx, msg, promise);
}

代码示例来源:origin: com.hotels.styx/styx-client

@VisibleForTesting
static HttpResponse.Builder toStyxResponse(io.netty.handler.codec.http.HttpResponse nettyResponse) {
  HttpResponse.Builder responseBuilder = response(nettyResponse.getStatus());
  stream(nettyResponse.headers().spliterator(), false)
      .filter(header -> !isCookieHeader(header.getKey()))
      .forEach(header -> responseBuilder.addHeader(header.getKey(), header.getValue()));
  nettyResponse.headers().getAll(SET_COOKIE).stream()
      .map(ClientCookieDecoder.LAX::decode)
      .map(NettyToStyxResponsePropagator::nettyCookieToStyxCookie)
      .forEach(responseBuilder::addCookie);
  return responseBuilder;
}

代码示例来源:origin: org.jboss.errai.io.netty/netty-example

private void sendHttpResponse(ChannelHandlerContext ctx, HttpRequest req, HttpResponse res) {
  // Generate an error page if response status code is not OK (200).
  if (res.getStatus().getCode() != 200) {
    res.setContent(ChannelBuffers.copiedBuffer(res.getStatus().toString(), CharsetUtil.UTF_8));
    setContentLength(res, res.getContent().readableBytes());
  }
  // Send the response and close the connection if necessary.
  ChannelFuture f = ctx.getChannel().write(res);
  if (!isKeepAlive(req) || res.getStatus().getCode() != 200) {
    f.addListener(ChannelFutureListener.CLOSE);
  }
}

代码示例来源:origin: com.netflix.rxnetty/rx-netty

public HttpClientResponse(HttpResponse nettyResponse, UnicastContentSubject<T> content) {
  super(content);
  this.nettyResponse = nettyResponse;
  httpVersion = this.nettyResponse.getProtocolVersion();
  status = this.nettyResponse.getStatus();
  responseHeaders = new HttpResponseHeaders(nettyResponse);
  cookiesHolder = CookiesHolder.newClientResponseHolder(nettyResponse.headers());
}

代码示例来源:origin: io.reactivex/rxnetty

public HttpClientResponse(HttpResponse nettyResponse, UnicastContentSubject<T> content) {
  super(content);
  this.nettyResponse = nettyResponse;
  httpVersion = this.nettyResponse.getProtocolVersion();
  status = this.nettyResponse.getStatus();
  responseHeaders = new HttpResponseHeaders(nettyResponse);
  cookiesHolder = CookiesHolder.newClientResponseHolder(nettyResponse.headers());
}

代码示例来源:origin: misakuo/Dream-Catcher

protected void captureResponseHeaderSize(HttpResponse httpResponse) {
  Log.e("InnerHandle", "captureResponseHeaderSize " + harEntry.getId());
  String statusLine = httpResponse.getProtocolVersion().toString() + ' ' + httpResponse.getStatus().toString();
  // +2 => CRLF after status line, +4 => header/data separation
  long responseHeadersSize = statusLine.length() + 6;
  HttpHeaders headers = httpResponse.headers();
  responseHeadersSize += BrowserMobHttpUtil.getHeaderSize(headers);
  harResponse.getResponse().setHeadersSize(responseHeadersSize);
}

代码示例来源:origin: net.lightbody.bmp/browsermob-core

protected void captureResponseHeaderSize(HttpResponse httpResponse) {
  String statusLine = httpResponse.getProtocolVersion().toString() + ' ' + httpResponse.getStatus().toString();
  // +2 => CRLF after status line, +4 => header/data separation
  long responseHeadersSize = statusLine.length() + 6;
  HttpHeaders headers = httpResponse.headers();
  responseHeadersSize += BrowserMobHttpUtil.getHeaderSize(headers);
  harEntry.getResponse().setHeadersSize(responseHeadersSize);
}

代码示例来源:origin: net.lightbody.bmp/browsermob-core-littleproxy

protected void captureResponseHeaderSize(HttpResponse httpResponse) {
  String statusLine = httpResponse.getProtocolVersion().toString() + ' ' + httpResponse.getStatus().toString();
  // +2 => CRLF after status line, +4 => header/data separation
  long responseHeadersSize = statusLine.length() + 6;
  HttpHeaders headers = httpResponse.headers();
  responseHeadersSize += BrowserMobHttpUtil.getHeaderSize(headers);
  harEntry.getResponse().setHeadersSize(responseHeadersSize);
}

代码示例来源:origin: spinn3r/noxy

@Override
public HttpObject proxyToClientResponse(HttpObject httpObject) {
  if ( httpObject instanceof HttpResponse ) {
    HttpResponse httpResponse = (HttpResponse)httpObject;
    long duration = clock.currentTimeMillis() - httpRequestTimestamp;
    LogMessage logMessage = new LogMessage( httpRequest.getMethod(), httpRequest.getProtocolVersion(), httpRequestUri, httpResponse.getStatus(), duration, resolutionServerHostAndPort, resolvedRemoteAddress );
    logListener.onLogMessage( logMessage );
  }
  logListener.proxyToClientResponse( httpObject );
  return super.proxyToClientResponse( httpObject );
}

相关文章