20
20
import java .net .URISyntaxException ;
21
21
import java .nio .channels .ClosedChannelException ;
22
22
import java .time .Duration ;
23
+ import java .util .ArrayList ;
23
24
import java .util .Collections ;
25
+ import java .util .List ;
24
26
import java .util .Map ;
25
27
import java .util .Objects ;
26
28
import java .util .Set ;
@@ -106,6 +108,7 @@ class HttpClientOperations extends HttpOperations<NettyInbound, NettyOutbound>
106
108
final HttpHeaders requestHeaders ;
107
109
final ClientCookieEncoder cookieEncoder ;
108
110
final ClientCookieDecoder cookieDecoder ;
111
+ final List <Cookie > cookieList ;
109
112
final Sinks .One <HttpHeaders > trailerHeaders ;
110
113
111
114
Supplier <String >[] redirectedFrom = EMPTY_REDIRECTIONS ;
@@ -144,6 +147,7 @@ class HttpClientOperations extends HttpOperations<NettyInbound, NettyOutbound>
144
147
this .requestHeaders = replaced .requestHeaders ;
145
148
this .cookieEncoder = replaced .cookieEncoder ;
146
149
this .cookieDecoder = replaced .cookieDecoder ;
150
+ this .cookieList = replaced .cookieList ;
147
151
this .resourceUrl = replaced .resourceUrl ;
148
152
this .path = replaced .path ;
149
153
this .responseTimeout = replaced .responseTimeout ;
@@ -165,14 +169,14 @@ class HttpClientOperations extends HttpOperations<NettyInbound, NettyOutbound>
165
169
this .requestHeaders = nettyRequest .headers ();
166
170
this .cookieDecoder = decoder ;
167
171
this .cookieEncoder = encoder ;
172
+ this .cookieList = new ArrayList <>();
168
173
this .trailerHeaders = Sinks .unsafe ().one ();
169
174
}
170
175
171
176
@ Override
172
177
public HttpClientRequest addCookie (Cookie cookie ) {
173
178
if (!hasSentHeaders ()) {
174
- this .requestHeaders .add (HttpHeaderNames .COOKIE ,
175
- cookieEncoder .encode (cookie ));
179
+ this .cookieList .add (cookie );
176
180
}
177
181
else {
178
182
throw new IllegalStateException ("Status and headers already sent" );
@@ -587,6 +591,10 @@ protected void afterMarkSentHeaders() {
587
591
588
592
@ Override
589
593
protected void beforeMarkSentHeaders () {
594
+ if (!cookieList .isEmpty ()) {
595
+ requestHeaders .add (HttpHeaderNames .COOKIE , cookieEncoder .encode (cookieList ));
596
+ }
597
+
590
598
if (redirectedFrom .length > 0 ) {
591
599
if (redirectRequestConsumer != null ) {
592
600
redirectRequestConsumer .accept (this );
0 commit comments