From f4786f3ac7699f8f8664e7c7db0b7097585a0786 Mon Sep 17 00:00:00 2001 From: Stephane Landelle Date: Thu, 20 Apr 2017 15:12:04 +0200 Subject: [PATCH] Drop `HttpResponseHeaders` and add a default method to notify trailing headers, close #1397 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Motivation: HttpResponseHeaders brings an extra allocation and complexity for the sheer sake of holding the information that those headers are trailing ones. Trailing headers are actually a rare thing, we could just add an extra method on AsyncHandler with a default implementation that would noop. Modifications: * drop HttpResponseHeaders * pass Netty’s HttpHeaders * introduce AsyncHandler#onTrailingHeadersReceived Result: More simple API (no need to unwrap), less allocations --- .../AsyncCompletionHandler.java | 49 +++++++++---------- .../org/asynchttpclient/AsyncHandler.java | 17 +++++-- .../asynchttpclient/HttpResponseHeaders.java | 44 ----------------- .../java/org/asynchttpclient/Response.java | 6 +-- .../asynchttpclient/filter/FilterContext.java | 15 +++--- .../handler/BodyDeferringAsyncHandler.java | 17 ++++++- .../handler/TransferCompletionHandler.java | 11 +++-- .../resumable/ResumableAsyncHandler.java | 34 +++++-------- .../asynchttpclient/netty/NettyResponse.java | 13 +++-- .../netty/handler/HttpHandler.java | 9 ++-- .../netty/handler/WebSocketHandler.java | 8 +-- .../netty/handler/intercept/Interceptors.java | 4 +- .../intercept/ResponseFiltersInterceptor.java | 4 +- .../webdav/WebDavCompletionHandlerBase.java | 7 +-- .../ws/WebSocketUpgradeHandler.java | 5 +- .../asynchttpclient/AbstractBasicTest.java | 7 +-- .../AsyncStreamHandlerTest.java | 39 +++++++-------- .../AsyncStreamLifecycleTest.java | 5 +- .../org/asynchttpclient/BasicAuthTest.java | 3 +- .../asynchttpclient/FollowingThreadTest.java | 3 +- .../asynchttpclient/MultipleHeaderTest.java | 9 ++-- .../asynchttpclient/PostRedirectGetTest.java | 4 +- .../java/org/asynchttpclient/RC1KTest.java | 7 +-- .../org/asynchttpclient/RemoteSiteTest.java | 3 +- .../asynchttpclient/filter/FilterTest.java | 2 +- .../resumable/ResumableAsyncHandlerTest.java | 12 ++--- .../netty/NettyAsyncResponseTest.java | 8 +-- .../ReactiveStreamsDownLoadTest.java | 10 ++-- .../reactivestreams/ReactiveStreamsTest.java | 6 +-- .../request/body/EmptyBodyTest.java | 6 +-- .../request/body/ZeroCopyFileTest.java | 6 +-- .../test/EventCollectingHandler.java | 4 +- .../org/asynchttpclient/test/TestUtils.java | 4 +- .../AbstractSingleSubscriberBridge.java | 10 ++-- .../AbstractMaybeAsyncHandlerBridge.java | 11 ++--- .../AbstractMaybeAsyncHandlerBridgeTest.java | 9 ++-- .../extras/simple/SimpleAsyncHttpClient.java | 11 ++--- 37 files changed, 198 insertions(+), 224 deletions(-) delete mode 100644 client/src/main/java/org/asynchttpclient/HttpResponseHeaders.java diff --git a/client/src/main/java/org/asynchttpclient/AsyncCompletionHandler.java b/client/src/main/java/org/asynchttpclient/AsyncCompletionHandler.java index ec63edd284..5cb8530f82 100644 --- a/client/src/main/java/org/asynchttpclient/AsyncCompletionHandler.java +++ b/client/src/main/java/org/asynchttpclient/AsyncCompletionHandler.java @@ -16,14 +16,15 @@ */ package org.asynchttpclient; +import io.netty.handler.codec.http.HttpHeaders; + import org.asynchttpclient.handler.ProgressAsyncHandler; import org.slf4j.Logger; import org.slf4j.LoggerFactory; /** - * An {@link AsyncHandler} augmented with an {@link #onCompleted(Response)} convenience method which gets called - * when the {@link Response} processing is finished. This class also implement the {@link ProgressAsyncHandler} callback, - * all doing nothing except returning {@link org.asynchttpclient.AsyncHandler.State#CONTINUE} + * An {@link AsyncHandler} augmented with an {@link #onCompleted(Response)} convenience method which gets called when the {@link Response} processing is finished. This class also + * implement the {@link ProgressAsyncHandler} callback, all doing nothing except returning {@link org.asynchttpclient.AsyncHandler.State#CONTINUE} * * @param Type of the value that will be returned by the associated {@link java.util.concurrent.Future} */ @@ -32,41 +33,37 @@ public abstract class AsyncCompletionHandler implements AsyncHandler, Prog private static final Logger LOGGER = LoggerFactory.getLogger(AsyncCompletionHandler.class); private final Response.ResponseBuilder builder = new Response.ResponseBuilder(); - /** - * {@inheritDoc} - */ - public State onBodyPartReceived(final HttpResponseBodyPart content) throws Exception { + @Override + public State onBodyPartReceived(HttpResponseBodyPart content) throws Exception { builder.accumulate(content); return State.CONTINUE; } - /** - * {@inheritDoc} - */ - public State onStatusReceived(final HttpResponseStatus status) throws Exception { + @Override + public State onStatusReceived(HttpResponseStatus status) throws Exception { builder.reset(); builder.accumulate(status); return State.CONTINUE; } - /** - * {@inheritDoc} - */ - public State onHeadersReceived(final HttpResponseHeaders headers) throws Exception { + @Override + public State onHeadersReceived(HttpHeaders headers) throws Exception { builder.accumulate(headers); return State.CONTINUE; } - /** - * {@inheritDoc} - */ + @Override + public State onTrailingHeadersReceived(HttpHeaders headers) throws Exception { + builder.accumulate(headers); + return State.CONTINUE; + } + + @Override public final T onCompleted() throws Exception { return onCompleted(builder.build()); } - /** - * {@inheritDoc} - */ + @Override public void onThrowable(Throwable t) { LOGGER.debug(t.getMessage(), t); } @@ -85,16 +82,17 @@ public void onThrowable(Throwable t) { * * @return a {@link org.asynchttpclient.AsyncHandler.State} telling to CONTINUE or ABORT the current processing. */ + @Override public State onHeadersWritten() { return State.CONTINUE; } /** - * Invoked when the content (a {@link java.io.File}, {@link String} or {@link java.io.InputStream} has been fully - * written on the I/O socket. + * Invoked when the content (a {@link java.io.File}, {@link String} or {@link java.io.InputStream} has been fully written on the I/O socket. * * @return a {@link org.asynchttpclient.AsyncHandler.State} telling to CONTINUE or ABORT the current processing. */ + @Override public State onContentWritten() { return State.CONTINUE; } @@ -102,11 +100,12 @@ public State onContentWritten() { /** * Invoked when the I/O operation associated with the {@link Request} body as been progressed. * - * @param amount The amount of bytes to transfer + * @param amount The amount of bytes to transfer * @param current The amount of bytes transferred - * @param total The total number of bytes transferred + * @param total The total number of bytes transferred * @return a {@link org.asynchttpclient.AsyncHandler.State} telling to CONTINUE or ABORT the current processing. */ + @Override public State onContentWriteProgress(long amount, long current, long total) { return State.CONTINUE; } diff --git a/client/src/main/java/org/asynchttpclient/AsyncHandler.java b/client/src/main/java/org/asynchttpclient/AsyncHandler.java index f1cad2bc8c..4cccbc1dac 100644 --- a/client/src/main/java/org/asynchttpclient/AsyncHandler.java +++ b/client/src/main/java/org/asynchttpclient/AsyncHandler.java @@ -15,6 +15,8 @@ */ package org.asynchttpclient; +import io.netty.handler.codec.http.HttpHeaders; + /** * An asynchronous handler or callback which gets invoked as soon as some data is available when @@ -89,14 +91,23 @@ enum State { State onStatusReceived(HttpResponseStatus responseStatus) throws Exception; /** - * Invoked as soon as the HTTP headers has been received. Can potentially be invoked more than once if a broken server - * sent trailing headers. + * Invoked as soon as the HTTP headers have been received. * * @param headers the HTTP headers. * @return a {@link State} telling to CONTINUE or ABORT the current processing. * @throws Exception if something wrong happens */ - State onHeadersReceived(HttpResponseHeaders headers) throws Exception; + State onHeadersReceived(HttpHeaders headers) throws Exception; + + /** + * Invoked when trailing headers have been received. + * @param headers + * @return + * @throws Exception + */ + default State onTrailingHeadersReceived(HttpHeaders headers) throws Exception { + return State.CONTINUE; + } /** * Invoked once the HTTP response processing is finished. diff --git a/client/src/main/java/org/asynchttpclient/HttpResponseHeaders.java b/client/src/main/java/org/asynchttpclient/HttpResponseHeaders.java deleted file mode 100644 index 271f05ba71..0000000000 --- a/client/src/main/java/org/asynchttpclient/HttpResponseHeaders.java +++ /dev/null @@ -1,44 +0,0 @@ -/* - * Copyright 2010 Ning, Inc. - * - * This program is licensed to you under the Apache License, version 2.0 - * (the "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - */ -package org.asynchttpclient; - -import io.netty.handler.codec.http.HttpHeaders; - -/** - * A class that represent the HTTP headers. - */ -public class HttpResponseHeaders { - - private final HttpHeaders headers; - private final boolean trailling; - - public HttpResponseHeaders(HttpHeaders headers) { - this(headers, false); - } - - public HttpResponseHeaders(HttpHeaders headers, boolean trailling) { - this.headers = headers; - this.trailling = trailling; - } - - public HttpHeaders getHeaders() { - return headers; - } - - public boolean isTrailling() { - return trailling; - } -} diff --git a/client/src/main/java/org/asynchttpclient/Response.java b/client/src/main/java/org/asynchttpclient/Response.java index b92083a89b..974ef14d65 100644 --- a/client/src/main/java/org/asynchttpclient/Response.java +++ b/client/src/main/java/org/asynchttpclient/Response.java @@ -172,15 +172,15 @@ public interface Response { class ResponseBuilder { private final List bodyParts = new ArrayList<>(1); private HttpResponseStatus status; - private HttpResponseHeaders headers; + private HttpHeaders headers; public ResponseBuilder accumulate(HttpResponseStatus status) { this.status = status; return this; } - public ResponseBuilder accumulate(HttpResponseHeaders headers) { - this.headers = this.headers == null ? headers : new HttpResponseHeaders(this.headers.getHeaders().add(headers.getHeaders()), true); + public ResponseBuilder accumulate(HttpHeaders headers) { + this.headers = this.headers == null ? headers : this.headers.add(headers); return this; } diff --git a/client/src/main/java/org/asynchttpclient/filter/FilterContext.java b/client/src/main/java/org/asynchttpclient/filter/FilterContext.java index a1da7b0a7f..74d64e2976 100644 --- a/client/src/main/java/org/asynchttpclient/filter/FilterContext.java +++ b/client/src/main/java/org/asynchttpclient/filter/FilterContext.java @@ -12,13 +12,14 @@ */ package org.asynchttpclient.filter; +import io.netty.handler.codec.http.HttpHeaders; + +import java.io.IOException; + import org.asynchttpclient.AsyncHandler; -import org.asynchttpclient.HttpResponseHeaders; import org.asynchttpclient.HttpResponseStatus; import org.asynchttpclient.Request; -import java.io.IOException; - /** * A {@link FilterContext} can be used to decorate {@link Request} and {@link AsyncHandler} from a list of {@link RequestFilter}. * {@link RequestFilter} gets executed before the HTTP request is made to the remote server. Once the response bytes are @@ -68,9 +69,9 @@ public HttpResponseStatus getResponseStatus() { } /** - * @return the response {@link HttpResponseHeaders} + * @return the response {@link HttpHeaders} */ - public HttpResponseHeaders getResponseHeaders() { + public HttpHeaders getResponseHeaders() { return b.headers; } @@ -94,7 +95,7 @@ public static class FilterContextBuilder { private HttpResponseStatus responseStatus = null; private boolean replayRequest = false; private IOException ioException = null; - private HttpResponseHeaders headers; + private HttpHeaders headers; public FilterContextBuilder() { } @@ -130,7 +131,7 @@ public FilterContextBuilder responseStatus(HttpResponseStatus responseStatus) return this; } - public FilterContextBuilder responseHeaders(HttpResponseHeaders headers) { + public FilterContextBuilder responseHeaders(HttpHeaders headers) { this.headers = headers; return this; } diff --git a/client/src/main/java/org/asynchttpclient/handler/BodyDeferringAsyncHandler.java b/client/src/main/java/org/asynchttpclient/handler/BodyDeferringAsyncHandler.java index 27c4c6e14a..afbf78d63c 100644 --- a/client/src/main/java/org/asynchttpclient/handler/BodyDeferringAsyncHandler.java +++ b/client/src/main/java/org/asynchttpclient/handler/BodyDeferringAsyncHandler.java @@ -12,6 +12,8 @@ */ package org.asynchttpclient.handler; +import io.netty.handler.codec.http.HttpHeaders; + import java.io.FilterInputStream; import java.io.IOException; import java.io.InputStream; @@ -23,7 +25,6 @@ import org.asynchttpclient.AsyncHandler; import org.asynchttpclient.HttpResponseBodyPart; -import org.asynchttpclient.HttpResponseHeaders; import org.asynchttpclient.HttpResponseStatus; import org.asynchttpclient.Response; @@ -98,6 +99,7 @@ public BodyDeferringAsyncHandler(final OutputStream os) { this.responseSet = false; } + @Override public void onThrowable(Throwable t) { this.throwable = t; // Counting down to handle error cases too. @@ -121,17 +123,26 @@ public void onThrowable(Throwable t) { } } + @Override public State onStatusReceived(HttpResponseStatus responseStatus) throws Exception { responseBuilder.reset(); responseBuilder.accumulate(responseStatus); return State.CONTINUE; } - public State onHeadersReceived(HttpResponseHeaders headers) throws Exception { + @Override + public State onHeadersReceived(HttpHeaders headers) throws Exception { + responseBuilder.accumulate(headers); + return State.CONTINUE; + } + + @Override + public State onTrailingHeadersReceived(HttpHeaders headers) throws Exception { responseBuilder.accumulate(headers); return State.CONTINUE; } + @Override public State onBodyPartReceived(HttpResponseBodyPart bodyPart) throws Exception { // body arrived, flush headers if (!responseSet) { @@ -152,6 +163,7 @@ protected void closeOut() throws IOException { } } + @Override public Response onCompleted() throws IOException { if (!responseSet) { @@ -242,6 +254,7 @@ public BodyDeferringInputStream(final Future future, final BodyDeferri * Closes the input stream, and "joins" (wait for complete execution * together with potential exception thrown) of the async request. */ + @Override public void close() throws IOException { // close super.close(); diff --git a/client/src/main/java/org/asynchttpclient/handler/TransferCompletionHandler.java b/client/src/main/java/org/asynchttpclient/handler/TransferCompletionHandler.java index 202e824818..ae0eeb9430 100644 --- a/client/src/main/java/org/asynchttpclient/handler/TransferCompletionHandler.java +++ b/client/src/main/java/org/asynchttpclient/handler/TransferCompletionHandler.java @@ -18,7 +18,6 @@ import org.asynchttpclient.AsyncCompletionHandlerBase; import org.asynchttpclient.HttpResponseBodyPart; -import org.asynchttpclient.HttpResponseHeaders; import org.asynchttpclient.Response; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -97,8 +96,14 @@ public void headers(HttpHeaders headers) { } @Override - public State onHeadersReceived(final HttpResponseHeaders headers) throws Exception { - fireOnHeaderReceived(headers.getHeaders()); + public State onHeadersReceived(final HttpHeaders headers) throws Exception { + fireOnHeaderReceived(headers); + return super.onHeadersReceived(headers); + } + + @Override + public State onTrailingHeadersReceived(HttpHeaders headers) throws Exception { + fireOnHeaderReceived(headers); return super.onHeadersReceived(headers); } diff --git a/client/src/main/java/org/asynchttpclient/handler/resumable/ResumableAsyncHandler.java b/client/src/main/java/org/asynchttpclient/handler/resumable/ResumableAsyncHandler.java index 5167a08108..1a5274fab8 100644 --- a/client/src/main/java/org/asynchttpclient/handler/resumable/ResumableAsyncHandler.java +++ b/client/src/main/java/org/asynchttpclient/handler/resumable/ResumableAsyncHandler.java @@ -13,6 +13,7 @@ package org.asynchttpclient.handler.resumable; import static io.netty.handler.codec.http.HttpHeaderNames.*; +import io.netty.handler.codec.http.HttpHeaders; import java.io.IOException; import java.nio.ByteBuffer; @@ -23,7 +24,6 @@ import org.asynchttpclient.AsyncHandler; import org.asynchttpclient.HttpResponseBodyPart; -import org.asynchttpclient.HttpResponseHeaders; import org.asynchttpclient.HttpResponseStatus; import org.asynchttpclient.Request; import org.asynchttpclient.RequestBuilder; @@ -100,11 +100,8 @@ public ResumableAsyncHandler(ResumableProcessor resumableProcessor, boolean accu this(0, resumableProcessor, null, accumulateBody); } - /** - * {@inheritDoc} - */ @Override - public AsyncHandler.State onStatusReceived(final HttpResponseStatus status) throws Exception { + public State onStatusReceived(final HttpResponseStatus status) throws Exception { responseBuilder.accumulate(status); if (status.getStatusCode() == 200 || status.getStatusCode() == 206) { url = status.getUri().toUrl(); @@ -119,9 +116,6 @@ public AsyncHandler.State onStatusReceived(final HttpResponseStatus status) thro return AsyncHandler.State.CONTINUE; } - /** - * {@inheritDoc} - */ @Override public void onThrowable(Throwable t) { if (decoratedAsyncHandler != null) { @@ -131,11 +125,8 @@ public void onThrowable(Throwable t) { } } - /** - * {@inheritDoc} - */ @Override - public AsyncHandler.State onBodyPartReceived(HttpResponseBodyPart bodyPart) throws Exception { + public State onBodyPartReceived(HttpResponseBodyPart bodyPart) throws Exception { if (accumulateBody) { responseBuilder.accumulate(bodyPart); @@ -158,9 +149,6 @@ public AsyncHandler.State onBodyPartReceived(HttpResponseBodyPart bodyPart) thro return state; } - /** - * {@inheritDoc} - */ @Override public Response onCompleted() throws Exception { resumableProcessor.remove(url); @@ -173,13 +161,10 @@ public Response onCompleted() throws Exception { return responseBuilder.build(); } - /** - * {@inheritDoc} - */ @Override - public AsyncHandler.State onHeadersReceived(HttpResponseHeaders headers) throws Exception { + public State onHeadersReceived(HttpHeaders headers) throws Exception { responseBuilder.accumulate(headers); - String contentLengthHeader = headers.getHeaders().get(CONTENT_LENGTH); + String contentLengthHeader = headers.get(CONTENT_LENGTH); if (contentLengthHeader != null) { if (Long.parseLong(contentLengthHeader) == -1L) { return AsyncHandler.State.ABORT; @@ -189,7 +174,13 @@ public AsyncHandler.State onHeadersReceived(HttpResponseHeaders headers) throws if (decoratedAsyncHandler != null) { return decoratedAsyncHandler.onHeadersReceived(headers); } - return AsyncHandler.State.CONTINUE; + return State.CONTINUE; + } + + @Override + public State onTrailingHeadersReceived(HttpHeaders headers) throws Exception { + responseBuilder.accumulate(headers); + return State.CONTINUE; } /** @@ -315,6 +306,5 @@ public void onAllBytesReceived() { public long length() { return length; } - } } diff --git a/client/src/main/java/org/asynchttpclient/netty/NettyResponse.java b/client/src/main/java/org/asynchttpclient/netty/NettyResponse.java index ec3a7fd881..ff45fb681b 100755 --- a/client/src/main/java/org/asynchttpclient/netty/NettyResponse.java +++ b/client/src/main/java/org/asynchttpclient/netty/NettyResponse.java @@ -32,7 +32,6 @@ import java.util.Map; import org.asynchttpclient.HttpResponseBodyPart; -import org.asynchttpclient.HttpResponseHeaders; import org.asynchttpclient.HttpResponseStatus; import org.asynchttpclient.Response; import org.asynchttpclient.uri.Uri; @@ -43,12 +42,12 @@ public class NettyResponse implements Response { private final List bodyParts; - private final HttpResponseHeaders headers; + private final HttpHeaders headers; private final HttpResponseStatus status; private List cookies; public NettyResponse(HttpResponseStatus status,// - HttpResponseHeaders headers,// + HttpHeaders headers,// List bodyParts) { this.bodyParts = bodyParts; this.headers = headers; @@ -57,10 +56,10 @@ public NettyResponse(HttpResponseStatus status,// private List buildCookies() { - List setCookieHeaders = headers.getHeaders().getAll(SET_COOKIE2); + List setCookieHeaders = headers.getAll(SET_COOKIE2); if (!isNonEmpty(setCookieHeaders)) { - setCookieHeaders = headers.getHeaders().getAll(SET_COOKIE); + setCookieHeaders = headers.getAll(SET_COOKIE); } if (isNonEmpty(setCookieHeaders)) { @@ -118,7 +117,7 @@ public final List getHeaders(CharSequence name) { @Override public final HttpHeaders getHeaders() { - return headers != null ? headers.getHeaders() : EmptyHttpHeaders.INSTANCE; + return headers != null ? headers : EmptyHttpHeaders.INSTANCE; } @Override @@ -156,7 +155,7 @@ public boolean hasResponseStatus() { @Override public boolean hasResponseHeaders() { - return headers != null && !headers.getHeaders().isEmpty(); + return headers != null && !headers.isEmpty(); } @Override diff --git a/client/src/main/java/org/asynchttpclient/netty/handler/HttpHandler.java b/client/src/main/java/org/asynchttpclient/netty/handler/HttpHandler.java index 510f956c6b..98a15665c2 100755 --- a/client/src/main/java/org/asynchttpclient/netty/handler/HttpHandler.java +++ b/client/src/main/java/org/asynchttpclient/netty/handler/HttpHandler.java @@ -29,7 +29,6 @@ import org.asynchttpclient.AsyncHandler.State; import org.asynchttpclient.AsyncHttpClientConfig; import org.asynchttpclient.HttpResponseBodyPart; -import org.asynchttpclient.HttpResponseHeaders; import org.asynchttpclient.handler.StreamedAsyncHandler; import org.asynchttpclient.netty.NettyResponseFuture; import org.asynchttpclient.netty.NettyResponseStatus; @@ -52,8 +51,8 @@ private boolean abortAfterHandlingStatus(// private boolean abortAfterHandlingHeaders(// AsyncHandler handler,// - HttpResponseHeaders responseHeaders) throws Exception { - return !responseHeaders.getHeaders().isEmpty() && handler.onHeadersReceived(responseHeaders) == State.ABORT; + HttpHeaders responseHeaders) throws Exception { + return !responseHeaders.isEmpty() && handler.onHeadersReceived(responseHeaders) == State.ABORT; } private boolean abortAfterHandlingReactiveStreams(// @@ -80,7 +79,7 @@ private void handleHttpResponse(final HttpResponse response, final Channel chann future.setKeepAlive(config.getKeepAliveStrategy().keepAlive(future.getTargetRequest(), httpRequest, response)); NettyResponseStatus status = new NettyResponseStatus(future.getUri(), response, channel); - HttpResponseHeaders responseHeaders = new HttpResponseHeaders(response.headers()); + HttpHeaders responseHeaders = response.headers(); if (!interceptors.exitAfterIntercept(channel, future, handler, response, status, responseHeaders)) { boolean abort = abortAfterHandlingStatus(handler, status) || // @@ -106,7 +105,7 @@ private void handleChunk(HttpContent chunk,// LastHttpContent lastChunk = (LastHttpContent) chunk; HttpHeaders trailingHeaders = lastChunk.trailingHeaders(); if (!trailingHeaders.isEmpty()) { - abort = handler.onHeadersReceived(new HttpResponseHeaders(trailingHeaders, true)) == State.ABORT; + abort = handler.onTrailingHeadersReceived(trailingHeaders) == State.ABORT; } } diff --git a/client/src/main/java/org/asynchttpclient/netty/handler/WebSocketHandler.java b/client/src/main/java/org/asynchttpclient/netty/handler/WebSocketHandler.java index c469943b9e..4c5f1c22f1 100755 --- a/client/src/main/java/org/asynchttpclient/netty/handler/WebSocketHandler.java +++ b/client/src/main/java/org/asynchttpclient/netty/handler/WebSocketHandler.java @@ -19,6 +19,7 @@ import io.netty.channel.Channel; import io.netty.channel.ChannelHandler.Sharable; import io.netty.handler.codec.http.HttpHeaderValues; +import io.netty.handler.codec.http.HttpHeaders; import io.netty.handler.codec.http.HttpRequest; import io.netty.handler.codec.http.HttpResponse; import io.netty.handler.codec.http.LastHttpContent; @@ -28,7 +29,6 @@ import org.asynchttpclient.AsyncHandler.State; import org.asynchttpclient.AsyncHttpClientConfig; -import org.asynchttpclient.HttpResponseHeaders; import org.asynchttpclient.HttpResponseStatus; import org.asynchttpclient.netty.NettyResponseFuture; import org.asynchttpclient.netty.NettyResponseStatus; @@ -47,7 +47,7 @@ public WebSocketHandler(AsyncHttpClientConfig config,// super(config, channelManager, requestSender); } - private void upgrade(Channel channel, NettyResponseFuture future, WebSocketUpgradeHandler handler, HttpResponse response, HttpResponseHeaders responseHeaders) + private void upgrade(Channel channel, NettyResponseFuture future, WebSocketUpgradeHandler handler, HttpResponse response, HttpHeaders responseHeaders) throws Exception { boolean validStatus = response.status().equals(SWITCHING_PROTOCOLS); boolean validUpgrade = response.headers().get(UPGRADE) != null; @@ -70,7 +70,7 @@ private void upgrade(Channel channel, NettyResponseFuture future, WebSocketUp // if it comes in the same frame as the HTTP Upgrade response Channels.setAttribute(channel, future); - handler.setWebSocket(new NettyWebSocket(channel, responseHeaders.getHeaders())); + handler.setWebSocket(new NettyWebSocket(channel, responseHeaders)); channelManager.upgradePipelineForWebSockets(channel.pipeline()); // We don't need to synchronize as replacing the "ws-decoder" will @@ -111,7 +111,7 @@ public void handleRead(Channel channel, NettyResponseFuture future, Object e) WebSocketUpgradeHandler handler = getWebSocketUpgradeHandler(future); HttpResponseStatus status = new NettyResponseStatus(future.getUri(), response, channel); - HttpResponseHeaders responseHeaders = new HttpResponseHeaders(response.headers()); + HttpHeaders responseHeaders = response.headers(); if (!interceptors.exitAfterIntercept(channel, future, handler, response, status, responseHeaders)) { switch (handler.onStatusReceived(status)) { diff --git a/client/src/main/java/org/asynchttpclient/netty/handler/intercept/Interceptors.java b/client/src/main/java/org/asynchttpclient/netty/handler/intercept/Interceptors.java index 4633af0c40..ce144d38b4 100644 --- a/client/src/main/java/org/asynchttpclient/netty/handler/intercept/Interceptors.java +++ b/client/src/main/java/org/asynchttpclient/netty/handler/intercept/Interceptors.java @@ -15,13 +15,13 @@ import static org.asynchttpclient.util.HttpConstants.ResponseStatusCodes.*; import io.netty.channel.Channel; +import io.netty.handler.codec.http.HttpHeaders; import io.netty.handler.codec.http.HttpMethod; import io.netty.handler.codec.http.HttpRequest; import io.netty.handler.codec.http.HttpResponse; import org.asynchttpclient.AsyncHandler; import org.asynchttpclient.AsyncHttpClientConfig; -import org.asynchttpclient.HttpResponseHeaders; import org.asynchttpclient.HttpResponseStatus; import org.asynchttpclient.Realm; import org.asynchttpclient.Request; @@ -61,7 +61,7 @@ public boolean exitAfterIntercept(// AsyncHandler handler,// HttpResponse response,// HttpResponseStatus status,// - HttpResponseHeaders responseHeaders) throws Exception { + HttpHeaders responseHeaders) throws Exception { HttpRequest httpRequest = future.getNettyRequest().getHttpRequest(); ProxyServer proxyServer = future.getProxyServer(); diff --git a/client/src/main/java/org/asynchttpclient/netty/handler/intercept/ResponseFiltersInterceptor.java b/client/src/main/java/org/asynchttpclient/netty/handler/intercept/ResponseFiltersInterceptor.java index bd78f35b9c..8d449476a8 100644 --- a/client/src/main/java/org/asynchttpclient/netty/handler/intercept/ResponseFiltersInterceptor.java +++ b/client/src/main/java/org/asynchttpclient/netty/handler/intercept/ResponseFiltersInterceptor.java @@ -15,10 +15,10 @@ import static org.asynchttpclient.util.Assertions.assertNotNull; import io.netty.channel.Channel; +import io.netty.handler.codec.http.HttpHeaders; import org.asynchttpclient.AsyncHandler; import org.asynchttpclient.AsyncHttpClientConfig; -import org.asynchttpclient.HttpResponseHeaders; import org.asynchttpclient.HttpResponseStatus; import org.asynchttpclient.filter.FilterContext; import org.asynchttpclient.filter.FilterException; @@ -42,7 +42,7 @@ public boolean exitAfterProcessingFilters(// NettyResponseFuture future,// AsyncHandler handler, // HttpResponseStatus status,// - HttpResponseHeaders responseHeaders) { + HttpHeaders responseHeaders) { FilterContext fc = new FilterContext.FilterContextBuilder().asyncHandler(handler).request(future.getCurrentRequest()).responseStatus(status) .responseHeaders(responseHeaders).build(); diff --git a/client/src/main/java/org/asynchttpclient/webdav/WebDavCompletionHandlerBase.java b/client/src/main/java/org/asynchttpclient/webdav/WebDavCompletionHandlerBase.java index 9e0e26c85e..5511509338 100644 --- a/client/src/main/java/org/asynchttpclient/webdav/WebDavCompletionHandlerBase.java +++ b/client/src/main/java/org/asynchttpclient/webdav/WebDavCompletionHandlerBase.java @@ -13,6 +13,8 @@ package org.asynchttpclient.webdav; +import io.netty.handler.codec.http.HttpHeaders; + import java.io.IOException; import java.io.InputStream; import java.net.SocketAddress; @@ -26,7 +28,6 @@ import org.asynchttpclient.AsyncCompletionHandlerBase; import org.asynchttpclient.AsyncHandler; import org.asynchttpclient.HttpResponseBodyPart; -import org.asynchttpclient.HttpResponseHeaders; import org.asynchttpclient.HttpResponseStatus; import org.asynchttpclient.netty.NettyResponse; import org.slf4j.Logger; @@ -46,7 +47,7 @@ public abstract class WebDavCompletionHandlerBase implements AsyncHandler private final Logger logger = LoggerFactory.getLogger(AsyncCompletionHandlerBase.class); private HttpResponseStatus status; - private HttpResponseHeaders headers; + private HttpHeaders headers; private final List bodyParts = Collections.synchronizedList(new ArrayList<>()); /** @@ -71,7 +72,7 @@ public final State onStatusReceived(final HttpResponseStatus status) throws Exce * {@inheritDoc} */ @Override - public final State onHeadersReceived(final HttpResponseHeaders headers) throws Exception { + public final State onHeadersReceived(final HttpHeaders headers) throws Exception { this.headers = headers; return State.CONTINUE; } diff --git a/client/src/main/java/org/asynchttpclient/ws/WebSocketUpgradeHandler.java b/client/src/main/java/org/asynchttpclient/ws/WebSocketUpgradeHandler.java index 09de4f6dfe..39f1b40b2f 100644 --- a/client/src/main/java/org/asynchttpclient/ws/WebSocketUpgradeHandler.java +++ b/client/src/main/java/org/asynchttpclient/ws/WebSocketUpgradeHandler.java @@ -13,12 +13,13 @@ */ package org.asynchttpclient.ws; +import io.netty.handler.codec.http.HttpHeaders; + import java.util.ArrayList; import java.util.List; import org.asynchttpclient.AsyncHandler; import org.asynchttpclient.HttpResponseBodyPart; -import org.asynchttpclient.HttpResponseHeaders; import org.asynchttpclient.HttpResponseStatus; import org.asynchttpclient.netty.ws.NettyWebSocket; @@ -42,7 +43,7 @@ public final State onStatusReceived(HttpResponseStatus responseStatus) throws Ex } @Override - public final State onHeadersReceived(HttpResponseHeaders headers) throws Exception { + public final State onHeadersReceived(HttpHeaders headers) throws Exception { return State.CONTINUE; } diff --git a/client/src/test/java/org/asynchttpclient/AbstractBasicTest.java b/client/src/test/java/org/asynchttpclient/AbstractBasicTest.java index 33d66a685c..6333153121 100644 --- a/client/src/test/java/org/asynchttpclient/AbstractBasicTest.java +++ b/client/src/test/java/org/asynchttpclient/AbstractBasicTest.java @@ -17,6 +17,7 @@ import static org.asynchttpclient.test.TestUtils.addHttpConnector; import static org.testng.Assert.fail; +import io.netty.handler.codec.http.HttpHeaders; import org.asynchttpclient.test.EchoHandler; import org.eclipse.jetty.server.Server; @@ -92,17 +93,17 @@ public void onThrowable(Throwable t) { } @Override - public State onBodyPartReceived(final HttpResponseBodyPart content) throws Exception { + public State onBodyPartReceived(HttpResponseBodyPart content) throws Exception { return State.CONTINUE; } @Override - public State onStatusReceived(final HttpResponseStatus responseStatus) throws Exception { + public State onStatusReceived(HttpResponseStatus responseStatus) throws Exception { return State.CONTINUE; } @Override - public State onHeadersReceived(final HttpResponseHeaders headers) throws Exception { + public State onHeadersReceived(HttpHeaders headers) throws Exception { return State.CONTINUE; } diff --git a/client/src/test/java/org/asynchttpclient/AsyncStreamHandlerTest.java b/client/src/test/java/org/asynchttpclient/AsyncStreamHandlerTest.java index 68b964cc48..fec5a3e6ed 100644 --- a/client/src/test/java/org/asynchttpclient/AsyncStreamHandlerTest.java +++ b/client/src/test/java/org/asynchttpclient/AsyncStreamHandlerTest.java @@ -16,6 +16,7 @@ package org.asynchttpclient; import static io.netty.handler.codec.http.HttpHeaderNames.*; +import static io.netty.util.internal.ThrowableUtil.unknownStackTrace; import static java.nio.charset.StandardCharsets.US_ASCII; import static org.asynchttpclient.Dsl.config; import static org.asynchttpclient.test.TestUtils.*; @@ -23,8 +24,6 @@ import io.netty.handler.codec.http.HttpHeaderValues; import io.netty.handler.codec.http.HttpHeaders; -import static io.netty.util.internal.ThrowableUtil.*; - import java.util.Arrays; import java.util.concurrent.CountDownLatch; import java.util.concurrent.Future; @@ -70,8 +69,8 @@ public void getWithOnHeadersReceivedAbort() throws Throwable { client.prepareGet(getTargetUrl()).execute(new AsyncHandlerAdapter() { @Override - public State onHeadersReceived(HttpResponseHeaders content) throws Exception { - assertContentTypesEquals(content.getHeaders().get(CONTENT_TYPE), TEXT_HTML_CONTENT_TYPE_WITH_UTF_8_CHARSET); + public State onHeadersReceived(HttpHeaders headers) throws Exception { + assertContentTypesEquals(headers.get(CONTENT_TYPE), TEXT_HTML_CONTENT_TYPE_WITH_UTF_8_CHARSET); return State.ABORT; } }).get(5, TimeUnit.SECONDS); @@ -94,8 +93,8 @@ public void asyncStreamPOSTTest() throws Throwable { private StringBuilder builder = new StringBuilder(); @Override - public State onHeadersReceived(HttpResponseHeaders content) throws Exception { - assertContentTypesEquals(content.getHeaders().get(CONTENT_TYPE), TEXT_HTML_CONTENT_TYPE_WITH_UTF_8_CHARSET); + public State onHeadersReceived(HttpHeaders headers) throws Exception { + assertContentTypesEquals(headers.get(CONTENT_TYPE), TEXT_HTML_CONTENT_TYPE_WITH_UTF_8_CHARSET); return State.CONTINUE; } @@ -134,9 +133,9 @@ public void asyncStreamInterruptTest() throws Throwable { .execute(new AsyncHandlerAdapter() { @Override - public State onHeadersReceived(HttpResponseHeaders content) throws Exception { + public State onHeadersReceived(HttpHeaders headers) throws Exception { onHeadersReceived.set(true); - assertContentTypesEquals(content.getHeaders().get(CONTENT_TYPE), TEXT_HTML_CONTENT_TYPE_WITH_UTF_8_CHARSET); + assertContentTypesEquals(headers.get(CONTENT_TYPE), TEXT_HTML_CONTENT_TYPE_WITH_UTF_8_CHARSET); return State.ABORT; } @@ -176,8 +175,8 @@ public void asyncStreamFutureTest() throws Throwable { private StringBuilder builder = new StringBuilder(); @Override - public State onHeadersReceived(HttpResponseHeaders content) throws Exception { - assertContentTypesEquals(content.getHeaders().get(CONTENT_TYPE), TEXT_HTML_CONTENT_TYPE_WITH_UTF_8_CHARSET); + public State onHeadersReceived(HttpHeaders headers) throws Exception { + assertContentTypesEquals(headers.get(CONTENT_TYPE), TEXT_HTML_CONTENT_TYPE_WITH_UTF_8_CHARSET); onHeadersReceived.set(true); return State.CONTINUE; } @@ -218,7 +217,7 @@ public void asyncStreamThrowableRefusedTest() throws Throwable { client.prepareGet(getTargetUrl()).execute(new AsyncHandlerAdapter() { @Override - public State onHeadersReceived(HttpResponseHeaders content) throws Exception { + public State onHeadersReceived(HttpHeaders headers) throws Exception { throw unknownStackTrace(new RuntimeException("FOO"), AsyncStreamHandlerTest.class, "asyncStreamThrowableRefusedTest"); } @@ -259,8 +258,8 @@ public void asyncStreamReusePOSTTest() throws Throwable { private StringBuilder builder = new StringBuilder(); @Override - public State onHeadersReceived(HttpResponseHeaders content) throws Exception { - responseHeaders.set(content.getHeaders()); + public State onHeadersReceived(HttpHeaders headers) throws Exception { + responseHeaders.set(headers); return State.CONTINUE; } @@ -292,8 +291,8 @@ public String onCompleted() throws Exception { private StringBuilder builder = new StringBuilder(); @Override - public State onHeadersReceived(HttpResponseHeaders content) throws Exception { - responseHeaders.set(content.getHeaders()); + public State onHeadersReceived(HttpHeaders headers) throws Exception { + responseHeaders.set(headers); return State.CONTINUE; } @@ -381,7 +380,7 @@ public State onStatusReceived(HttpResponseStatus responseStatus) throws Exceptio } @Override - public State onHeadersReceived(HttpResponseHeaders headers) throws Exception { + public State onHeadersReceived(HttpHeaders headers) throws Exception { whatCalled[OTHER] = true; latch.countDown(); return State.ABORT; @@ -427,8 +426,8 @@ public void asyncOptionsTest() throws Throwable { Future f = client.prepareOptions("http://www.apache.org/").execute(new AsyncHandlerAdapter() { @Override - public State onHeadersReceived(HttpResponseHeaders content) throws Exception { - responseHeaders.set(content.getHeaders()); + public State onHeadersReceived(HttpHeaders headers) throws Exception { + responseHeaders.set(headers); return State.ABORT; } @@ -461,8 +460,8 @@ public void closeConnectionTest() throws Throwable { private Response.ResponseBuilder builder = new Response.ResponseBuilder(); - public State onHeadersReceived(HttpResponseHeaders content) throws Exception { - builder.accumulate(content); + public State onHeadersReceived(HttpHeaders headers) throws Exception { + builder.accumulate(headers); return State.CONTINUE; } diff --git a/client/src/test/java/org/asynchttpclient/AsyncStreamLifecycleTest.java b/client/src/test/java/org/asynchttpclient/AsyncStreamLifecycleTest.java index 9b155e33c4..d3c27d5649 100644 --- a/client/src/test/java/org/asynchttpclient/AsyncStreamLifecycleTest.java +++ b/client/src/test/java/org/asynchttpclient/AsyncStreamLifecycleTest.java @@ -15,8 +15,9 @@ */ package org.asynchttpclient; -import static org.asynchttpclient.Dsl.*; +import static org.asynchttpclient.Dsl.asyncHttpClient; import static org.testng.Assert.*; +import io.netty.handler.codec.http.HttpHeaders; import java.io.IOException; import java.io.PrintWriter; @@ -121,7 +122,7 @@ public State onStatusReceived(HttpResponseStatus e) throws Exception { return State.CONTINUE; } - public State onHeadersReceived(HttpResponseHeaders e) throws Exception { + public State onHeadersReceived(HttpHeaders e) throws Exception { if (headers.incrementAndGet() == 2) { throw new Exception("Analyze this."); } diff --git a/client/src/test/java/org/asynchttpclient/BasicAuthTest.java b/client/src/test/java/org/asynchttpclient/BasicAuthTest.java index 063a018360..4e3acb6a35 100644 --- a/client/src/test/java/org/asynchttpclient/BasicAuthTest.java +++ b/client/src/test/java/org/asynchttpclient/BasicAuthTest.java @@ -20,6 +20,7 @@ import static org.asynchttpclient.Dsl.*; import static org.asynchttpclient.test.TestUtils.*; import static org.testng.Assert.*; +import io.netty.handler.codec.http.HttpHeaders; import java.io.ByteArrayInputStream; import java.io.IOException; @@ -217,7 +218,7 @@ public State onStatusReceived(HttpResponseStatus responseStatus) throws Exceptio return State.CONTINUE; } - public State onHeadersReceived(HttpResponseHeaders headers) throws Exception { + public State onHeadersReceived(HttpHeaders headers) throws Exception { return State.CONTINUE; } diff --git a/client/src/test/java/org/asynchttpclient/FollowingThreadTest.java b/client/src/test/java/org/asynchttpclient/FollowingThreadTest.java index 521c5ad77b..f36abf6cee 100644 --- a/client/src/test/java/org/asynchttpclient/FollowingThreadTest.java +++ b/client/src/test/java/org/asynchttpclient/FollowingThreadTest.java @@ -16,6 +16,7 @@ package org.asynchttpclient; import static org.asynchttpclient.Dsl.*; +import io.netty.handler.codec.http.HttpHeaders; import java.io.IOException; import java.util.concurrent.CountDownLatch; @@ -64,7 +65,7 @@ public State onStatusReceived(HttpResponseStatus responseStatus) throws Exceptio return State.CONTINUE; } - public State onHeadersReceived(HttpResponseHeaders headers) throws Exception { + public State onHeadersReceived(HttpHeaders headers) throws Exception { return State.CONTINUE; } diff --git a/client/src/test/java/org/asynchttpclient/MultipleHeaderTest.java b/client/src/test/java/org/asynchttpclient/MultipleHeaderTest.java index e5af4d9e33..273309faf1 100644 --- a/client/src/test/java/org/asynchttpclient/MultipleHeaderTest.java +++ b/client/src/test/java/org/asynchttpclient/MultipleHeaderTest.java @@ -15,6 +15,7 @@ import static io.netty.handler.codec.http.HttpHeaderNames.CONTENT_LENGTH; import static org.asynchttpclient.Dsl.*; import static org.testng.Assert.*; +import io.netty.handler.codec.http.HttpHeaders; import java.io.BufferedReader; import java.io.IOException; @@ -108,9 +109,9 @@ public State onStatusReceived(HttpResponseStatus objectHttpResponseStatus) throw return State.CONTINUE; } - public State onHeadersReceived(HttpResponseHeaders response) throws Exception { + public State onHeadersReceived(HttpHeaders response) throws Exception { int i = 0; - for (String header : response.getHeaders().getAll("X-Forwarded-For")) { + for (String header : response.getAll("X-Forwarded-For")) { xffHeaders[i++] = header; } latch.countDown(); @@ -157,10 +158,10 @@ public State onStatusReceived(HttpResponseStatus objectHttpResponseStatus) throw return State.CONTINUE; } - public State onHeadersReceived(HttpResponseHeaders response) throws Exception { + public State onHeadersReceived(HttpHeaders response) throws Exception { try { int i = 0; - for (String header : response.getHeaders().getAll(CONTENT_LENGTH)) { + for (String header : response.getAll(CONTENT_LENGTH)) { clHeaders[i++] = header; } } finally { diff --git a/client/src/test/java/org/asynchttpclient/PostRedirectGetTest.java b/client/src/test/java/org/asynchttpclient/PostRedirectGetTest.java index bc414b1405..4762556fbe 100644 --- a/client/src/test/java/org/asynchttpclient/PostRedirectGetTest.java +++ b/client/src/test/java/org/asynchttpclient/PostRedirectGetTest.java @@ -74,7 +74,7 @@ private void doTestNegative(final int status, boolean strict) throws Exception { public FilterContext filter(FilterContext ctx) throws FilterException { // pass on the x-expect-get and remove the x-redirect // headers if found in the response - ctx.getResponseHeaders().getHeaders().get("x-expect-post"); + ctx.getResponseHeaders().get("x-expect-post"); ctx.getRequest().getHeaders().add("x-expect-post", "true"); ctx.getRequest().getHeaders().remove("x-redirect"); return ctx; @@ -109,7 +109,7 @@ private void doTestPositive(final int status) throws Exception { public FilterContext filter(FilterContext ctx) throws FilterException { // pass on the x-expect-get and remove the x-redirect // headers if found in the response - ctx.getResponseHeaders().getHeaders().get("x-expect-get"); + ctx.getResponseHeaders().get("x-expect-get"); ctx.getRequest().getHeaders().add("x-expect-get", "true"); ctx.getRequest().getHeaders().remove("x-redirect"); return ctx; diff --git a/client/src/test/java/org/asynchttpclient/RC1KTest.java b/client/src/test/java/org/asynchttpclient/RC1KTest.java index 848b37e97a..fd2b043b4a 100644 --- a/client/src/test/java/org/asynchttpclient/RC1KTest.java +++ b/client/src/test/java/org/asynchttpclient/RC1KTest.java @@ -16,8 +16,9 @@ package org.asynchttpclient; import static org.asynchttpclient.Dsl.*; -import static org.asynchttpclient.test.TestUtils.*; +import static org.asynchttpclient.test.TestUtils.addHttpConnector; import static org.testng.Assert.*; +import io.netty.handler.codec.http.HttpHeaders; import java.io.IOException; import java.util.ArrayList; @@ -127,8 +128,8 @@ public State onStatusReceived(HttpResponseStatus event) throws Exception { return State.CONTINUE; } - public State onHeadersReceived(HttpResponseHeaders event) throws Exception { - assertEquals(event.getHeaders().get(ARG_HEADER), arg); + public State onHeadersReceived(HttpHeaders event) throws Exception { + assertEquals(event.get(ARG_HEADER), arg); return State.CONTINUE; } diff --git a/client/src/test/java/org/asynchttpclient/RemoteSiteTest.java b/client/src/test/java/org/asynchttpclient/RemoteSiteTest.java index 06d93f51dd..81b2bf2c7a 100644 --- a/client/src/test/java/org/asynchttpclient/RemoteSiteTest.java +++ b/client/src/test/java/org/asynchttpclient/RemoteSiteTest.java @@ -19,6 +19,7 @@ import static java.nio.charset.StandardCharsets.UTF_8; import static org.asynchttpclient.Dsl.*; import static org.testng.Assert.*; +import io.netty.handler.codec.http.HttpHeaders; import io.netty.handler.codec.http.cookie.Cookie; import io.netty.handler.codec.http.cookie.DefaultCookie; @@ -208,7 +209,7 @@ public State onStatusReceived(HttpResponseStatus responseStatus) throws Exceptio return State.CONTINUE; } - public State onHeadersReceived(HttpResponseHeaders headers) throws Exception { + public State onHeadersReceived(HttpHeaders headers) throws Exception { builder.accumulate(headers); return State.CONTINUE; } diff --git a/client/src/test/java/org/asynchttpclient/filter/FilterTest.java b/client/src/test/java/org/asynchttpclient/filter/FilterTest.java index a8ff8f354b..becf9d249c 100644 --- a/client/src/test/java/org/asynchttpclient/filter/FilterTest.java +++ b/client/src/test/java/org/asynchttpclient/filter/FilterTest.java @@ -165,7 +165,7 @@ public void replayHeaderResponseFilterTest() throws Exception { final AtomicBoolean replay = new AtomicBoolean(true); ResponseFilter responseFilter = new ResponseFilter() { public FilterContext filter(FilterContext ctx) throws FilterException { - if (ctx.getResponseHeaders() != null && ctx.getResponseHeaders().getHeaders().get("Ping").equals("Pong") && replay.getAndSet(false)) { + if (ctx.getResponseHeaders() != null && ctx.getResponseHeaders().get("Ping").equals("Pong") && replay.getAndSet(false)) { Request request = new RequestBuilder(ctx.getRequest()).addHeader("Ping", "Pong").build(); return new FilterContext.FilterContextBuilder().asyncHandler(ctx.getAsyncHandler()).request(request).replayRequest(true).build(); } diff --git a/client/src/test/java/org/asynchttpclient/handler/resumable/ResumableAsyncHandlerTest.java b/client/src/test/java/org/asynchttpclient/handler/resumable/ResumableAsyncHandlerTest.java index 8441844551..ff762a72fe 100644 --- a/client/src/test/java/org/asynchttpclient/handler/resumable/ResumableAsyncHandlerTest.java +++ b/client/src/test/java/org/asynchttpclient/handler/resumable/ResumableAsyncHandlerTest.java @@ -27,7 +27,6 @@ import org.asynchttpclient.AsyncHandler; import org.asynchttpclient.AsyncHandler.State; import org.asynchttpclient.HttpResponseBodyPart; -import org.asynchttpclient.HttpResponseHeaders; import org.asynchttpclient.HttpResponseStatus; import org.asynchttpclient.Request; import org.asynchttpclient.Response; @@ -167,23 +166,21 @@ public void testOnBodyPartReceivedWithDecoratedAsyncHandler() throws Exception { public void testOnHeadersReceived() throws Exception { ResumableAsyncHandler handler = new ResumableAsyncHandler(); HttpHeaders responseHeaders = new DefaultHttpHeaders(); - HttpResponseHeaders headers = new HttpResponseHeaders(responseHeaders); - State status = handler.onHeadersReceived(headers); + State status = handler.onHeadersReceived(responseHeaders); assertEquals(status, AsyncHandler.State.CONTINUE, "State should be CONTINUE for a successful onHeadersReceived"); } @Test public void testOnHeadersReceivedWithDecoratedAsyncHandler() throws Exception { HttpHeaders responseHeaders = new DefaultHttpHeaders(); - HttpResponseHeaders headers = new HttpResponseHeaders(responseHeaders); @SuppressWarnings("unchecked") AsyncHandler decoratedAsyncHandler = mock(AsyncHandler.class); State mockState = mock(State.class); - when(decoratedAsyncHandler.onHeadersReceived(headers)).thenReturn(mockState); + when(decoratedAsyncHandler.onHeadersReceived(responseHeaders)).thenReturn(mockState); ResumableAsyncHandler handler = new ResumableAsyncHandler(decoratedAsyncHandler); - State status = handler.onHeadersReceived(headers); + State status = handler.onHeadersReceived(responseHeaders); assertEquals(status, mockState, "State should be equal to the state returned from decoratedAsyncHandler"); } @@ -192,8 +189,7 @@ public void testOnHeadersReceivedContentLengthMinus() throws Exception { ResumableAsyncHandler handler = new ResumableAsyncHandler(); HttpHeaders responseHeaders = new DefaultHttpHeaders(); responseHeaders.add(CONTENT_LENGTH, -1); - HttpResponseHeaders headers = new HttpResponseHeaders(responseHeaders); - State status = handler.onHeadersReceived(headers); + State status = handler.onHeadersReceived(responseHeaders); assertEquals(status, AsyncHandler.State.ABORT, "State should be ABORT for content length -1"); } } diff --git a/client/src/test/java/org/asynchttpclient/netty/NettyAsyncResponseTest.java b/client/src/test/java/org/asynchttpclient/netty/NettyAsyncResponseTest.java index 176dbee17b..12bec34498 100644 --- a/client/src/test/java/org/asynchttpclient/netty/NettyAsyncResponseTest.java +++ b/client/src/test/java/org/asynchttpclient/netty/NettyAsyncResponseTest.java @@ -15,6 +15,7 @@ import static io.netty.handler.codec.http.HttpHeaderNames.SET_COOKIE; import static org.testng.Assert.*; import io.netty.handler.codec.http.DefaultHttpHeaders; +import io.netty.handler.codec.http.HttpHeaders; import io.netty.handler.codec.http.cookie.Cookie; import java.text.SimpleDateFormat; @@ -23,7 +24,6 @@ import java.util.Locale; import java.util.TimeZone; -import org.asynchttpclient.HttpResponseHeaders; import org.testng.annotations.Test; public class NettyAsyncResponseTest { @@ -37,7 +37,7 @@ public void testCookieParseExpires() { Date date = new Date(System.currentTimeMillis() + 60000); final String cookieDef = String.format("efmembercheck=true; expires=%s; path=/; domain=.eclipse.org", sdf.format(date)); - HttpResponseHeaders responseHeaders = new HttpResponseHeaders(new DefaultHttpHeaders().add(SET_COOKIE, cookieDef)); + HttpHeaders responseHeaders = new DefaultHttpHeaders().add(SET_COOKIE, cookieDef); NettyResponse response = new NettyResponse(new NettyResponseStatus(null, null, null), responseHeaders, null); List cookies = response.getCookies(); @@ -51,7 +51,7 @@ public void testCookieParseExpires() { public void testCookieParseMaxAge() { final String cookieDef = "efmembercheck=true; max-age=60; path=/; domain=.eclipse.org"; - HttpResponseHeaders responseHeaders = new HttpResponseHeaders(new DefaultHttpHeaders().add(SET_COOKIE, cookieDef)); + HttpHeaders responseHeaders = new DefaultHttpHeaders().add(SET_COOKIE, cookieDef); NettyResponse response = new NettyResponse(new NettyResponseStatus(null, null, null), responseHeaders, null); List cookies = response.getCookies(); assertEquals(cookies.size(), 1); @@ -63,7 +63,7 @@ public void testCookieParseMaxAge() { @Test(groups = "standalone") public void testCookieParseWeirdExpiresValue() { final String cookieDef = "efmembercheck=true; expires=60; path=/; domain=.eclipse.org"; - HttpResponseHeaders responseHeaders = new HttpResponseHeaders(new DefaultHttpHeaders().add(SET_COOKIE, cookieDef)); + HttpHeaders responseHeaders = new DefaultHttpHeaders().add(SET_COOKIE, cookieDef); NettyResponse response = new NettyResponse(new NettyResponseStatus(null, null, null), responseHeaders, null); List cookies = response.getCookies(); diff --git a/client/src/test/java/org/asynchttpclient/reactivestreams/ReactiveStreamsDownLoadTest.java b/client/src/test/java/org/asynchttpclient/reactivestreams/ReactiveStreamsDownLoadTest.java index 1d92babfba..909ca8115f 100644 --- a/client/src/test/java/org/asynchttpclient/reactivestreams/ReactiveStreamsDownLoadTest.java +++ b/client/src/test/java/org/asynchttpclient/reactivestreams/ReactiveStreamsDownLoadTest.java @@ -13,6 +13,10 @@ */ package org.asynchttpclient.reactivestreams; +import static org.asynchttpclient.Dsl.asyncHttpClient; +import static org.testng.Assert.assertEquals; +import io.netty.handler.codec.http.HttpHeaders; + import java.io.ByteArrayOutputStream; import java.io.File; import java.util.ArrayList; @@ -20,12 +24,8 @@ import java.util.List; import java.util.concurrent.CountDownLatch; -import static org.asynchttpclient.Dsl.*; -import static org.testng.Assert.*; - import org.asynchttpclient.AsyncHttpClient; import org.asynchttpclient.HttpResponseBodyPart; -import org.asynchttpclient.HttpResponseHeaders; import org.asynchttpclient.HttpResponseStatus; import org.asynchttpclient.ListenableFuture; import org.asynchttpclient.handler.StreamedAsyncHandler; @@ -115,7 +115,7 @@ public State onStatusReceived(HttpResponseStatus responseStatus) throws Exceptio } @Override - public State onHeadersReceived(HttpResponseHeaders headers) throws Exception { + public State onHeadersReceived(HttpHeaders headers) throws Exception { return State.CONTINUE; } diff --git a/client/src/test/java/org/asynchttpclient/reactivestreams/ReactiveStreamsTest.java b/client/src/test/java/org/asynchttpclient/reactivestreams/ReactiveStreamsTest.java index a26a43ed81..9ac668c2f3 100644 --- a/client/src/test/java/org/asynchttpclient/reactivestreams/ReactiveStreamsTest.java +++ b/client/src/test/java/org/asynchttpclient/reactivestreams/ReactiveStreamsTest.java @@ -15,6 +15,7 @@ import static org.asynchttpclient.Dsl.*; import static org.asynchttpclient.test.TestUtils.*; import static org.testng.Assert.assertEquals; +import io.netty.handler.codec.http.HttpHeaders; import java.io.ByteArrayOutputStream; import java.nio.ByteBuffer; @@ -28,7 +29,6 @@ import org.asynchttpclient.AsyncHttpClient; import org.asynchttpclient.BoundRequestBuilder; import org.asynchttpclient.HttpResponseBodyPart; -import org.asynchttpclient.HttpResponseHeaders; import org.asynchttpclient.HttpResponseStatus; import org.asynchttpclient.ListenableFuture; import org.asynchttpclient.Response; @@ -153,7 +153,7 @@ public State onStatusReceived(HttpResponseStatus responseStatus) throws Exceptio } @Override - public State onHeadersReceived(HttpResponseHeaders headers) throws Exception { + public State onHeadersReceived(HttpHeaders headers) throws Exception { return State.CONTINUE; } @@ -243,7 +243,7 @@ public State onStatusReceived(HttpResponseStatus responseStatus) throws Exceptio } @Override - public State onHeadersReceived(HttpResponseHeaders headers) throws Exception { + public State onHeadersReceived(HttpHeaders headers) throws Exception { return State.CONTINUE; } diff --git a/client/src/test/java/org/asynchttpclient/request/body/EmptyBodyTest.java b/client/src/test/java/org/asynchttpclient/request/body/EmptyBodyTest.java index e9b11e70e6..304723cfd7 100644 --- a/client/src/test/java/org/asynchttpclient/request/body/EmptyBodyTest.java +++ b/client/src/test/java/org/asynchttpclient/request/body/EmptyBodyTest.java @@ -15,8 +15,9 @@ */ package org.asynchttpclient.request.body; -import static org.asynchttpclient.Dsl.*; +import static org.asynchttpclient.Dsl.asyncHttpClient; import static org.testng.Assert.*; +import io.netty.handler.codec.http.HttpHeaders; import java.io.IOException; import java.io.InputStream; @@ -34,7 +35,6 @@ import org.asynchttpclient.AsyncHandler; import org.asynchttpclient.AsyncHttpClient; import org.asynchttpclient.HttpResponseBodyPart; -import org.asynchttpclient.HttpResponseHeaders; import org.asynchttpclient.HttpResponseStatus; import org.asynchttpclient.Response; import org.eclipse.jetty.server.Request; @@ -95,7 +95,7 @@ public State onStatusReceived(HttpResponseStatus e) throws Exception { return AsyncHandler.State.CONTINUE; } - public State onHeadersReceived(HttpResponseHeaders e) throws Exception { + public State onHeadersReceived(HttpHeaders e) throws Exception { if (headers.incrementAndGet() == 2) { throw new Exception("Analyze this."); } diff --git a/client/src/test/java/org/asynchttpclient/request/body/ZeroCopyFileTest.java b/client/src/test/java/org/asynchttpclient/request/body/ZeroCopyFileTest.java index e8e9c973c7..306ccb17a3 100644 --- a/client/src/test/java/org/asynchttpclient/request/body/ZeroCopyFileTest.java +++ b/client/src/test/java/org/asynchttpclient/request/body/ZeroCopyFileTest.java @@ -15,6 +15,7 @@ import static org.asynchttpclient.Dsl.asyncHttpClient; import static org.asynchttpclient.test.TestUtils.*; import static org.testng.Assert.*; +import io.netty.handler.codec.http.HttpHeaders; import java.io.File; import java.io.IOException; @@ -36,7 +37,6 @@ import org.asynchttpclient.AsyncHttpClient; import org.asynchttpclient.BasicHttpsTest; import org.asynchttpclient.HttpResponseBodyPart; -import org.asynchttpclient.HttpResponseHeaders; import org.asynchttpclient.HttpResponseStatus; import org.asynchttpclient.Response; import org.eclipse.jetty.server.Request; @@ -132,7 +132,7 @@ public State onStatusReceived(HttpResponseStatus responseStatus) throws Exceptio return State.CONTINUE; } - public State onHeadersReceived(HttpResponseHeaders headers) throws Exception { + public State onHeadersReceived(HttpHeaders headers) throws Exception { return State.CONTINUE; } @@ -170,7 +170,7 @@ public State onStatusReceived(HttpResponseStatus responseStatus) throws Exceptio return State.CONTINUE; } - public State onHeadersReceived(HttpResponseHeaders headers) throws Exception { + public State onHeadersReceived(HttpHeaders headers) throws Exception { return State.CONTINUE; } diff --git a/client/src/test/java/org/asynchttpclient/test/EventCollectingHandler.java b/client/src/test/java/org/asynchttpclient/test/EventCollectingHandler.java index 3d33cbdbbc..0e0b594ed6 100644 --- a/client/src/test/java/org/asynchttpclient/test/EventCollectingHandler.java +++ b/client/src/test/java/org/asynchttpclient/test/EventCollectingHandler.java @@ -13,6 +13,7 @@ package org.asynchttpclient.test; import io.netty.channel.Channel; +import io.netty.handler.codec.http.HttpHeaders; import java.net.InetSocketAddress; import java.util.List; @@ -22,7 +23,6 @@ import java.util.concurrent.TimeUnit; import org.asynchttpclient.AsyncCompletionHandlerBase; -import org.asynchttpclient.HttpResponseHeaders; import org.asynchttpclient.HttpResponseStatus; import org.asynchttpclient.Response; import org.asynchttpclient.handler.AsyncHandlerExtensions; @@ -77,7 +77,7 @@ public State onStatusReceived(HttpResponseStatus status) throws Exception { } @Override - public State onHeadersReceived(HttpResponseHeaders headers) throws Exception { + public State onHeadersReceived(HttpHeaders headers) throws Exception { firedEvents.add(HEADERS_RECEIVED_EVENT); return super.onHeadersReceived(headers); } diff --git a/client/src/test/java/org/asynchttpclient/test/TestUtils.java b/client/src/test/java/org/asynchttpclient/test/TestUtils.java index 75f1f21cb4..18ba817f64 100644 --- a/client/src/test/java/org/asynchttpclient/test/TestUtils.java +++ b/client/src/test/java/org/asynchttpclient/test/TestUtils.java @@ -15,6 +15,7 @@ import static java.nio.charset.StandardCharsets.UTF_8; import static org.testng.Assert.*; +import io.netty.handler.codec.http.HttpHeaders; import java.io.File; import java.io.FileNotFoundException; @@ -57,7 +58,6 @@ import org.asynchttpclient.AsyncCompletionHandler; import org.asynchttpclient.AsyncHandler; import org.asynchttpclient.HttpResponseBodyPart; -import org.asynchttpclient.HttpResponseHeaders; import org.asynchttpclient.HttpResponseStatus; import org.asynchttpclient.Response; import org.asynchttpclient.SslEngineFactory; @@ -395,7 +395,7 @@ public State onStatusReceived(final HttpResponseStatus responseStatus) throws Ex } @Override - public State onHeadersReceived(final HttpResponseHeaders headers) throws Exception { + public State onHeadersReceived(final HttpHeaders headers) throws Exception { return State.CONTINUE; } diff --git a/extras/rxjava/src/main/java/org/asynchttpclient/extras/rxjava/single/AbstractSingleSubscriberBridge.java b/extras/rxjava/src/main/java/org/asynchttpclient/extras/rxjava/single/AbstractSingleSubscriberBridge.java index 98a0c3e633..7aa72a839f 100644 --- a/extras/rxjava/src/main/java/org/asynchttpclient/extras/rxjava/single/AbstractSingleSubscriberBridge.java +++ b/extras/rxjava/src/main/java/org/asynchttpclient/extras/rxjava/single/AbstractSingleSubscriberBridge.java @@ -13,18 +13,18 @@ package org.asynchttpclient.extras.rxjava.single; import static java.util.Objects.requireNonNull; +import io.netty.handler.codec.http.HttpHeaders; + +import java.util.Arrays; +import java.util.concurrent.atomic.AtomicBoolean; import org.asynchttpclient.AsyncHandler; import org.asynchttpclient.HttpResponseBodyPart; -import org.asynchttpclient.HttpResponseHeaders; import org.asynchttpclient.HttpResponseStatus; import org.asynchttpclient.extras.rxjava.UnsubscribedException; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import java.util.Arrays; -import java.util.concurrent.atomic.AtomicBoolean; - import rx.SingleSubscriber; import rx.exceptions.CompositeException; import rx.exceptions.Exceptions; @@ -52,7 +52,7 @@ public State onStatusReceived(HttpResponseStatus status) throws Exception { } @Override - public State onHeadersReceived(HttpResponseHeaders headers) throws Exception { + public State onHeadersReceived(HttpHeaders headers) throws Exception { return subscriber.isUnsubscribed() ? abort() : delegate().onHeadersReceived(headers); } diff --git a/extras/rxjava2/src/main/java/org/asynchttpclient/extras/rxjava2/maybe/AbstractMaybeAsyncHandlerBridge.java b/extras/rxjava2/src/main/java/org/asynchttpclient/extras/rxjava2/maybe/AbstractMaybeAsyncHandlerBridge.java index 7af4857879..1af66c44c0 100644 --- a/extras/rxjava2/src/main/java/org/asynchttpclient/extras/rxjava2/maybe/AbstractMaybeAsyncHandlerBridge.java +++ b/extras/rxjava2/src/main/java/org/asynchttpclient/extras/rxjava2/maybe/AbstractMaybeAsyncHandlerBridge.java @@ -14,22 +14,21 @@ package org.asynchttpclient.extras.rxjava2.maybe; import static java.util.Objects.requireNonNull; +import io.netty.handler.codec.http.HttpHeaders; +import io.reactivex.MaybeEmitter; +import io.reactivex.exceptions.CompositeException; +import io.reactivex.exceptions.Exceptions; import java.util.Arrays; import java.util.concurrent.atomic.AtomicBoolean; import org.asynchttpclient.AsyncHandler; import org.asynchttpclient.HttpResponseBodyPart; -import org.asynchttpclient.HttpResponseHeaders; import org.asynchttpclient.HttpResponseStatus; import org.asynchttpclient.extras.rxjava2.DisposedException; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import io.reactivex.MaybeEmitter; -import io.reactivex.exceptions.CompositeException; -import io.reactivex.exceptions.Exceptions; - /** * Abstract base class that bridges events between the {@code Maybe} reactive base type and {@code AsyncHandlers}. * @@ -78,7 +77,7 @@ public final State onStatusReceived(HttpResponseStatus status) throws Exception } @Override - public final State onHeadersReceived(HttpResponseHeaders headers) throws Exception { + public final State onHeadersReceived(HttpHeaders headers) throws Exception { return emitter.isDisposed() ? disposed() : delegate().onHeadersReceived(headers); } diff --git a/extras/rxjava2/src/test/java/org/asynchttpclient/extras/rxjava2/maybe/AbstractMaybeAsyncHandlerBridgeTest.java b/extras/rxjava2/src/test/java/org/asynchttpclient/extras/rxjava2/maybe/AbstractMaybeAsyncHandlerBridgeTest.java index 2e37df5202..711ba263e1 100644 --- a/extras/rxjava2/src/test/java/org/asynchttpclient/extras/rxjava2/maybe/AbstractMaybeAsyncHandlerBridgeTest.java +++ b/extras/rxjava2/src/test/java/org/asynchttpclient/extras/rxjava2/maybe/AbstractMaybeAsyncHandlerBridgeTest.java @@ -27,6 +27,9 @@ import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.verifyNoMoreInteractions; +import io.netty.handler.codec.http.HttpHeaders; +import io.reactivex.MaybeEmitter; +import io.reactivex.exceptions.CompositeException; import java.util.Arrays; import java.util.List; @@ -35,7 +38,6 @@ import org.asynchttpclient.AsyncHandler; import org.asynchttpclient.AsyncHandler.State; import org.asynchttpclient.HttpResponseBodyPart; -import org.asynchttpclient.HttpResponseHeaders; import org.asynchttpclient.HttpResponseStatus; import org.asynchttpclient.extras.rxjava2.DisposedException; import org.mockito.ArgumentCaptor; @@ -48,9 +50,6 @@ import org.testng.annotations.DataProvider; import org.testng.annotations.Test; -import io.reactivex.MaybeEmitter; -import io.reactivex.exceptions.CompositeException; - public class AbstractMaybeAsyncHandlerBridgeTest { @Mock @@ -63,7 +62,7 @@ public class AbstractMaybeAsyncHandlerBridgeTest { private HttpResponseStatus status; @Mock - private HttpResponseHeaders headers; + private HttpHeaders headers; @Mock private HttpResponseBodyPart bodyPart; diff --git a/extras/simple/src/main/java/org/asynchttpclient/extras/simple/SimpleAsyncHttpClient.java b/extras/simple/src/main/java/org/asynchttpclient/extras/simple/SimpleAsyncHttpClient.java index e32a54bfc0..60c1e62eb7 100644 --- a/extras/simple/src/main/java/org/asynchttpclient/extras/simple/SimpleAsyncHttpClient.java +++ b/extras/simple/src/main/java/org/asynchttpclient/extras/simple/SimpleAsyncHttpClient.java @@ -33,7 +33,6 @@ import org.asynchttpclient.AsyncHttpClientConfig; import org.asynchttpclient.DefaultAsyncHttpClientConfig; import org.asynchttpclient.HttpResponseBodyPart; -import org.asynchttpclient.HttpResponseHeaders; import org.asynchttpclient.HttpResponseStatus; import org.asynchttpclient.Param; import org.asynchttpclient.Realm; @@ -790,7 +789,7 @@ private boolean isErrorStatus(HttpResponseStatus status) { } @Override - public State onHeadersReceived(HttpResponseHeaders headers) throws Exception { + public State onHeadersReceived(HttpHeaders headers) throws Exception { calculateTotal(headers); fireHeaders(headers); @@ -798,8 +797,8 @@ public State onHeadersReceived(HttpResponseHeaders headers) throws Exception { return super.onHeadersReceived(headers); } - private void calculateTotal(HttpResponseHeaders headers) { - String length = headers.getHeaders().get(CONTENT_LENGTH); + private void calculateTotal(HttpHeaders headers) { + String length = headers.get(CONTENT_LENGTH); try { total = Integer.valueOf(length); @@ -830,9 +829,9 @@ private void fireReceived(HttpResponseBodyPart content) { } } - private void fireHeaders(HttpResponseHeaders headers) { + private void fireHeaders(HttpHeaders headers) { if (listener != null) { - listener.onHeaders(uri, headers.getHeaders()); + listener.onHeaders(uri, headers); } }