simplist 0.0.5

plain and simple http, for when you just want to make a darn request! supports tokio-based async, traditional sync and async-await models.
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
use std::cell::RefCell;

use futures::Future;
use futures::future::FutureResult;
use hina;
use hina::result::ResultExt;
use hina::task::OneOfFuture;
use hyper::Body;
use hyper::client::Client;
use hyper::client::HttpConnector;
use tokio_core::reactor::CoreId;
use tokio_core::reactor::Remote;

use simplist::HttpContent;
use simplist::HttpError;
use simplist::HttpMethod;
use simplist::HttpRequest;
use simplist::HttpResponse;
use simplist::HttpSyncResponse;
use simplist::IntoUrl;
use simplist::Url;



thread_local! {
    static THREAD_LOCAL_DATA: RefCell<Option<ThreadData>> = RefCell::new(None);
}

struct ThreadData {
    core:   CoreId,
    client: Client<HttpConnector, Body>,
}



/// an asynchronous, futures-based http client.
///
/// a class for sending http requests and receiving http responses from a resource identified by a uri. this class
/// provides a simple, asynchronous, futures-based api.
///
/// if you'd like to use a synchronous, blocking api instead, [`HttpSyncClient`](struct.HttpSyncClient.html) may be
/// easier to use. alternatively, you can emulate a blocking api on this struct by synchronously waiting for future
/// results by calling `wait()` on all returned futures.
///
/// all examples here assume that you have an existing tokio reactor you can use. if you not already have a tokio core,
/// a complete example demonstrating the initialization and usage of tokio together with this http client is available
/// at https://github.com/hinaria/simplist/blob/master/examples/basic-async.rs.
///
/// # nightly
///
/// if you're using a nightly compiler, you can significantly reduce the number of allocations that simplist performs by
/// enabling the `nightly` feature. refer to the [module-level](https://docs.rs/simplist/) docs for more information.
///
/// # methods
///
/// this struct provides two sets of operations for performing http operations: one for returning the response as a
/// [`Vec<u8>`](https://doc.rust-lang.org/std/vec/struct.Vec.html), and another for returning the response as a
/// [`String`](https://doc.rust-lang.org/std/string/struct.String.html).
///
/// finally, there is a separate method, [`fn request(...)`](struct.HttpClient.html#method.request) that takes a
/// [`HttpRequest`](struct.HttpRequest.html) and allows you to manually set the http method, as well as set http
/// headers.
///
/// rustdoc currently generates some pretty unreadable documentation for this struct, so we'll summarize the available
/// methods here.
///
/// ## methods returning a [`Vec<u8>`](https://doc.rust-lang.org/std/vec/struct.Vec.html):
///
/// ```
/// .
///     fn options(url, Option<body>) -> Future<Item = Vec<u8>, Error = HttpError>;
///     fn get    (url)               -> Future<Item = Vec<u8>, Error = HttpError>;
///     fn post   (url, Option<body>) -> Future<Item = Vec<u8>, Error = HttpError>;
///     fn put    (url, Option<body>) -> Future<Item = Vec<u8>, Error = HttpError>;
///     fn delete (url)               -> Future<Item = Vec<u8>, Error = HttpError>;
///     fn head   (url)               -> Future<Item = Vec<u8>, Error = HttpError>;
///     fn trace  (url)               -> Future<Item = Vec<u8>, Error = HttpError>;
///     fn connect(url)               -> Future<Item = Vec<u8>, Error = HttpError>;
///     fn patch  (url, Option<body>) -> Future<Item = Vec<u8>, Error = HttpError>;
/// ```
///
/// ## methods returning a [`String<u8>`](https://doc.rust-lang.org/std/string/struct.String.html):
///
/// ```
/// .
///     fn options_string(url, Option<body>) -> Future<Item = String, Error = HttpError>;
///     fn get_string    (url)               -> Future<Item = String, Error = HttpError>;
///     fn post_string   (url, Option<body>) -> Future<Item = String, Error = HttpError>;
///     fn put_string    (url, Option<body>) -> Future<Item = String, Error = HttpError>;
///     fn delete_string (url)               -> Future<Item = String, Error = HttpError>;
///     fn head_string   (url)               -> Future<Item = String, Error = HttpError>;
///     fn trace_string  (url)               -> Future<Item = String, Error = HttpError>;
///     fn connect_string(url)               -> Future<Item = String, Error = HttpError>;
///     fn patch_string  (url, Option<body>) -> Future<Item = String, Error = HttpError>;
/// ```
///
/// # examples
///
/// ## asynchronous, with await notation.
///
/// ```
/// use simplist::HttpClient;
///
/// let http = HttpClient::new(handle);
/// let html = await http.get_string("https://hinaria.com")?;
///
/// println!("{:?}", html);
/// // => "<!doctype html>\n<html lang=\"en\">\n<head>\n    <meta charset=\"utf-8\"> ..."
/// ```
///
/// ## asynchronous, with future callbacks.
///
/// ```
/// use simplist::HttpClient;
///
/// let http   = HttpClient::new(handle);
/// let future = http.get_string("https://hinaria.com").and_then(|html| {
///     println!("{:?}", html);
///     Ok(())
/// }).map_err(|_| ());
///
/// handle.spawn(future);
/// // => "<!doctype html>\n<html lang=\"en\">\n<head>\n    <meta charset=\"utf-8\"> ..."
/// ```
///
/// ## synchronous.
///
/// ```
/// use simplist::HttpSyncClient;
///
/// let http = HttpSyncClient::new(handle);
/// let html = http.get_string("https://hinaria.com")?;
///
/// println!("{:?}", html);
/// // => "<!doctype html>\n<html lang=\"en\">\n<head>\n    <meta charset=\"utf-8\"> ..."
/// ```
#[derive(Clone, Debug)]
pub struct HttpClient {
    remote: Remote,
}

impl HttpClient {
    /// creates a new http client.
    ///
    /// this method is very cheap, and does not perform any kind of initialization.
    ///
    /// # examples
    ///
    /// ```
    /// use simplist::HttpClient;
    ///
    /// let http = HttpClient::new(handle);
    /// ```
    pub fn new(remote: Remote) -> HttpClient  {
        HttpClient { remote }
    }

    /// sends a http request as an asynchronous operation.
    ///
    /// # examples
    ///
    /// ```
    /// use simplist::HttpClient;
    /// use simplist::HttpMethod;
    ///
    /// let http      = HttpClient::new(handle);
    /// let url       = "https://hinaria.com".parse()?;
    /// let operation = HttpRequest::with(url, HttpMethod::Get);
    /// let response  = await http.request(operation)?;
    ///
    /// assert_eq!(response.status(), StatusCode::Ok);
    /// ```
    pub fn request(&self, request: HttpRequest) -> Box<Future<Item = HttpResponse, Error = HttpError>> {
        let request         = request.into();
        let (send, receive) = hina::task::sync::source();

        self.remote.spawn(|handle| {
            THREAD_LOCAL_DATA.with(|data| {
                let core        = handle.id();
                let mut storage = data.borrow_mut();


                // initialize the hyper http client if it does not exist, or if it does not belong to this core.
                if storage.is_none() || storage.as_ref().unwrap().core != core {
                    *storage = Some(ThreadData {
                        core:   core,
                        client: Client::new(handle),
                    })
                }


                // perform the request.
                let data = storage
                    .as_ref()
                    .expect(d!["invariant broken: thread local data was none."]);

                data.client.request(request)
                    .map    (HttpResponse::new)
                    .map_err(From::from)
                    .then   (|x| { send.done(x).consume(); Ok(()) })
            })
        });

        Box::new(receive)
    }

    fn run_bytes<TBody>(&self, url: Url, method: HttpMethod, content: Option<TBody>) -> Box<Future<Item = Vec<u8>, Error = HttpError>>
        where TBody: Into<HttpContent> {

        let request = HttpRequest::new()
            .with_url(url)
            .with_method(method)
            .with_body(content);

        let future  = self.request(request).and_then(|response| {
            match response.status_code() {
                0...399 => OneOfFuture::A(response.read_as_bytes()),
                _       => OneOfFuture::B(hina::task::failed(HttpError::Status(response.status()))),
            }
        });

        Box::new(future)
    }

    fn run_string<TBody>(&self, url: Url, method: HttpMethod, content: Option<TBody>) -> Box<Future<Item = String, Error = HttpError>>
        where TBody: Into<HttpContent> {

        Box::new(
            self.run_bytes(url, method, content)
                .and_then (|x| String::from_utf8(x).map_err(From::from)))
    }
}



/// a synchronous, blocking http client.
///
/// a class for sending http requests and receiving http responses from a resource identified by a uri. this class uses
/// tokio behind the scenes, but exposes a blocking, synchronous api.
///
/// all examples here assume that you have an existing tokio reactor you can use. if you not already have a tokio core,
/// a complete example demonstrating the initialization and usage of tokio together with this http client is available
/// at https://github.com/hinaria/simplist/blob/master/examples/basic-sync.rs.
///
/// # methods
///
/// this struct provides two sets of operations for performing http operations: one for returning the response as a
/// [`Vec<u8>`](https://doc.rust-lang.org/std/vec/struct.Vec.html), and another for returning the response as a
/// [`String`](https://doc.rust-lang.org/std/string/struct.String.html).
///
/// finally, there is a separate method, [`fn request(...)`](struct.HttpSyncClient.html#method.request) that takes a
/// [`HttpRequest`](struct.HttpRequest.html) and allows you to manually set the http method, as well as set http
/// headers.
///
/// rustdoc currently generates some pretty unreadable documentation for this struct, so we'll summarize the available
/// methods here.
///
/// ## methods returning a [`Vec<u8>`](https://doc.rust-lang.org/std/vec/struct.Vec.html):
///
/// ```
/// .
///     fn options(url, Option<body>) -> Result<Vec<u8>, HttpError>;
///     fn get    (url)               -> Result<Vec<u8>, HttpError>;
///     fn post   (url, Option<body>) -> Result<Vec<u8>, HttpError>;
///     fn put    (url, Option<body>) -> Result<Vec<u8>, HttpError>;
///     fn delete (url)               -> Result<Vec<u8>, HttpError>;
///     fn head   (url)               -> Result<Vec<u8>, HttpError>;
///     fn trace  (url)               -> Result<Vec<u8>, HttpError>;
///     fn connect(url)               -> Result<Vec<u8>, HttpError>;
///     fn patch  (url, Option<body>) -> Result<Vec<u8>, HttpError>;
/// ```
///
/// ## methods returning a [`String<u8>`](https://doc.rust-lang.org/std/string/struct.String.html):
///
/// ```
/// .
///     fn options_string(url, Option<body>) -> Result<String, HttpError>;
///     fn get_string    (url)               -> Result<String, HttpError>;
///     fn post_string   (url, Option<body>) -> Result<String, HttpError>;
///     fn put_string    (url, Option<body>) -> Result<String, HttpError>;
///     fn delete_string (url)               -> Result<String, HttpError>;
///     fn head_string   (url)               -> Result<String, HttpError>;
///     fn trace_string  (url)               -> Result<String, HttpError>;
///     fn connect_string(url)               -> Result<String, HttpError>;
///     fn patch_string  (url, Option<body>) -> Result<String, HttpError>;
/// ```
///
/// # examples
///
/// ```
/// use simplist::HttpSyncClient;
///
/// let http = HttpSyncClient::new(handle);
/// let html = http.get_string("https://hinaria.com")?;
///
/// println!("{:?}", html);
/// // => "<!doctype html>\n<html lang=\"en\">\n<head>\n    <meta charset=\"utf-8\"> ..."
/// ```
#[derive(Clone, Debug)]
pub struct HttpSyncClient {
    underlying: HttpClient,
}

impl HttpSyncClient {
    /// creates a new http client.
    ///
    /// this method is very cheap, and does not perform any kind of initialization.
    ///
    /// # examples
    ///
    /// ```
    /// use simplist::HttpSyncClient;
    ///
    /// let http = HttpSyncClient::new(handle);
    /// ```
    pub fn new(remote: Remote) -> HttpSyncClient  {
        HttpSyncClient {
            underlying: HttpClient::new(remote),
        }
    }

    /// sends a http request.
    ///
    /// # examples
    ///
    /// ```
    /// use simplist::HttpClient;
    /// use simplist::HttpMethod;
    ///
    /// let http      = HttpClient::new(handle);
    /// let url       = "https://hinaria.com".parse()?;
    /// let operation = HttpRequest::with(url, HttpMethod::Get);
    /// let response  = http.request(operation)?;
    ///
    /// assert_eq!(response.status(), StatusCode::Ok);
    /// ```
    pub fn request(&self, request: HttpRequest) -> Result<HttpSyncResponse, HttpError> {
        self.underlying.request(request)
            .wait()
            .map (HttpSyncResponse::new)
    }
}


macro_rules! http_client_methods {
    () => {};

    // :: [content = no] implementation for methods with no content body
    (no-content, $method_variant: path, $method_name: ident, $string_method_name: ident) => {
        impl HttpClient {
            /// sends an asynchronous http request, returning the response as a
            /// [`Vec<u8>`](https://doc.rust-lang.org/std/vec/struct.Vec.html).
            ///
            /// # examples
            ///
            /// ```
            /// use simplist::HttpClient;
            ///
            /// let http = HttpClient::new(handle);
            ///
            /// assert_eq!(
            ///     &await http.get("https://hinaria.com")?,
            ///     &[60, 33, 68, 79, 67, 84, 89, 80, 69, 32, 104, 116, ...]);
            /// ```
            pub fn $method_name<TUrl>(&self, url: TUrl) -> OneOfFuture<Box<Future<Item = Vec<u8>, Error = HttpError>>, FutureResult<Vec<u8>, HttpError>, Vec<u8>, HttpError>
                where TUrl: IntoUrl {

                match url.as_url() {
                    Ok(url) => OneOfFuture::A(self.run_bytes(url, $method_variant, Option::None::<&'static [u8]>)),
                    Err(e)  => OneOfFuture::B(hina::task::failed(e)),
                }
            }

            /// sends an asynchronous http request, returning the response as a
            /// [`String`](https://doc.rust-lang.org/std/string/struct.String.html).
            ///
            /// # examples
            ///
            /// ```
            /// use simplist::HttpClient;
            ///
            /// let http = HttpClient::new(handle);
            ///
            /// assert_eq!(
            ///     await http.get_string("https://hinaria.com")?,
            ///     "<!doctype html>\n<html lang=\"en\">\n<head>\n    <meta charset=\"utf-8\"> ...");
            /// ```
            pub fn $string_method_name<TUrl>(&self, url: TUrl) -> OneOfFuture<Box<Future<Item = String, Error = HttpError>>, FutureResult<String, HttpError>, String, HttpError>
                where TUrl: IntoUrl {

                match url.as_url() {
                    Ok(url) => OneOfFuture::A(self.run_string(url, $method_variant, Option::None::<&'static [u8]>)),
                    Err(e)  => OneOfFuture::B(hina::task::failed(e)),
                }
            }
        }

        impl HttpSyncClient {
            /// sends an http request, returning the response as a
            /// [`Vec<u8>`](https://doc.rust-lang.org/std/vec/struct.Vec.html).
            ///
            /// # examples
            ///
            /// ```
            /// use simplist::HttpSyncClient;
            ///
            /// let http = HttpSyncClient::new(handle);
            ///
            /// assert_eq!(
            ///     &http.get("https://hinaria.com")?,
            ///     &[60, 33, 68, 79, 67, 84, 89, 80, 69, 32, 104, 116, ...]);
            /// ```
            pub fn $method_name<TUrl>(&self, url: TUrl) -> Result<Vec<u8>, HttpError>
                where TUrl: IntoUrl {

                self.underlying.$method_name(url).wait()
            }

            /// sends an asynchronous http request, returning the response as a
            /// [`String`](https://doc.rust-lang.org/std/string/struct.String.html).
            ///
            /// # examples
            ///
            /// ```
            /// use simplist::HttpSyncClient;
            ///
            /// let http = HttpSyncClient::new(handle);
            ///
            /// assert_eq!(
            ///     http.get_string("https://hinaria.com")?,
            ///     "<!doctype html>\n<html lang=\"en\">\n<head>\n    <meta charset=\"utf-8\"> ...");
            /// ```
            pub fn $string_method_name<TUrl>(&self, url: TUrl) -> Result<String, HttpError>
                where TUrl: IntoUrl {

                self.underlying.$string_method_name(url).wait()
            }
        }
    };

    // :: [content = yes] implementation for methods with a content body
    (x, $method_variant: path, $method_name: ident, $string_method_name: ident) => {
        impl HttpClient {
            /// sends an asynchronous http request, returning the response as a
            /// [`Vec<u8>`](https://doc.rust-lang.org/std/vec/struct.Vec.html).
            ///
            /// the request body can be any type that is convertible to a [`HttpContent`](struct.HttpContent.html).
            /// refer to [`HttpContent`](struct.HttpContent.html) to see a list of types that can be used.
            ///
            /// # examples
            ///
            /// ```
            /// use simplist::HttpClient;
            ///
            /// let http = HttpClient::new(handle);
            /// let body = Some("{ id: 1234 }");
            ///
            /// assert_eq!(
            ///     &await http.post("https://hinaria.com/users/@me/database", body)?,
            ///     &[60, 33, 68, 79, 67, 84, 89, 80, 69, 32, 104, 116, ...]);
            /// ```
            pub fn $method_name<TUrl, TContent>(&self, url: TUrl, content: Option<TContent>) -> OneOfFuture<Box<Future<Item = Vec<u8>, Error = HttpError>>, FutureResult<Vec<u8>, HttpError>, Vec<u8>, HttpError>
                where TUrl:     IntoUrl,
                      TContent: Into<HttpContent>, {

                match url.as_url() {
                    Ok(url) => OneOfFuture::A(self.run_bytes(url, $method_variant, content)),
                    Err(e)  => OneOfFuture::B(hina::task::failed(e)),
                }
            }

            /// sends an asynchronous http request, returning the response as a
            /// [`String`](https://doc.rust-lang.org/std/string/struct.String.html).
            ///
            /// the request body can be any type that is convertible to a [`HttpContent`](struct.HttpContent.html).
            /// refer to [`HttpContent`](struct.HttpContent.html) to see a list of types that can be used.
            ///
            /// # examples
            ///
            /// ```
            /// use simplist::HttpClient;
            ///
            /// let http = HttpClient::new(handle);
            /// let body = Some("{ id: 1234 }");
            ///
            /// assert_eq!(
            ///     &await http.post_string("https://hinaria.com/users/@me/database", body)?,
            ///     "<!doctype html>\n<html lang=\"en\">\n<head>\n    <meta charset=\"utf-8\"> ...");
            /// ```
            pub fn $string_method_name<TUrl, TContent>(&self, url: TUrl, content: Option<TContent>) -> OneOfFuture<Box<Future<Item = String, Error = HttpError>>, FutureResult<String, HttpError>, String, HttpError>
                where TUrl:     IntoUrl,
                      TContent: Into<HttpContent>, {

                match url.as_url() {
                    Ok(url) => OneOfFuture::A(self.run_string(url, $method_variant, content)),
                    Err(e)  => OneOfFuture::B(hina::task::failed(e)),
                }
            }
        }

        impl HttpSyncClient {
            /// sends an asynchronous http request, returning the response as a
            /// [`Vec<u8>`](https://doc.rust-lang.org/std/vec/struct.Vec.html).
            ///
            /// the request body can be any type that is convertible to a [`HttpContent`](struct.HttpContent.html).
            /// refer to [`HttpContent`](struct.HttpContent.html) to see a list of types that can be used.
            ///
            /// # examples
            ///
            /// ```
            /// use simplist::HttpSyncClient;
            ///
            /// let http = HttpSyncClient::new(handle);
            /// let body = Some("{ id: 1234 }");
            ///
            /// assert_eq!(
            ///     &http.post("https://hinaria.com/users/@me/database", body)?,
            ///     &[60, 33, 68, 79, 67, 84, 89, 80, 69, 32, 104, 116, ...]);
            /// ```
            pub fn $method_name<TUrl, TContent>(&self, url: TUrl, content: Option<TContent>) -> Result<Vec<u8>, HttpError>
                where TUrl:     IntoUrl,
                      TContent: Into<HttpContent>, {

                self.underlying.$method_name(url, content).wait()
            }

            /// sends an asynchronous http request, returning the response as a
            /// [`String`](https://doc.rust-lang.org/std/string/struct.String.html).
            ///
            /// the request body can be any type that is convertible to a [`HttpContent`](struct.HttpContent.html).
            /// refer to [`HttpContent`](struct.HttpContent.html) to see a list of types that can be used.
            ///
            /// # examples
            ///
            /// ```
            /// use simplist::HttpSyncClient;
            ///
            /// let http = HttpSyncClient::new(handle);
            /// let body = Some("{ id: 1234 }");
            ///
            /// assert_eq!(
            ///     &http.post_string("https://hinaria.com/users/@me/database", body)?,
            ///     "<!doctype html>\n<html lang=\"en\">\n<head>\n    <meta charset=\"utf-8\"> ...");
            /// ```
            pub fn $string_method_name<TUrl, TContent>(&self, url: TUrl, content: Option<TContent>) -> Result<String, HttpError>
                where TUrl:     IntoUrl,
                      TContent: Into<HttpContent>, {

                self.underlying.$string_method_name(url, content).wait()
            }
        }
    };

    ([no-content, $method_variant: path, $method_name: ident, $string_method_name: ident], $($rest:tt)*) => {
        http_client_methods!(no-content, $method_variant, $method_name, $string_method_name);
        http_client_methods!($($rest)*);
    };

    ([x,          $method_variant: path, $method_name: ident, $string_method_name: ident], $($rest:tt)*) => {
        http_client_methods!(x, $method_variant, $method_name, $string_method_name);
        http_client_methods!($($rest)*);
    };
}

http_client_methods!(
    [x,          HttpMethod::Options, options, options_string],
    [no-content, HttpMethod::Get,     get,     get_string    ],
    [x,          HttpMethod::Post,    post,    post_string   ],
    [x,          HttpMethod::Put,     put,     put_string    ],
    [no-content, HttpMethod::Delete,  delete,  delete_string ],
    [no-content, HttpMethod::Head,    head,    head_string   ],
    [no-content, HttpMethod::Trace,   trace,   trace_string  ],
    [no-content, HttpMethod::Connect, connect, connect_string],
    [x,          HttpMethod::Patch,   patch,   patch_string  ],
);