本文整理了Java中org.jboss.netty.handler.codec.http.HttpResponse.setChunked()
方法的一些代码示例,展示了HttpResponse.setChunked()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。HttpResponse.setChunked()
方法的具体详情如下:
包路径:org.jboss.netty.handler.codec.http.HttpResponse
类名称:HttpResponse
方法名:setChunked
暂无
代码示例来源:origin: apache/incubator-druid
response.setChunked(true);
ClientResponse<InputStream> clientResponse = responseHandler.handleResponse(response, null);
final int failAt = RANDOM.nextInt(allBytes.length);
代码示例来源:origin: apache/incubator-druid
@Test
public void simpleMultiStreamTest() throws IOException
{
Iterator<byte[]> it = BYTE_LIST.iterator();
SequenceInputStreamResponseHandler responseHandler = new SequenceInputStreamResponseHandler();
final HttpResponse response = new DefaultHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.OK);
response.setChunked(true);
ClientResponse<InputStream> clientResponse = responseHandler.handleResponse(response, null);
long chunkNum = 0;
while (it.hasNext()) {
final DefaultHttpChunk chunk = new DefaultHttpChunk(new BigEndianHeapChannelBuffer(it.next()));
clientResponse = responseHandler.handleChunk(clientResponse, chunk, ++chunkNum);
}
clientResponse = responseHandler.done(clientResponse);
final InputStream stream = clientResponse.getObj();
final InputStream expectedStream = new ByteArrayInputStream(allBytes);
int read = 0;
while (read < allBytes.length) {
final byte[] expectedBytes = new byte[Math.min(RANDOM.nextInt(128), allBytes.length - read)];
final byte[] actualBytes = new byte[expectedBytes.length];
fillBuff(stream, actualBytes);
fillBuff(expectedStream, expectedBytes);
Assert.assertArrayEquals(expectedBytes, actualBytes);
read += expectedBytes.length;
}
Assert.assertEquals(allBytes.length, responseHandler.getByteCount());
}
代码示例来源:origin: apache/incubator-druid
@Test
public void simpleSingleStreamTest() throws IOException
{
SequenceInputStreamResponseHandler responseHandler = new SequenceInputStreamResponseHandler();
final HttpResponse response = new DefaultHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.OK);
response.setChunked(false);
response.setContent(new BigEndianHeapChannelBuffer(allBytes));
ClientResponse<InputStream> clientResponse = responseHandler.handleResponse(response, null);
clientResponse = responseHandler.done(clientResponse);
final InputStream stream = clientResponse.getObj();
final InputStream expectedStream = new ByteArrayInputStream(allBytes);
int read = 0;
while (read < allBytes.length) {
final byte[] expectedBytes = new byte[Math.min(RANDOM.nextInt(128), allBytes.length - read)];
final byte[] actualBytes = new byte[expectedBytes.length];
fillBuff(stream, actualBytes);
fillBuff(expectedStream, expectedBytes);
Assert.assertArrayEquals(expectedBytes, actualBytes);
read += expectedBytes.length;
}
Assert.assertEquals(allBytes.length, responseHandler.getByteCount());
}
代码示例来源:origin: apache/incubator-druid
@Test
public void alignedMultiStreamTest() throws IOException
{
Iterator<byte[]> it = BYTE_LIST.iterator();
SequenceInputStreamResponseHandler responseHandler = new SequenceInputStreamResponseHandler();
final HttpResponse response = new DefaultHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.OK);
response.setChunked(true);
ClientResponse<InputStream> clientResponse = responseHandler.handleResponse(response, null);
long chunkNum = 0;
while (it.hasNext()) {
final DefaultHttpChunk chunk = new DefaultHttpChunk(new BigEndianHeapChannelBuffer(it.next()));
clientResponse = responseHandler.handleChunk(clientResponse, chunk, ++chunkNum);
}
clientResponse = responseHandler.done(clientResponse);
final InputStream stream = clientResponse.getObj();
final InputStream expectedStream = new ByteArrayInputStream(allBytes);
for (byte[] bytes : BYTE_LIST) {
final byte[] expectedBytes = new byte[bytes.length];
final byte[] actualBytes = new byte[expectedBytes.length];
fillBuff(stream, actualBytes);
fillBuff(expectedStream, expectedBytes);
Assert.assertArrayEquals(expectedBytes, actualBytes);
Assert.assertArrayEquals(expectedBytes, bytes);
}
Assert.assertEquals(allBytes.length, responseHandler.getByteCount());
}
代码示例来源:origin: apache/incubator-druid
@Test(expected = TesterException.class)
public void testExceptionalSingleStream() throws IOException
{
SequenceInputStreamResponseHandler responseHandler = new SequenceInputStreamResponseHandler();
final HttpResponse response = new DefaultHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.OK);
response.setChunked(false);
response.setContent(
new BigEndianHeapChannelBuffer(allBytes)
{
@Override
public void getBytes(int index, byte[] dst, int dstIndex, int length)
{
if (dstIndex + length >= allBytes.length) {
throw new TesterException();
}
super.getBytes(index, dst, dstIndex, length);
}
}
);
ClientResponse<InputStream> clientResponse = responseHandler.handleResponse(response, null);
clientResponse = responseHandler.done(clientResponse);
final InputStream stream = clientResponse.getObj();
final byte[] buff = new byte[allBytes.length];
fillBuff(stream, buff);
}
代码示例来源:origin: webbit/webbit
@Override
public NettyHttpResponse chunked() {
response.setHeader(Names.TRANSFER_ENCODING, Values.CHUNKED);
response.setChunked(true);
ctx.getChannel().write(response);
return this;
}
代码示例来源: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: org.webbitserver/webbit
@Override
public NettyHttpResponse chunked() {
response.setHeader(Names.TRANSFER_ENCODING, Values.CHUNKED);
response.setChunked(true);
ctx.getChannel().write(response);
return this;
}
代码示例来源:origin: org.vert-x/vertx-core
private void sendError(String err, HttpResponseStatus status, Channel ch) {
HttpResponse resp = new DefaultHttpResponse(HTTP_1_1, status);
resp.setChunked(false);
if (status.getCode() == METHOD_NOT_ALLOWED.getCode()) {
// SockJS requires this
resp.setHeader("allow", "GET");
}
if (err != null) {
ChannelBuffer buff = ChannelBuffers.copiedBuffer(err.getBytes(Charset.forName("UTF-8")));
resp.setHeader("Content-Length", err.length());
resp.setContent(buff);
} else {
resp.setHeader(HttpHeaders.Names.CONTENT_LENGTH, "0");
}
ch.write(resp);
}
代码示例来源: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: metamx/java-util
@Test
public void simpleMultiStreamTest() throws IOException
{
Iterator<byte[]> it = BYTE_LIST.iterator();
SequenceInputStreamResponseHandler responseHandler = new SequenceInputStreamResponseHandler();
final HttpResponse response = new DefaultHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.OK);
response.setChunked(true);
ClientResponse<InputStream> clientResponse = responseHandler.handleResponse(response);
while (it.hasNext()) {
final DefaultHttpChunk chunk = new DefaultHttpChunk(new BigEndianHeapChannelBuffer(it.next()));
clientResponse = responseHandler.handleChunk(clientResponse, chunk);
}
clientResponse = responseHandler.done(clientResponse);
final InputStream stream = clientResponse.getObj();
final InputStream expectedStream = new ByteArrayInputStream(allBytes);
int read = 0;
while (read < allBytes.length) {
final byte[] expectedBytes = new byte[Math.min(Math.abs(RANDOM.nextInt()) % 128, allBytes.length - read)];
final byte[] actualBytes = new byte[expectedBytes.length];
fillBuff(stream, actualBytes);
fillBuff(expectedStream, expectedBytes);
Assert.assertArrayEquals(expectedBytes, actualBytes);
read += expectedBytes.length;
}
Assert.assertEquals(allBytes.length, responseHandler.getByteCount());
}
代码示例来源:origin: metamx/java-util
@Test
public void simpleSingleStreamTest() throws IOException
{
SequenceInputStreamResponseHandler responseHandler = new SequenceInputStreamResponseHandler();
final HttpResponse response = new DefaultHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.OK);
response.setChunked(false);
response.setContent(new BigEndianHeapChannelBuffer(allBytes));
ClientResponse<InputStream> clientResponse = responseHandler.handleResponse(response);
clientResponse = responseHandler.done(clientResponse);
final InputStream stream = clientResponse.getObj();
final InputStream expectedStream = new ByteArrayInputStream(allBytes);
int read = 0;
while (read < allBytes.length) {
final byte[] expectedBytes = new byte[Math.min(Math.abs(RANDOM.nextInt()) % 128, allBytes.length - read)];
final byte[] actualBytes = new byte[expectedBytes.length];
fillBuff(stream, actualBytes);
fillBuff(expectedStream, expectedBytes);
Assert.assertArrayEquals(expectedBytes, actualBytes);
read += expectedBytes.length;
}
Assert.assertEquals(allBytes.length, responseHandler.getByteCount());
}
代码示例来源:origin: projectodd/stilts
@Override
public HttpResponse generateResponse(HttpRequest request) throws Exception {
HttpResponse response = new DefaultHttpResponse( HttpVersion.HTTP_1_1, new HttpResponseStatus( 101, "Web Socket Protocol Handshake - IETF-07" ) );
String origin = request.getHeader( Names.ORIGIN );
if (origin != null) {
response.addHeader( Names.ORIGIN, origin );
}
response.addHeader( Names.SEC_WEBSOCKET_LOCATION, getWebSocketLocation( request ) );
String protocol = request.getHeader( Names.SEC_WEBSOCKET_PROTOCOL );
if (protocol != null) {
response.addHeader( Names.SEC_WEBSOCKET_PROTOCOL, protocol );
}
String key = request.getHeader( "Sec-WebSocket-Key" );
String solution = Ietf07WebSocketChallenge.solve( key );
response.addHeader( "Sec-WebSocket-Accept", solution );
response.setChunked( false );
return response;
}
代码示例来源:origin: projectodd/stilts
@Override
public HttpResponse generateResponse(HttpRequest request) throws Exception {
HttpResponse response = new DefaultHttpResponse( HttpVersion.HTTP_1_1, new HttpResponseStatus( 101, "Web Socket Protocol Handshake - IETF-07" ) );
String origin = request.getHeader( Names.ORIGIN );
if (origin != null) {
response.addHeader( Names.SEC_WEBSOCKET_ORIGIN, origin );
}
response.addHeader( Names.SEC_WEBSOCKET_LOCATION, getWebSocketLocation( request ) );
String protocol = request.getHeader( Names.SEC_WEBSOCKET_PROTOCOL );
if (protocol != null) {
response.addHeader( Names.SEC_WEBSOCKET_PROTOCOL, protocol );
}
String key = request.getHeader( "Sec-WebSocket-Key" );
String solution = Ietf07WebSocketChallenge.solve( key );
response.addHeader( "Sec-WebSocket-Accept", solution );
response.setChunked( false );
return response;
}
代码示例来源:origin: projectodd/stilts
@Override
public HttpResponse generateResponse(HttpRequest request) throws Exception {
HttpResponse response = new DefaultHttpResponse( HttpVersion.HTTP_1_1, new HttpResponseStatus( 101, "Web Socket Protocol Handshake - IETF-07" ) );
String origin = request.getHeader( Names.ORIGIN );
if (origin != null) {
response.addHeader( Names.SEC_WEBSOCKET_ORIGIN, origin );
}
response.addHeader( Names.SEC_WEBSOCKET_LOCATION, getWebSocketLocation( request ) );
String protocol = request.getHeader( Names.SEC_WEBSOCKET_PROTOCOL );
if (protocol != null) {
response.addHeader( Names.SEC_WEBSOCKET_PROTOCOL, protocol );
}
String key = request.getHeader( "Sec-WebSocket-Key" );
String solution = Ietf07WebSocketChallenge.solve( key );
response.addHeader( "Sec-WebSocket-Accept", solution );
response.setChunked( false );
return response;
}
代码示例来源:origin: org.vert-x/vertx-core
public HttpResponse generateResponse(HttpRequest request, String serverOrigin) throws Exception {
HttpResponse response = new DefaultHttpResponse(HttpVersion.HTTP_1_1,
new HttpResponseStatus(101, "Switching Protocols"));
response.addHeader(HttpHeaders.Names.UPGRADE, "WebSocket");
response.addHeader(HttpHeaders.Names.CONNECTION, "Upgrade");
String origin = request.getHeader(Names.ORIGIN);
if (origin == null) {
origin = serverOrigin;
}
response.addHeader(Names.SEC_WEBSOCKET_ORIGIN, origin);
response.addHeader(Names.SEC_WEBSOCKET_LOCATION, getWebSocketLocation(request, serverOrigin));
String protocol = request.getHeader(Names.SEC_WEBSOCKET_PROTOCOL);
if (protocol != null) {
response.addHeader(Names.SEC_WEBSOCKET_PROTOCOL, protocol);
}
String key = request.getHeader("Sec-WebSocket-Key");
String solution = WebSocketChallenge08.solve(key);
response.addHeader("Sec-WebSocket-Accept", solution);
response.setChunked(false);
return response;
}
代码示例来源:origin: org.vert-x/vertx-core
public HttpResponse generateResponse(HttpRequest request, String serverOrigin) throws Exception {
HttpResponse response = new DefaultHttpResponse(HttpVersion.HTTP_1_1, new HttpResponseStatus(101,
"Switching Protocols"));
response.addHeader(Names.UPGRADE, "WebSocket");
response.addHeader(HttpHeaders.Names.CONNECTION, "Upgrade");
String origin = request.getHeader(Names.ORIGIN);
if (origin != null) {
response.addHeader(Names.SEC_WEBSOCKET_ORIGIN, origin);
}
response.addHeader(Names.SEC_WEBSOCKET_LOCATION, getWebSocketLocation(request, serverOrigin));
String protocol = request.getHeader(Names.SEC_WEBSOCKET_PROTOCOL);
if (protocol != null) {
response.addHeader(Names.SEC_WEBSOCKET_PROTOCOL, protocol);
}
String key = request.getHeader("Sec-WebSocket-Key");
String solution = WebSocketChallenge08.solve(key);
response.addHeader("Sec-WebSocket-Accept", solution);
response.setChunked(false);
return response;
}
代码示例来源:origin: metamx/java-util
@Test(expected = TesterException.class)
public void testExceptionalSingleStream() throws IOException
{
SequenceInputStreamResponseHandler responseHandler = new SequenceInputStreamResponseHandler();
final HttpResponse response = new DefaultHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.OK);
response.setChunked(false);
response.setContent(
new BigEndianHeapChannelBuffer(allBytes)
{
@Override
public void getBytes(int index, byte[] dst, int dstIndex, int length)
{
if (dstIndex + length >= allBytes.length) {
throw new TesterException();
}
super.getBytes(index, dst, dstIndex, length);
}
}
);
ClientResponse<InputStream> clientResponse = responseHandler.handleResponse(response);
clientResponse = responseHandler.done(clientResponse);
final InputStream stream = clientResponse.getObj();
final byte[] buff = new byte[allBytes.length];
fillBuff(stream, buff);
}
代码示例来源:origin: projectodd/stilts
@Override
public HttpResponse generateResponse(HttpRequest request) throws Exception {
HttpResponse response = new DefaultHttpResponse( HttpVersion.HTTP_1_1, new HttpResponseStatus( 101, "Web Socket Protocol Handshake - IETF-00" ) );
String origin = request.getHeader( Names.ORIGIN );
if (origin != null) {
response.addHeader( Names.SEC_WEBSOCKET_ORIGIN, request.getHeader( Names.ORIGIN ) );
}
response.addHeader( Names.SEC_WEBSOCKET_LOCATION, getWebSocketLocation( request ) );
String protocol = request.getHeader( Names.SEC_WEBSOCKET_PROTOCOL );
if (protocol != null) {
response.addHeader( Names.SEC_WEBSOCKET_PROTOCOL, protocol );
}
// Calculate the answer of the challenge.
String key1 = request.getHeader( Names.SEC_WEBSOCKET_KEY1 );
String key2 = request.getHeader( Names.SEC_WEBSOCKET_KEY2 );
byte[] key3 = new byte[8];
request.getContent().readBytes( key3 );
byte[] solution = Ietf00WebSocketChallenge.solve( key1, key2, key3 );
ChannelBuffer buffer = ChannelBuffers.dynamicBuffer( solution.length + 2 );
buffer.writeBytes( solution );
response.setContent( buffer );
response.setChunked( false );
return response;
}
代码示例来源:origin: org.vert-x/vertx-core
public HttpResponse generateResponse(HttpRequest request, String serverOrigin) throws Exception {
HttpResponse response = new DefaultHttpResponse(HttpVersion.HTTP_1_1, new HttpResponseStatus(101,
"WebSocket Protocol Handshake"));
response.addHeader(HttpHeaders.Names.CONNECTION, "Upgrade");
response.addHeader(HttpHeaders.Names.UPGRADE, "WebSocket");
String origin = request.getHeader(Names.ORIGIN);
if (origin == null) {
origin = serverOrigin;
}
response.addHeader(Names.SEC_WEBSOCKET_ORIGIN, origin);
response.addHeader(Names.SEC_WEBSOCKET_LOCATION, getWebSocketLocation(request, serverOrigin));
String protocol = request.getHeader(Names.SEC_WEBSOCKET_PROTOCOL);
if (protocol != null) {
response.addHeader(Names.SEC_WEBSOCKET_PROTOCOL, protocol);
}
// Calculate the answer of the challenge.
String key1 = request.getHeader(Names.SEC_WEBSOCKET_KEY1);
String key2 = request.getHeader(Names.SEC_WEBSOCKET_KEY2);
byte[] key3 = new byte[8];
request.getContent().readBytes(key3);
byte[] solution = WebSocketChallenge00.solve(key1, key2, key3);
ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(solution.length + 2);
buffer.writeBytes(solution);
response.addHeader("Content-Length", buffer.readableBytes());
response.setContent(buffer);
response.setChunked(false);
return response;
}
内容来源于网络,如有侵权,请联系作者删除!