1717package  org .springframework .web .reactive .function .client ;
1818
1919import  java .net .URI ;
20- import  java .nio .charset .Charset ;
21- import  java .time .ZonedDateTime ;
2220
2321import  org .reactivestreams .Publisher ;
2422import  reactor .core .publisher .Mono ;
2523
2624import  org .springframework .http .HttpHeaders ;
2725import  org .springframework .http .HttpMethod ;
28- import  org .springframework .http .MediaType ;
2926import  org .springframework .http .client .reactive .ClientHttpRequest ;
3027import  org .springframework .util .Assert ;
3128import  org .springframework .util .MultiValueMap ;
3229import  org .springframework .web .reactive .function .BodyInserter ;
33- import  org .springframework .web .util .DefaultUriTemplateHandler ;
34- import  org .springframework .web .util .UriTemplateHandler ;
3530
3631/** 
37-  * Represents a typed, immutable, client-side HTTP request, as executed by the {@link WebClient}.  
38-  * Instances of this interface are  created via static builder methods:  
39-  * {@link #method(HttpMethod, String, Object...)}, {@link #GET(String, Object...)}, etc . 
32+  * Represents a typed, immutable, client-side HTTP request, as executed by the 
33+  * {@link WebClient}.  Instances of this interface can be  created via static 
34+  * builder methods in this class . 
4035 * 
36+  * <p>Note that applications are more likely to perform requests through 
37+  * {@link WebClientOperations} rather than using this directly. 
38+  * : 
4139 * @param <T> the type of the body that this request contains 
4240 * @author Brian Clozel 
4341 * @author Arjen Poutsma 
4442 * @since 5.0 
4543 */ 
4644public  interface  ClientRequest <T > {
4745
48- 	// Instance methods 
49- 
5046	/** 
5147	 * Return the HTTP method. 
5248	 */ 
@@ -81,6 +77,7 @@ public interface ClientRequest<T> {
8177	 */ 
8278	Mono <Void > writeTo (ClientHttpRequest  request , WebClientStrategies  strategies );
8379
80+ 
8481	// Static builder methods 
8582
8683	/** 
@@ -89,7 +86,7 @@ public interface ClientRequest<T> {
8986	 * @param other the request to copy the method, URI, headers, and cookies from 
9087	 * @return the created builder 
9188	 */ 
92- 	static  BodyBuilder  from (ClientRequest <?> other ) {
89+ 	static  Builder  from (ClientRequest <?> other ) {
9390		Assert .notNull (other , "'other' must not be null" );
9491		return  new  DefaultClientRequestBuilder (other .method (), other .url ())
9592				.headers (other .headers ())
@@ -102,100 +99,15 @@ static BodyBuilder from(ClientRequest<?> other) {
10299	 * @param url the URL 
103100	 * @return the created builder 
104101	 */ 
105- 	static  BodyBuilder  method (HttpMethod  method , URI  url ) {
106- 		return  new  DefaultClientRequestBuilder (method , url );
107- 	}
108- 
109- 	/** 
110- 	 * Create a builder with the given method and url template. 
111- 	 * @param method the HTTP method (GET, POST, etc) 
112- 	 * @param urlTemplate the URL template 
113- 	 * @param uriVariables optional variables to expand the template 
114- 	 * @return the created builder 
115- 	 */ 
116- 	static  BodyBuilder  method (HttpMethod  method , String  urlTemplate , Object ... uriVariables ) {
117- 		UriTemplateHandler  templateHandler  = new  DefaultUriTemplateHandler ();
118- 		URI  url  = templateHandler .expand (urlTemplate , uriVariables );
102+ 	static  Builder  method (HttpMethod  method , URI  url ) {
119103		return  new  DefaultClientRequestBuilder (method , url );
120104	}
121105
122- 	/** 
123- 	 * Create an HTTP GET builder with the given url template. 
124- 	 * @param urlTemplate the URL template 
125- 	 * @param uriVariables optional variables to expand the template 
126- 	 * @return the created builder 
127- 	 */ 
128- 	static  HeadersBuilder <?> GET (String  urlTemplate , Object ... uriVariables ) {
129- 		return  method (HttpMethod .GET , urlTemplate , uriVariables );
130- 	}
131- 
132- 	/** 
133- 	 * Create an HTTP HEAD builder with the given url template. 
134- 	 * @param urlTemplate the URL template 
135- 	 * @param uriVariables optional variables to expand the template 
136- 	 * @return the created builder 
137- 	 */ 
138- 	static  HeadersBuilder <?> HEAD (String  urlTemplate , Object ... uriVariables ) {
139- 		return  method (HttpMethod .HEAD , urlTemplate , uriVariables );
140- 	}
141- 
142- 	/** 
143- 	 * Create an HTTP POST builder with the given url template. 
144- 	 * @param urlTemplate the URL template 
145- 	 * @param uriVariables optional variables to expand the template 
146- 	 * @return the created builder 
147- 	 */ 
148- 	static  BodyBuilder  POST (String  urlTemplate , Object ... uriVariables ) {
149- 		return  method (HttpMethod .POST , urlTemplate , uriVariables );
150- 	}
151- 
152- 	/** 
153- 	 * Create an HTTP PUT builder with the given url template. 
154- 	 * @param urlTemplate the URL template 
155- 	 * @param uriVariables optional variables to expand the template 
156- 	 * @return the created builder 
157- 	 */ 
158- 	static  BodyBuilder  PUT (String  urlTemplate , Object ... uriVariables ) {
159- 		return  method (HttpMethod .PUT , urlTemplate , uriVariables );
160- 	}
161- 
162- 	/** 
163- 	 * Create an HTTP PATCH builder with the given url template. 
164- 	 * @param urlTemplate the URL template 
165- 	 * @param uriVariables optional variables to expand the template 
166- 	 * @return the created builder 
167- 	 */ 
168- 	static  BodyBuilder  PATCH (String  urlTemplate , Object ... uriVariables ) {
169- 		return  method (HttpMethod .PATCH , urlTemplate , uriVariables );
170- 	}
171- 
172- 	/** 
173- 	 * Create an HTTP DELETE builder with the given url template. 
174- 	 * @param urlTemplate the URL template 
175- 	 * @param uriVariables optional variables to expand the template 
176- 	 * @return the created builder 
177- 	 */ 
178- 	static  HeadersBuilder <?> DELETE (String  urlTemplate , Object ... uriVariables ) {
179- 		return  method (HttpMethod .DELETE , urlTemplate , uriVariables );
180- 	}
181- 
182- 	/** 
183- 	 * Creates an HTTP OPTIONS builder with the given url template. 
184- 	 * @param urlTemplate the URL template 
185- 	 * @param uriVariables optional variables to expand the template 
186- 	 * @return the created builder 
187- 	 */ 
188- 	static  HeadersBuilder <?> OPTIONS (String  urlTemplate , Object ... uriVariables ) {
189- 		return  method (HttpMethod .OPTIONS , urlTemplate , uriVariables );
190- 	}
191- 
192106
193107	/** 
194- 	 * Defines a builder that adds headers to the request. 
195- 	 * 
196- 	 * @param <B> the builder subclass 
108+ 	 * Defines a builder for a request. 
197109	 */ 
198- 	interface  HeadersBuilder < B   extends   HeadersBuilder < B >>  {
110+ 	interface  Builder  {
199111
200112		/** 
201113		 * Add the given, single header value under the given name. 
@@ -204,95 +116,37 @@ interface HeadersBuilder<B extends HeadersBuilder<B>> {
204116		 * @return this builder 
205117		 * @see HttpHeaders#add(String, String) 
206118		 */ 
207- 		B  header (String  headerName , String ... headerValues );
119+ 		Builder  header (String  headerName , String ... headerValues );
208120
209121		/** 
210122		 * Copy the given headers into the entity's headers map. 
211123		 * 
212124		 * @param headers the existing HttpHeaders to copy from 
213125		 * @return this builder 
214126		 */ 
215- 		B  headers (HttpHeaders  headers );
216- 
217- 		/** 
218- 		 * Set the list of acceptable {@linkplain MediaType media types}, as 
219- 		 * specified by the {@code Accept} header. 
220- 		 * @param acceptableMediaTypes the acceptable media types 
221- 		 * @return this builder 
222- 		 */ 
223- 		B  accept (MediaType ... acceptableMediaTypes );
224- 
225- 		/** 
226- 		 * Set the list of acceptable {@linkplain Charset charsets}, as specified 
227- 		 * by the {@code Accept-Charset} header. 
228- 		 * @param acceptableCharsets the acceptable charsets 
229- 		 * @return this builder 
230- 		 */ 
231- 		B  acceptCharset (Charset ... acceptableCharsets );
232- 
233- 		/** 
234- 		 * Set the value of the {@code If-Modified-Since} header. 
235- 		 * <p>The date should be specified as the number of milliseconds since 
236- 		 * January 1, 1970 GMT. 
237- 		 * @param ifModifiedSince the new value of the header 
238- 		 * @return this builder 
239- 		 */ 
240- 		B  ifModifiedSince (ZonedDateTime  ifModifiedSince );
241- 
242- 		/** 
243- 		 * Set the values of the {@code If-None-Match} header. 
244- 		 * @param ifNoneMatches the new value of the header 
245- 		 * @return this builder 
246- 		 */ 
247- 		B  ifNoneMatch (String ... ifNoneMatches );
127+ 		Builder  headers (HttpHeaders  headers );
248128
249129		/** 
250130		 * Add a cookie with the given name and value. 
251131		 * @param name the cookie name 
252132		 * @param value the cookie value 
253133		 * @return this builder 
254134		 */ 
255- 		B  cookie (String  name , String  value );
135+ 		Builder  cookie (String  name , String  value );
256136
257137		/** 
258138		 * Copy the given cookies into the entity's cookies map. 
259139		 * 
260140		 * @param cookies the existing cookies to copy from 
261141		 * @return this builder 
262142		 */ 
263- 		B  cookies (MultiValueMap <String , String > cookies );
143+ 		Builder  cookies (MultiValueMap <String , String > cookies );
264144
265145		/** 
266146		 * Builds the request entity with no body. 
267147		 * @return the request entity 
268148		 */ 
269149		ClientRequest <Void > build ();
270- 	}
271- 
272- 
273- 	/** 
274- 	 * Defines a builder that adds a body to the request entity. 
275- 	 */ 
276- 	interface  BodyBuilder  extends  HeadersBuilder <BodyBuilder > {
277- 
278- 
279- 		/** 
280- 		 * Set the length of the body in bytes, as specified by the 
281- 		 * {@code Content-Length} header. 
282- 		 * @param contentLength the content length 
283- 		 * @return this builder 
284- 		 * @see HttpHeaders#setContentLength(long) 
285- 		 */ 
286- 		BodyBuilder  contentLength (long  contentLength );
287- 
288- 		/** 
289- 		 * Set the {@linkplain MediaType media type} of the body, as specified 
290- 		 * by the {@code Content-Type} header. 
291- 		 * @param contentType the content type 
292- 		 * @return this builder 
293- 		 * @see HttpHeaders#setContentType(MediaType) 
294- 		 */ 
295- 		BodyBuilder  contentType (MediaType  contentType );
296150
297151		/** 
298152		 * Set the body of the request to the given {@code BodyInserter} and return it. 
@@ -314,5 +168,4 @@ interface BodyBuilder extends HeadersBuilder<BodyBuilder> {
314168
315169	}
316170
317- 
318171}
0 commit comments