本文整理匯總了Java中io.netty.handler.codec.http.LastHttpContent類的典型用法代碼示例。如果您正苦於以下問題:Java LastHttpContent類的具體用法?Java LastHttpContent怎麽用?Java LastHttpContent使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
LastHttpContent類屬於io.netty.handler.codec.http包,在下文中一共展示了LastHttpContent類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: write
import io.netty.handler.codec.http.LastHttpContent; //導入依賴的package包/類
@Override
public void write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise) throws Exception {
HttpProcessingState state = ChannelAttributes.getHttpProcessingStateForChannel(ctx).get();
allowCompressionForThisRequest = false;
if (state != null) {
// We only want to allow compression if the endpoint being hit is *not* a ProxyRouterEndpoint, the response is full, and the response size
// is greater than the threshold
boolean isFull = msg instanceof HttpResponse && msg instanceof LastHttpContent;
boolean endpointAllowed = endpointAllowsCompression(state.getEndpointForExecution());
boolean responseInfoAllowed =
state.getResponseInfo() == null || !state.getResponseInfo().isPreventCompressedOutput();
if (isFull && endpointAllowed && responseInfoAllowed
&& ((LastHttpContent) msg).content().readableBytes() > responseSizeThresholdBytes) {
allowCompressionForThisRequest = true;
}
}
super.write(ctx, msg, promise);
}
示例2: beforeRequest
import io.netty.handler.codec.http.LastHttpContent; //導入依賴的package包/類
@Override
public void beforeRequest(Channel clientChannel, HttpContent httpContent,
HttpProxyInterceptPipeline pipeline) throws Exception {
if (content != null) {
ByteBuf temp = httpContent.content().slice();
content.writeBytes(temp);
if (httpContent instanceof LastHttpContent) {
try {
byte[] contentBts = new byte[content.readableBytes()];
content.readBytes(contentBts);
((HttpRequestInfo) pipeline.getHttpRequest()).setContent(contentBts);
} finally {
ReferenceCountUtil.release(content);
content = null; //狀態回歸
}
}
}
pipeline.beforeRequest(clientChannel, httpContent);
}
示例3: getTrailingHeaders
import io.netty.handler.codec.http.LastHttpContent; //導入依賴的package包/類
@Override
protected List<Entry<String, String>> getTrailingHeaders(Object obj) {
List chunkes = (List) obj;
Map<String, String> trailingHeaders = new LinkedHashMap<>();
for (Object chunk : chunkes) {
if (chunk instanceof LastHttpContent) {
Iterator<Entry<String, String>> it = ((LastHttpContent) chunk)
.trailingHeaders().iterator();
while (it.hasNext()) {
Entry<String, String> next = it.next();
trailingHeaders.put(next.getKey(), next.getValue());
}
}
}
return new ArrayList<>(trailingHeaders.entrySet());
}
示例4: doChannelRead
import io.netty.handler.codec.http.LastHttpContent; //導入依賴的package包/類
@Override
public PipelineContinuationBehavior doChannelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
if (msg instanceof LastHttpContent) {
HttpProcessingState state = ChannelAttributes.getHttpProcessingStateForChannel(ctx).get();
Endpoint<?> endpoint = state.getEndpointForExecution();
RequestInfo reqInfo = state.getRequestInfo();
// Don't bother trying to deserialize until we have an endpoint and the request content has fully arrived
if (endpoint != null && reqInfo.isCompleteRequestWithAllChunks()) {
// Setup the content deserializer if desired
TypeReference<?> contentTypeRef = endpoint.requestContentType();
if (contentTypeRef != null) {
// A non-null TypeReference is available, so deserialization is possible. Retrieve the appropriate
// deserializer and setup the RequestInfo so that it can lazily deserialize when requested.
ObjectMapper deserializer = endpoint.customRequestContentDeserializer(reqInfo);
if (deserializer == null)
deserializer = defaultRequestContentDeserializer;
//noinspection unchecked
reqInfo.setupContentDeserializer(deserializer, contentTypeRef);
}
}
}
return PipelineContinuationBehavior.CONTINUE;
}
示例5: mock
import io.netty.handler.codec.http.LastHttpContent; //導入依賴的package包/類
@Test
public void StreamingChannel_doStreamChunk_works_as_expected_when_last_chunk_already_sent_downstream_and_incoming_chunk_is_empty_last_chunk() {
// given
streamingChannelSpy.downstreamLastChunkSentHolder.heldObject = true;
LastHttpContent contentChunkMock = mock(LastHttpContent.class);
ByteBuf contentByteBufMock = mock(ByteBuf.class);
doReturn(contentByteBufMock).when(contentChunkMock).content();
doReturn(0).when(contentByteBufMock).readableBytes();
ChannelFuture successFutureMock = mock(ChannelFuture.class);
doReturn(successFutureMock).when(channelMock).newSucceededFuture();
// when
ChannelFuture result = streamingChannelSpy.doStreamChunk(contentChunkMock);
// then
verify(channelMock, never()).writeAndFlush(any(Object.class));
verify(contentChunkMock).release();
verify(channelMock).newSucceededFuture();
assertThat(result).isSameAs(successFutureMock);
}
示例6: beforeMethod
import io.netty.handler.codec.http.LastHttpContent; //導入依賴的package包/類
@Before
public void beforeMethod() {
channelMock = mock(Channel.class);
ctxMock = mock(ChannelHandlerContext.class);
stateAttributeMock = mock(Attribute.class);
state = new HttpProcessingState();
doReturn(channelMock).when(ctxMock).channel();
doReturn(stateAttributeMock).when(channelMock).attr(ChannelAttributes.HTTP_PROCESSING_STATE_ATTRIBUTE_KEY);
doReturn(state).when(stateAttributeMock).get();
firstChunkMsgMock = mock(HttpRequest.class);
lastChunkMsgMock = mock(LastHttpContent.class);
filter1Mock = mock(RequestAndResponseFilter.class);
filter2Mock = mock(RequestAndResponseFilter.class);
filtersList = Arrays.asList(filter1Mock, filter2Mock);
handlerSpy = spy(new RequestFilterHandler(filtersList));
requestInfoMock = mock(RequestInfo.class);
state.setRequestInfo(requestInfoMock);
}
示例7: mock
import io.netty.handler.codec.http.LastHttpContent; //導入依賴的package包/類
@Test
public void argsAreEligibleForLinkingAndUnlinkingDistributedTracingInfo_only_returns_true_for_HttpRequest_or_LastHttpContent() {
// given
Object httpRequestMsg = mock(HttpRequest.class);
Object lastHttpContentMsg = mock(LastHttpContent.class);
Object httpMessageMsg = mock(HttpMessage.class);
// expect
assertThat(handlerSpy.argsAreEligibleForLinkingAndUnlinkingDistributedTracingInfo(
DO_CHANNEL_READ, ctxMock, httpRequestMsg, null)
).isTrue();
assertThat(handlerSpy.argsAreEligibleForLinkingAndUnlinkingDistributedTracingInfo(
DO_CHANNEL_READ, ctxMock, lastHttpContentMsg, null)
).isTrue();
assertThat(handlerSpy.argsAreEligibleForLinkingAndUnlinkingDistributedTracingInfo(
DO_CHANNEL_READ, ctxMock, httpMessageMsg, null)
).isFalse();
}
示例8: beforeMethod
import io.netty.handler.codec.http.LastHttpContent; //導入依賴的package包/類
@Before
public void beforeMethod() {
stateMock = mock(HttpProcessingState.class);
ctxMock = mock(ChannelHandlerContext.class);
channelMock = mock(Channel.class);
pipelineMock = mock(ChannelPipeline.class);
stateAttrMock = mock(Attribute.class);
proxyRouterProcessingStateAttrMock = mock(Attribute.class);
metricsListenerMock = mock(MetricsListener.class);
msgMockFirstChunkOnly = mock(HttpRequest.class);
msgMockFullRequest = mock(FullHttpRequest.class);
msgMockLastChunkOnly = mock(LastHttpContent.class);
idleChannelTimeoutHandlerMock = mock(IdleChannelTimeoutHandler.class);
doReturn(channelMock).when(ctxMock).channel();
doReturn(pipelineMock).when(ctxMock).pipeline();
doReturn(idleChannelTimeoutHandlerMock).when(pipelineMock).get(IDLE_CHANNEL_TIMEOUT_HANDLER_NAME);
doReturn(stateAttrMock).when(channelMock).attr(ChannelAttributes.HTTP_PROCESSING_STATE_ATTRIBUTE_KEY);
doReturn(stateMock).when(stateAttrMock).get();
doReturn(proxyRouterProcessingStateAttrMock).when(channelMock).attr(ChannelAttributes.PROXY_ROUTER_PROCESSING_STATE_ATTRIBUTE_KEY);
handler = new RequestStateCleanerHandler(metricsListenerMock, incompleteHttpCallTimeoutMillis);
}
示例9: beforeMethod
import io.netty.handler.codec.http.LastHttpContent; //導入依賴的package包/類
@Before
public void beforeMethod() {
msg = mock(LastHttpContent.class);
stateMock = mock(HttpProcessingState.class);
ctxMock = mock(ChannelHandlerContext.class);
channelMock = mock(Channel.class);
stateAttrMock = mock(Attribute.class);
endpointMock = mock(Endpoint.class);
requestInfoSpy = spy((RequestInfo<String>) RequestInfoImpl.dummyInstanceForUnknownRequests());
String rawContentString = UUID.randomUUID().toString();
Whitebox.setInternalState(requestInfoSpy, "rawContent", rawContentString);
Whitebox.setInternalState(requestInfoSpy, "rawContentBytes", rawContentString.getBytes());
defaultHandlerDeserializerMock = mock(ObjectMapper.class);
doReturn(channelMock).when(ctxMock).channel();
doReturn(stateAttrMock).when(channelMock).attr(ChannelAttributes.HTTP_PROCESSING_STATE_ATTRIBUTE_KEY);
doReturn(stateMock).when(stateAttrMock).get();
doReturn(endpointMock).when(stateMock).getEndpointForExecution();
doReturn(requestInfoSpy).when(stateMock).getRequestInfo();
doReturn(contentTypeRef).when(endpointMock).requestContentType();
doReturn(endpointMatcher).when(endpointMock).requestMatcher();
handler = new RequestContentDeserializerHandler(defaultHandlerDeserializerMock);
}
示例10: addContentChunk_adds_last_chunk_trailing_headers
import io.netty.handler.codec.http.LastHttpContent; //導入依賴的package包/類
@Test
public void addContentChunk_adds_last_chunk_trailing_headers() {
// given
RequestInfoImpl<?> requestInfo = RequestInfoImpl.dummyInstanceForUnknownRequests();
requestInfo.isCompleteRequestWithAllChunks = false;
LastHttpContent lastChunk = new DefaultLastHttpContent(Unpooled.copiedBuffer(UUID.randomUUID().toString(), CharsetUtil.UTF_8));
String headerKey = UUID.randomUUID().toString();
List<String> headerVal = Arrays.asList(UUID.randomUUID().toString(), UUID.randomUUID().toString());
lastChunk.trailingHeaders().add(headerKey, headerVal);
// when
requestInfo.addContentChunk(lastChunk);
// then
assertThat(requestInfo.trailingHeaders.names().size(), is(1));
assertThat(requestInfo.trailingHeaders.getAll(headerKey), is(headerVal));
}
示例11: write
import io.netty.handler.codec.http.LastHttpContent; //導入依賴的package包/類
@Override
public void write(Channel channel, NettyResponseFuture<?> future) throws IOException {
final InputStream is = inputStream;
if (future.isStreamWasAlreadyConsumed()) {
if (is.markSupported())
is.reset();
else {
LOGGER.warn("Stream has already been consumed and cannot be reset");
return;
}
} else {
future.setStreamWasAlreadyConsumed(true);
}
channel.write(new ChunkedStream(is), channel.newProgressivePromise()).addListener(
new ProgressListener(future.getAsyncHandler(), future, false, getContentLength()) {
public void operationComplete(ChannelProgressiveFuture cf) {
closeSilently(is);
super.operationComplete(cf);
}
});
channel.writeAndFlush(LastHttpContent.EMPTY_LAST_CONTENT);
}
示例12: handleChunk
import io.netty.handler.codec.http.LastHttpContent; //導入依賴的package包/類
private void handleChunk(HttpContent chunk,//
final Channel channel,//
final NettyResponseFuture<?> future,//
AsyncHandler<?> handler) throws IOException, Exception {
boolean interrupt = false;
boolean last = chunk instanceof LastHttpContent;
// Netty 4: the last chunk is not empty
if (last) {
LastHttpContent lastChunk = (LastHttpContent) chunk;
HttpHeaders trailingHeaders = lastChunk.trailingHeaders();
if (!trailingHeaders.isEmpty()) {
interrupt = handler.onHeadersReceived(new HttpResponseHeaders(trailingHeaders, true)) != State.CONTINUE;
}
}
ByteBuf buf = chunk.content();
if (!interrupt && !(handler instanceof StreamedAsyncHandler) && (buf.readableBytes() > 0 || last)) {
HttpResponseBodyPart part = config.getResponseBodyPartFactory().newResponseBodyPart(buf, last);
interrupt = updateBodyAndInterrupt(future, handler, part);
}
if (interrupt || last)
finishUpdate(future, channel, !last);
}
示例13: clientToProxyRequest
import io.netty.handler.codec.http.LastHttpContent; //導入依賴的package包/類
@Override
public HttpResponse clientToProxyRequest(HttpObject httpObject) {
if (httpObject instanceof HttpRequest) {
this.httpRequest = (HttpRequest) httpObject;
}
if (httpObject instanceof HttpContent) {
HttpContent httpContent = (HttpContent) httpObject;
storeRequestContent(httpContent);
if (httpContent instanceof LastHttpContent) {
LastHttpContent lastHttpContent = (LastHttpContent) httpContent;
trailingHeaders = lastHttpContent .trailingHeaders();
}
}
return null;
}
示例14: serverToProxyResponse
import io.netty.handler.codec.http.LastHttpContent; //導入依賴的package包/類
@Override
public HttpObject serverToProxyResponse(HttpObject httpObject) {
if (httpObject instanceof HttpResponse) {
httpResponse = (HttpResponse) httpObject;
captureContentEncoding(httpResponse);
}
if (httpObject instanceof HttpContent) {
HttpContent httpContent = (HttpContent) httpObject;
storeResponseContent(httpContent);
if (httpContent instanceof LastHttpContent) {
LastHttpContent lastContent = (LastHttpContent) httpContent;
captureTrailingHeaders(lastContent);
captureFullResponseContents();
}
}
return super.serverToProxyResponse(httpObject);
}
示例15: onOutboundComplete
import io.netty.handler.codec.http.LastHttpContent; //導入依賴的package包/類
@Override
protected void onOutboundComplete() {
if (isWebsocket() || isInboundCancelled()) {
return;
}
if (markSentHeaderAndBody()) {
if (log.isDebugEnabled()) {
log.debug("No sendHeaders() called before complete, sending " + "zero-length header");
}
channel().writeAndFlush(newFullEmptyBodyMessage());
}
else if (markSentBody()) {
channel().writeAndFlush(LastHttpContent.EMPTY_LAST_CONTENT);
}
channel().read();
}