1
1
/*
2
- * Copyright 2002-2018 the original author or authors.
2
+ * Copyright 2002-2020 the original author or authors.
3
3
*
4
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
5
* you may not use this file except in compliance with the License.
24
24
import org .eclipse .jetty .client .api .Request ;
25
25
import org .eclipse .jetty .reactive .client .ContentChunk ;
26
26
import org .eclipse .jetty .reactive .client .ReactiveRequest ;
27
+ import org .eclipse .jetty .reactive .client .internal .PublisherContentProvider ;
27
28
import org .eclipse .jetty .util .Callback ;
28
29
import org .reactivestreams .Publisher ;
29
30
import reactor .core .Exceptions ;
37
38
import org .springframework .http .HttpHeaders ;
38
39
import org .springframework .http .HttpMethod ;
39
40
import org .springframework .http .MediaType ;
40
- import org .springframework .lang .Nullable ;
41
41
import org .springframework .util .Assert ;
42
42
43
43
/**
@@ -53,9 +53,6 @@ class JettyClientHttpRequest extends AbstractClientHttpRequest {
53
53
54
54
private final DataBufferFactory bufferFactory ;
55
55
56
- @ Nullable
57
- private ReactiveRequest reactiveRequest ;
58
-
59
56
60
57
public JettyClientHttpRequest (Request jettyRequest , DataBufferFactory bufferFactory ) {
61
58
this .jettyRequest = jettyRequest ;
@@ -87,20 +84,21 @@ public DataBufferFactory bufferFactory() {
87
84
88
85
@ Override
89
86
public Mono <Void > writeWith (Publisher <? extends DataBuffer > body ) {
90
- Flux <ContentChunk > chunks = Flux .from (body ).map (this ::toContentChunk );
91
- ReactiveRequest .Content content = ReactiveRequest .Content .fromPublisher (chunks , getContentType ());
92
- this .reactiveRequest = ReactiveRequest .newBuilder (this .jettyRequest ).content (content ).build ();
87
+ ReactiveRequest .Content content = Flux .from (body )
88
+ .map (this ::toContentChunk )
89
+ .as (chunks -> ReactiveRequest .Content .fromPublisher (chunks , getContentType ()));
90
+ this .jettyRequest .content (new PublisherContentProvider (content ));
93
91
return doCommit (this ::completes );
94
92
}
95
93
96
94
@ Override
97
95
public Mono <Void > writeAndFlushWith (Publisher <? extends Publisher <? extends DataBuffer >> body ) {
98
- Flux < ContentChunk > chunks = Flux .from (body )
96
+ ReactiveRequest . Content content = Flux .from (body )
99
97
.flatMap (Function .identity ())
100
98
.doOnDiscard (PooledDataBuffer .class , DataBufferUtils ::release )
101
- .map (this ::toContentChunk );
102
- ReactiveRequest . Content content = ReactiveRequest .Content .fromPublisher (chunks , getContentType ());
103
- this .reactiveRequest = ReactiveRequest . newBuilder ( this . jettyRequest ) .content (content ). build ( );
99
+ .map (this ::toContentChunk )
100
+ . as ( chunks -> ReactiveRequest .Content .fromPublisher (chunks , getContentType () ));
101
+ this .jettyRequest .content (new PublisherContentProvider ( content ));
104
102
return doCommit (this ::completes );
105
103
}
106
104
@@ -145,11 +143,4 @@ protected void applyHeaders() {
145
143
}
146
144
}
147
145
148
- ReactiveRequest getReactiveRequest () {
149
- if (this .reactiveRequest == null ) {
150
- this .reactiveRequest = ReactiveRequest .newBuilder (this .jettyRequest ).build ();
151
- }
152
- return this .reactiveRequest ;
153
- }
154
-
155
146
}
0 commit comments