org.jboss.netty.handler.codec.http.HttpResponse.setStatus()方法的使用及代码示例

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

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

HttpResponse.setStatus介绍

[英]Sets the status of this response.
[中]设置此响应的状态。

代码示例

代码示例来源:origin: io.netty/netty

/**
 * Return that we need cannot not support the web socket version
 *
 * @param channel
 *            Channel
 */
public ChannelFuture sendUnsupportedWebSocketVersionResponse(Channel channel) {
  HttpResponse res = new DefaultHttpResponse(
      HttpVersion.HTTP_1_1,
      HttpResponseStatus.SWITCHING_PROTOCOLS);
  res.setStatus(HttpResponseStatus.UPGRADE_REQUIRED);
  res.headers().set(Names.SEC_WEBSOCKET_VERSION, WebSocketVersion.V13.toHttpHeaderValue());
  return channel.write(res);
}

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

@Override
public NettyHttpResponse status(int status) {
  response.setStatus(HttpResponseStatus.valueOf(status));
  return this;
}

代码示例来源:origin: io.netty/netty

res.setStatus(HttpResponseStatus.SWITCHING_PROTOCOLS);
res.headers().add(Names.UPGRADE, WEBSOCKET.toLowerCase());
res.headers().add(Names.CONNECTION, Names.UPGRADE);

代码示例来源:origin: io.netty/netty

res.setStatus(HttpResponseStatus.SWITCHING_PROTOCOLS);
res.headers().add(Names.UPGRADE, WEBSOCKET.toLowerCase());
res.headers().add(Names.CONNECTION, Names.UPGRADE);

代码示例来源:origin: io.netty/netty

res.setStatus(HttpResponseStatus.SWITCHING_PROTOCOLS);
res.headers().add(Names.UPGRADE, WEBSOCKET.toLowerCase());
res.headers().add(Names.CONNECTION, Names.UPGRADE);

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

@Override
public NettyHttpResponse error(Throwable error) {
  if (error instanceof TooLongFrameException) {
    response.setStatus(HttpResponseStatus.REQUEST_ENTITY_TOO_LARGE);
  } else {
    response.setStatus(HttpResponseStatus.INTERNAL_SERVER_ERROR);
  }
  String message = getStackTrace(error);
  header("Content-Type", "text/plain");
  content(message);
  flushResponse();
  exceptionHandler.uncaughtException(Thread.currentThread(),
      WebbitException.fromException(error, ctx.getChannel()));
  return this;
}

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

@Override
public void prepareHandshakeResponse(NettyWebSocketConnection webSocketConnection) {
  webSocketConnection.setHybiWebSocketVersion(getHybiVersion());
  if (getHybiVersion() < MIN_HYBI_VERSION) {
    res.setStatus(HttpResponseStatus.UPGRADE_REQUIRED);
    res.setHeader(SEC_WEBSOCKET_VERSION, String.valueOf(MIN_HYBI_VERSION));
    return;
  }
  String key = req.getHeader(SEC_WEBSOCKET_KEY);
  if (key == null) {
    res.setStatus(HttpResponseStatus.BAD_REQUEST);
    return;
  }
  String accept = Base64.encode(sha1(key + ACCEPT_GUID));
  res.setStatus(new HttpResponseStatus(101, "Switching Protocols"));
  res.addHeader(UPGRADE, WEBSOCKET.toLowerCase());
  res.addHeader(CONNECTION, UPGRADE);
  res.addHeader(SEC_WEBSOCKET_ACCEPT, accept);
  String webSocketProtocol = req.getHeader(SEC_WEBSOCKET_PROTOCOL);
  if (webSocketProtocol != null) {
    res.addHeader(SEC_WEBSOCKET_PROTOCOL, webSocketProtocol);
  }
}

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

private void performEventSourceHandshake(ChannelHandler eventSourceConnectionHandler) {
  nettyHttpResponse.setStatus(HttpResponseStatus.OK);
  nettyHttpResponse.addHeader("Content-Type", "text/event-stream");
  nettyHttpResponse.addHeader("Transfer-Encoding", "identity");
  nettyHttpResponse.addHeader("Connection", "keep-alive");
  nettyHttpResponse.addHeader("Cache-Control", "no-cache");
  nettyHttpResponse.setChunked(false);
  ctx.getChannel().write(nettyHttpResponse);
  getReadyToSendEventSourceMessages(eventSourceConnectionHandler);
}

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

@Override
public void prepareHandshakeResponse(NettyWebSocketConnection webSocketConnection) {
  webSocketConnection.setVersion("HIXIE-76");
  res.setStatus(new HttpResponseStatus(101, "Web Socket Protocol Handshake"));
  res.addHeader(UPGRADE, WEBSOCKET);
  res.addHeader(CONNECTION, UPGRADE);
  res.addHeader(SEC_WEBSOCKET_ORIGIN, req.getHeader(ORIGIN));
  res.addHeader(SEC_WEBSOCKET_LOCATION, getWebSocketLocation(req));
  String protocol = req.getHeader(SEC_WEBSOCKET_PROTOCOL);
  if (protocol != null) {
    res.addHeader(SEC_WEBSOCKET_PROTOCOL, protocol);
  }
  // Calculate the answer of the challenge.
  String key1 = req.getHeader(SEC_WEBSOCKET_KEY1);
  String key2 = req.getHeader(SEC_WEBSOCKET_KEY2);
  int a = (int) (Long.parseLong(key1.replaceAll("[^0-9]", "")) / key1.replaceAll("[^ ]", "").length());
  int b = (int) (Long.parseLong(key2.replaceAll("[^0-9]", "")) / key2.replaceAll("[^ ]", "").length());
  long c = req.getContent().readLong();
  ChannelBuffer input = ChannelBuffers.buffer(16);
  input.writeInt(a);
  input.writeInt(b);
  input.writeLong(c);
  ChannelBuffer output = ChannelBuffers.wrappedBuffer(MD5.digest(input.array()));
  res.setContent(output);
}

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

@Override
public void prepareHandshakeResponse(NettyWebSocketConnection webSocketConnection) {
  webSocketConnection.setVersion("HIXIE-75");
  res.setStatus(new HttpResponseStatus(101, "Web Socket Protocol Handshake"));
  res.addHeader(UPGRADE, WEBSOCKET);
  res.addHeader(CONNECTION, HttpHeaders.Values.UPGRADE);
  String origin = req.getHeader(ORIGIN);
  if (origin != null) {
    res.addHeader(WEBSOCKET_ORIGIN, origin);
  }
  res.addHeader(WEBSOCKET_LOCATION, getWebSocketLocation(req));
  String protocol = req.getHeader(WEBSOCKET_PROTOCOL);
  if (protocol != null) {
    res.addHeader(WEBSOCKET_PROTOCOL, protocol);
  }
}

代码示例来源:origin: org.webbitserver/webbit

@Override
public NettyHttpResponse status(int status) {
  response.setStatus(HttpResponseStatus.valueOf(status));
  return this;
}

代码示例来源:origin: org.webbitserver/webbit

@Override
public NettyHttpResponse error(Throwable error) {
  if (error instanceof TooLongFrameException) {
    response.setStatus(HttpResponseStatus.REQUEST_ENTITY_TOO_LARGE);
  } else {
    response.setStatus(HttpResponseStatus.INTERNAL_SERVER_ERROR);
  }
  String message = getStackTrace(error);
  header("Content-Type", "text/plain");
  content(message);
  flushResponse();
  exceptionHandler.uncaughtException(Thread.currentThread(),
      WebbitException.fromException(error, ctx.getChannel()));
  return this;
}

代码示例来源:origin: org.webbitserver/webbit

@Override
public void prepareHandshakeResponse(NettyWebSocketConnection webSocketConnection) {
  webSocketConnection.setHybiWebSocketVersion(getHybiVersion());
  if (getHybiVersion() < MIN_HYBI_VERSION) {
    res.setStatus(HttpResponseStatus.UPGRADE_REQUIRED);
    res.setHeader(SEC_WEBSOCKET_VERSION, String.valueOf(MIN_HYBI_VERSION));
    return;
  }
  String key = req.getHeader(SEC_WEBSOCKET_KEY);
  if (key == null) {
    res.setStatus(HttpResponseStatus.BAD_REQUEST);
    return;
  }
  String accept = Base64.encode(sha1(key + ACCEPT_GUID));
  res.setStatus(new HttpResponseStatus(101, "Switching Protocols"));
  res.addHeader(UPGRADE, WEBSOCKET.toLowerCase());
  res.addHeader(CONNECTION, UPGRADE);
  res.addHeader(SEC_WEBSOCKET_ACCEPT, accept);
  String webSocketProtocol = req.getHeader(SEC_WEBSOCKET_PROTOCOL);
  if (webSocketProtocol != null) {
    res.addHeader(SEC_WEBSOCKET_PROTOCOL, webSocketProtocol);
  }
}

代码示例来源:origin: org.webbitserver/webbit

private void performEventSourceHandshake(ChannelHandler eventSourceConnectionHandler) {
  nettyHttpResponse.setStatus(HttpResponseStatus.OK);
  nettyHttpResponse.addHeader("Content-Type", "text/event-stream");
  nettyHttpResponse.addHeader("Transfer-Encoding", "identity");
  nettyHttpResponse.addHeader("Connection", "keep-alive");
  nettyHttpResponse.addHeader("Cache-Control", "no-cache");
  nettyHttpResponse.setChunked(false);
  ctx.getChannel().write(nettyHttpResponse);
  getReadyToSendEventSourceMessages(eventSourceConnectionHandler);
}

代码示例来源:origin: org.webbitserver/webbit

@Override
public void prepareHandshakeResponse(NettyWebSocketConnection webSocketConnection) {
  webSocketConnection.setVersion("HIXIE-76");
  res.setStatus(new HttpResponseStatus(101, "Web Socket Protocol Handshake"));
  res.addHeader(UPGRADE, WEBSOCKET);
  res.addHeader(CONNECTION, UPGRADE);
  res.addHeader(SEC_WEBSOCKET_ORIGIN, req.getHeader(ORIGIN));
  res.addHeader(SEC_WEBSOCKET_LOCATION, getWebSocketLocation(req));
  String protocol = req.getHeader(SEC_WEBSOCKET_PROTOCOL);
  if (protocol != null) {
    res.addHeader(SEC_WEBSOCKET_PROTOCOL, protocol);
  }
  // Calculate the answer of the challenge.
  String key1 = req.getHeader(SEC_WEBSOCKET_KEY1);
  String key2 = req.getHeader(SEC_WEBSOCKET_KEY2);
  int a = (int) (Long.parseLong(key1.replaceAll("[^0-9]", "")) / key1.replaceAll("[^ ]", "").length());
  int b = (int) (Long.parseLong(key2.replaceAll("[^0-9]", "")) / key2.replaceAll("[^ ]", "").length());
  long c = req.getContent().readLong();
  ChannelBuffer input = ChannelBuffers.buffer(16);
  input.writeInt(a);
  input.writeInt(b);
  input.writeLong(c);
  ChannelBuffer output = ChannelBuffers.wrappedBuffer(MD5.digest(input.array()));
  res.setContent(output);
}

代码示例来源:origin: zauberlabs/gnip4j

if (uri.equals("/")) {
  final HttpResponse response = new DefaultHttpResponse(HTTP_1_1, OK);
  response.setStatus(MOVED_PERMANENTLY);
  setHeader(response, LOCATION, "/fake-stream");

代码示例来源:origin: cgbystrom/sockjs-netty

public void handle(HttpRequest request, HttpResponse response) {
  QueryStringDecoder qsd = new QueryStringDecoder(request.getUri());
  String path = qsd.getPath();
  if (!path.matches(".*/iframe[0-9-.a-z_]*.html")) {
    response.setStatus(HttpResponseStatus.NOT_FOUND);
    response.setContent(ChannelBuffers.copiedBuffer("Not found", CharsetUtil.UTF_8));
    return;
  }
  response.setHeader(HttpHeaders.Names.SET_COOKIE, "JSESSIONID=dummy; path=/");
  if (request.containsHeader(HttpHeaders.Names.IF_NONE_MATCH)) {
    response.setStatus(HttpResponseStatus.NOT_MODIFIED);
    response.removeHeader(HttpHeaders.Names.CONTENT_TYPE);
  } else {
    response.setHeader(HttpHeaders.Names.CONTENT_TYPE, "text/html; charset=UTF-8");
    response.setHeader(HttpHeaders.Names.CACHE_CONTROL, "max-age=31536000, public");
    response.setHeader(HttpHeaders.Names.EXPIRES, "FIXME"); // FIXME: Fix this
    response.removeHeader(HttpHeaders.Names.SET_COOKIE);
    response.setContent(content);
  }
  response.setHeader(HttpHeaders.Names.ETAG, etag);
}

代码示例来源:origin: com.google.code.maven-play-plugin.org.playframework/play

public void prepareNettyResponse(HttpResponse nettyResponse) {
  nettyResponse.headers().add("Accept-Ranges", "bytes");
  if(unsatisfiable) {
    nettyResponse.setStatus(HttpResponseStatus.REQUESTED_RANGE_NOT_SATISFIABLE);
    nettyResponse.headers().set("Content-Range", "bytes " + 0 + "-" + (fileLength-1) + "/" + fileLength);
    nettyResponse.headers().set("Content-length", 0);
  } else {
    nettyResponse.setStatus(HttpResponseStatus.PARTIAL_CONTENT);
    if(byteRanges.length == 1) {
      ByteRange range = byteRanges[0];
      nettyResponse.headers().set("Content-Range", "bytes " + range.start + "-" + range.end + "/" + fileLength);
    } else {
      nettyResponse.headers().set("Content-type", "multipart/byteranges; boundary="+DEFAULT_SEPARATOR);
    }
    long length = 0;
    for(ByteRange range: byteRanges) {
      length += range.computeTotalLength();
    }
    nettyResponse.headers().set("Content-length", length);
  }
}

代码示例来源:origin: org.vert-x/vertx-core

private void writeHead() {
 if (!headWritten) {
  HttpResponseStatus status = statusMessage == null ? HttpResponseStatus.valueOf(statusCode) :
    new HttpResponseStatus(statusCode, statusMessage);
  response.setStatus(status);
  if (version == HttpVersion.HTTP_1_0 && keepAlive) {
   response.setHeader("Connection", "Keep-Alive");
  }
  writeHeaders();
  if (chunked) {
   response.setHeader(Names.TRANSFER_ENCODING, HttpHeaders.Values.CHUNKED);
  } else if (version != HttpVersion.HTTP_1_0 && !contentLengthSet()) {
   response.setHeader(Names.CONTENT_LENGTH, "0");
  }
  channelFuture = conn.write(response);
  headWritten = true;
 }
}

代码示例来源:origin: org.webbitserver/webbit

@Override
public void prepareHandshakeResponse(NettyWebSocketConnection webSocketConnection) {
  webSocketConnection.setVersion("HIXIE-75");
  res.setStatus(new HttpResponseStatus(101, "Web Socket Protocol Handshake"));
  res.addHeader(UPGRADE, WEBSOCKET);
  res.addHeader(CONNECTION, HttpHeaders.Values.UPGRADE);
  String origin = req.getHeader(ORIGIN);
  if (origin != null) {
    res.addHeader(WEBSOCKET_ORIGIN, origin);
  }
  res.addHeader(WEBSOCKET_LOCATION, getWebSocketLocation(req));
  String protocol = req.getHeader(WEBSOCKET_PROTOCOL);
  if (protocol != null) {
    res.addHeader(WEBSOCKET_PROTOCOL, protocol);
  }
}

相关文章