@@ -151,42 +151,42 @@ impl Client {
151
151
}
152
152
153
153
/// Build a Get request.
154
- pub fn get < U : IntoUrl > ( & self , url : U ) -> RequestBuilder < U > {
154
+ pub fn get < U : IntoUrl > ( & self , url : U ) -> RequestBuilder {
155
155
self . request ( Method :: Get , url)
156
156
}
157
157
158
158
/// Build a Head request.
159
- pub fn head < U : IntoUrl > ( & self , url : U ) -> RequestBuilder < U > {
159
+ pub fn head < U : IntoUrl > ( & self , url : U ) -> RequestBuilder {
160
160
self . request ( Method :: Head , url)
161
161
}
162
162
163
163
/// Build a Patch request.
164
- pub fn patch < U : IntoUrl > ( & self , url : U ) -> RequestBuilder < U > {
164
+ pub fn patch < U : IntoUrl > ( & self , url : U ) -> RequestBuilder {
165
165
self . request ( Method :: Patch , url)
166
166
}
167
167
168
168
/// Build a Post request.
169
- pub fn post < U : IntoUrl > ( & self , url : U ) -> RequestBuilder < U > {
169
+ pub fn post < U : IntoUrl > ( & self , url : U ) -> RequestBuilder {
170
170
self . request ( Method :: Post , url)
171
171
}
172
172
173
173
/// Build a Put request.
174
- pub fn put < U : IntoUrl > ( & self , url : U ) -> RequestBuilder < U > {
174
+ pub fn put < U : IntoUrl > ( & self , url : U ) -> RequestBuilder {
175
175
self . request ( Method :: Put , url)
176
176
}
177
177
178
178
/// Build a Delete request.
179
- pub fn delete < U : IntoUrl > ( & self , url : U ) -> RequestBuilder < U > {
179
+ pub fn delete < U : IntoUrl > ( & self , url : U ) -> RequestBuilder {
180
180
self . request ( Method :: Delete , url)
181
181
}
182
182
183
183
184
184
/// Build a new request using this Client.
185
- pub fn request < U : IntoUrl > ( & self , method : Method , url : U ) -> RequestBuilder < U > {
185
+ pub fn request < U : IntoUrl > ( & self , method : Method , url : U ) -> RequestBuilder {
186
186
RequestBuilder {
187
187
client : self ,
188
188
method : method,
189
- url : url,
189
+ url : url. into_url ( ) ,
190
190
body : None ,
191
191
headers : None ,
192
192
}
@@ -201,30 +201,39 @@ impl Default for Client {
201
201
///
202
202
/// One of these will be built for you if you use one of the convenience
203
203
/// methods, such as `get()`, `post()`, etc.
204
- pub struct RequestBuilder < ' a , U : IntoUrl > {
204
+ pub struct RequestBuilder < ' a > {
205
205
client : & ' a Client ,
206
- url : U ,
206
+ // We store a result here because it's good to keep RequestBuilder
207
+ // from being generic, but it is a nicer API to report the error
208
+ // from `send` (when other errors may be happening, so it already
209
+ // returns a `Result`). Why's it good to keep it non-generic? It
210
+ // stops downstream crates having to remonomorphise and recompile
211
+ // the code, which can take a while, since `send` is fairly large.
212
+ // (For an extreme example, a tiny crate containing
213
+ // `hyper::Client::new().get("x").send().unwrap();` took ~4s to
214
+ // compile with a generic RequestBuilder, but 2s with this scheme,)
215
+ url : Result < Url , UrlError > ,
207
216
headers : Option < Headers > ,
208
217
method : Method ,
209
218
body : Option < Body < ' a > > ,
210
219
}
211
220
212
- impl < ' a , U : IntoUrl > RequestBuilder < ' a , U > {
221
+ impl < ' a > RequestBuilder < ' a > {
213
222
214
223
/// Set a request body to be sent.
215
- pub fn body < B : Into < Body < ' a > > > ( mut self , body : B ) -> RequestBuilder < ' a , U > {
224
+ pub fn body < B : Into < Body < ' a > > > ( mut self , body : B ) -> RequestBuilder < ' a > {
216
225
self . body = Some ( body. into ( ) ) ;
217
226
self
218
227
}
219
228
220
229
/// Add additional headers to the request.
221
- pub fn headers ( mut self , headers : Headers ) -> RequestBuilder < ' a , U > {
230
+ pub fn headers ( mut self , headers : Headers ) -> RequestBuilder < ' a > {
222
231
self . headers = Some ( headers) ;
223
232
self
224
233
}
225
234
226
235
/// Add an individual new header to the request.
227
- pub fn header < H : Header + HeaderFormat > ( mut self , header : H ) -> RequestBuilder < ' a , U > {
236
+ pub fn header < H : Header + HeaderFormat > ( mut self , header : H ) -> RequestBuilder < ' a > {
228
237
{
229
238
let mut headers = match self . headers {
230
239
Some ( ref mut h) => h,
@@ -242,7 +251,7 @@ impl<'a, U: IntoUrl> RequestBuilder<'a, U> {
242
251
/// Execute this request and receive a Response back.
243
252
pub fn send ( self ) -> :: Result < Response > {
244
253
let RequestBuilder { client, method, url, headers, body } = self ;
245
- let mut url = try!( url. into_url ( ) ) ;
254
+ let mut url = try!( url) ;
246
255
trace ! ( "send {:?} {:?}" , method, url) ;
247
256
248
257
let can_have_body = match & method {
0 commit comments