@@ -69,7 +69,8 @@ public final class HttpTxContext {
69
69
private final CloseListener listener = new CloseListener <Closeable , CloseType >() {
70
70
@ Override
71
71
public void onClosed (Closeable closeable , CloseType type ) throws IOException {
72
- if (isGracefullyFinishResponseOnClose ()) {
72
+ if (responseStatus != null && // responseStatus==null if request wasn't even sent
73
+ isGracefullyFinishResponseOnClose ()) {
73
74
// Connection was closed.
74
75
// This event is fired only for responses, which don't have
75
76
// associated transfer-encoding or content-length.
@@ -107,10 +108,14 @@ public static void set(final FilterChainContext ctx, final HttpTxContext httpTxC
107
108
REQUEST_STATE_ATTR .set (httpContext , httpTxContext );
108
109
}
109
110
110
- public static void remove (final FilterChainContext ctx , final HttpTxContext httpTxContext ) {
111
- HttpContext httpContext = HttpContext .get (ctx );
112
- httpContext .getCloseable ().removeCloseListener (httpTxContext .listener );
113
- REQUEST_STATE_ATTR .remove (ctx );
111
+ public static HttpTxContext remove (final FilterChainContext ctx ) {
112
+ final HttpContext httpContext = HttpContext .get (ctx );
113
+ final HttpTxContext httpTxContext = REQUEST_STATE_ATTR .remove (httpContext );
114
+ if (httpTxContext != null ) {
115
+ httpContext .getCloseable ().removeCloseListener (httpTxContext .listener );
116
+ }
117
+
118
+ return httpTxContext ;
114
119
}
115
120
116
121
public static HttpTxContext get (FilterChainContext ctx ) {
0 commit comments