      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

    //! A Collection of Header implementations for common HTTP Headers.
    //!
    //! ## Mime
    //!
    //! Several header fields use MIME values for their contents. Keeping with the
    //! strongly-typed theme, the [mime](https://docs.rs/mime) crate
    //! is used, such as `ContentType(pub Mime)`.
    #![cfg_attr(rustfmt, rustfmt_skip)]

    pub use self::accept_charset::AcceptCharset;
    //pub use self::accept_encoding::AcceptEncoding;
    pub use self::accept_language::AcceptLanguage;
    pub use self::accept::Accept;
    pub use self::allow::Allow;
    pub use self::cache_control::{CacheControl, CacheDirective};
    pub use self::content_disposition::{ContentDisposition, DispositionType, DispositionParam};
    pub use self::content_language::ContentLanguage;
    pub use self::content_range::{ContentRange, ContentRangeSpec};
    pub use self::content_type::ContentType;
    pub use self::date::Date;
    pub use self::etag::ETag;
    pub use self::expires::Expires;
    pub use self::if_match::IfMatch;
    pub use self::if_modified_since::IfModifiedSince;
    pub use self::if_none_match::IfNoneMatch;
    pub use self::if_range::IfRange;
    pub use self::if_unmodified_since::IfUnmodifiedSince;
    pub use self::last_modified::LastModified;
    //pub use self::range::{Range, ByteRangeSpec};

    #[doc(hidden)]
    #[macro_export]
    macro_rules! __hyper__deref {
        ($from:ty => $to:ty) => {
            impl ::std::ops::Deref for $from {
                type Target = $to;

                #[inline]
                fn deref(&self) -> &$to {
                    &self.0
                }
            }

            impl ::std::ops::DerefMut for $from {
                #[inline]
                fn deref_mut(&mut self) -> &mut $to {
                    &mut self.0
                }
            }
        }
    }

    #[doc(hidden)]
    #[macro_export]
    macro_rules! __hyper__tm {
        ($id:ident, $tm:ident{$($tf:item)*}) => {
            #[allow(unused_imports)]
            #[cfg(test)]
            mod $tm{
                use std::str;
                use http::Method;
                use $crate::header::*;
                use $crate::mime::*;
                use super::$id as HeaderField;
                $($tf)*
            }

        }
    }

    #[doc(hidden)]
    #[macro_export]
    macro_rules! test_header {
        ($id:ident, $raw:expr) => {
            #[test]
            fn $id() {
                use test;
                let raw = $raw;
                let a: Vec<Vec<u8>> = raw.iter().map(|x| x.to_vec()).collect();
                let mut req = test::TestRequest::default();
                for item in a {
                    req = req.header(HeaderField::name(), item);
                }
                let req = req.finish();
                let value = HeaderField::parse(&req);
                let result = format!("{}", value.unwrap());
                let expected = String::from_utf8(raw[0].to_vec()).unwrap();
                let result_cmp: Vec<String> = result
                    .to_ascii_lowercase()
                    .split(' ')
                    .map(|x| x.to_owned())
                    .collect();
                let expected_cmp: Vec<String> = expected
                    .to_ascii_lowercase()
                    .split(' ')
                    .map(|x| x.to_owned())
                    .collect();
                assert_eq!(result_cmp.concat(), expected_cmp.concat());
            }
        };
        ($id:ident, $raw:expr, $typed:expr) => {
            #[test]
            fn $id() {
                use $crate::test;
                let a: Vec<Vec<u8>> = $raw.iter().map(|x| x.to_vec()).collect();
                let mut req = test::TestRequest::default();
                for item in a {
                    req = req.header(HeaderField::name(), item);
                }
                let req = req.finish();
                let val = HeaderField::parse(&req);
                let typed: Option<HeaderField> = $typed;
                // Test parsing
                assert_eq!(val.ok(), typed);
                // Test formatting
                if typed.is_some() {
                    let raw = &($raw)[..];
                    let mut iter = raw.iter().map(|b|str::from_utf8(&b[..]).unwrap());
                    let mut joined = String::new();
                    joined.push_str(iter.next().unwrap());
                    for s in iter {
                        joined.push_str(", ");
                        joined.push_str(s);
                    }
                    assert_eq!(format!("{}", typed.unwrap()), joined);
                }
            }
        }
    }

    #[macro_export]
    macro_rules! header {
        // $a:meta: Attributes associated with the header item (usually docs)
        // $id:ident: Identifier of the header
        // $n:expr: Lowercase name of the header
        // $nn:expr: Nice name of the header

        // List header, zero or more items
        ($(#[$a:meta])*($id:ident, $name:expr) => ($item:ty)*) => {
            $(#[$a])*
            #[derive(Clone, Debug, PartialEq)]
            pub struct $id(pub Vec<$item>);
            __hyper__deref!($id => Vec<$item>);
            impl $crate::header::Header for $id {
                #[inline]
                fn name() -> $crate::header::HeaderName {
                    $name
                }
                #[inline]
                fn parse<T>(msg: &T) -> Result<Self, $crate::error::ParseError>
                    where T: $crate::HttpMessage
                {
                    $crate::header::from_comma_delimited(
                        msg.headers().get_all(Self::name())).map($id)
                }
            }
            impl ::std::fmt::Display for $id {
                #[inline]
                fn fmt(&self, f: &mut ::std::fmt::Formatter) -> ::std::fmt::Result {
                    $crate::header::fmt_comma_delimited(f, &self.0[..])
                }
            }
            impl $crate::header::IntoHeaderValue for $id {
                type Error = $crate::header::InvalidHeaderValueBytes;

                fn try_into(self) -> Result<$crate::header::HeaderValue, Self::Error> {
                    use std::fmt::Write;
                    let mut writer = $crate::header::Writer::new();
                    let _ = write!(&mut writer, "{}", self);
                    $crate::header::HeaderValue::from_shared(writer.take())
                }
            }
        };
        // List header, one or more items
        ($(#[$a:meta])*($id:ident, $name:expr) => ($item:ty)+) => {
            $(#[$a])*
            #[derive(Clone, Debug, PartialEq)]
            pub struct $id(pub Vec<$item>);
            __hyper__deref!($id => Vec<$item>);
            impl $crate::header::Header for $id {
                #[inline]
                fn name() -> $crate::header::HeaderName {
                    $name
                }
                #[inline]
                fn parse<T>(msg: &T) -> Result<Self, $crate::error::ParseError>
                    where T: $crate::HttpMessage
                {
                    $crate::header::from_comma_delimited(
                        msg.headers().get_all(Self::name())).map($id)
                }
            }
            impl ::std::fmt::Display for $id {
                #[inline]
                fn fmt(&self, f: &mut ::std::fmt::Formatter) -> ::std::fmt::Result {
                    $crate::header::fmt_comma_delimited(f, &self.0[..])
                }
            }
            impl $crate::header::IntoHeaderValue for $id {
                type Error = $crate::header::InvalidHeaderValueBytes;

                fn try_into(self) -> Result<$crate::header::HeaderValue, Self::Error> {
                    use std::fmt::Write;
                    let mut writer = $crate::header::Writer::new();
                    let _ = write!(&mut writer, "{}", self);
                    $crate::header::HeaderValue::from_shared(writer.take())
                }
            }
        };
        // Single value header
        ($(#[$a:meta])*($id:ident, $name:expr) => [$value:ty]) => {
            $(#[$a])*
            #[derive(Clone, Debug, PartialEq)]
            pub struct $id(pub $value);
            __hyper__deref!($id => $value);
            impl $crate::header::Header for $id {
                #[inline]
                fn name() -> $crate::header::HeaderName {
                    $name
                }
                #[inline]
                fn parse<T>(msg: &T) -> Result<Self, $crate::error::ParseError>
                    where T: $crate::HttpMessage
                {
                    $crate::header::from_one_raw_str(
                        msg.headers().get(Self::name())).map($id)
                }
            }
            impl ::std::fmt::Display for $id {
                #[inline]
                fn fmt(&self, f: &mut ::std::fmt::Formatter) -> ::std::fmt::Result {
                    ::std::fmt::Display::fmt(&self.0, f)
                }
            }
            impl $crate::header::IntoHeaderValue for $id {
                type Error = $crate::header::InvalidHeaderValueBytes;

                fn try_into(self) -> Result<$crate::header::HeaderValue, Self::Error> {
                    self.0.try_into()
                }
            }
        };
        // List header, one or more items with "*" option
        ($(#[$a:meta])*($id:ident, $name:expr) => {Any / ($item:ty)+}) => {
            $(#[$a])*
            #[derive(Clone, Debug, PartialEq)]
            pub enum $id {
                /// Any value is a match
                Any,
                /// Only the listed items are a match
                Items(Vec<$item>),
            }
            impl $crate::header::Header for $id {
                #[inline]
                fn name() -> $crate::header::HeaderName {
                    $name
                }
                #[inline]
                fn parse<T>(msg: &T) -> Result<Self, $crate::error::ParseError>
                    where T: $crate::HttpMessage
                {
                    let any = msg.headers().get(Self::name()).and_then(|hdr| {
                        hdr.to_str().ok().and_then(|hdr| Some(hdr.trim() == "*"))});

                    if let Some(true) = any {
                        Ok($id::Any)
                    } else {
                        Ok($id::Items(
                            $crate::header::from_comma_delimited(
                                msg.headers().get_all(Self::name()))?))
                    }
                }
            }
            impl ::std::fmt::Display for $id {
                #[inline]
                fn fmt(&self, f: &mut ::std::fmt::Formatter) -> ::std::fmt::Result {
                    match *self {
                        $id::Any => f.write_str("*"),
                        $id::Items(ref fields) => $crate::header::fmt_comma_delimited(
                            f, &fields[..])
                    }
                }
            }
            impl $crate::header::IntoHeaderValue for $id {
                type Error = $crate::header::InvalidHeaderValueBytes;

                fn try_into(self) -> Result<$crate::header::HeaderValue, Self::Error> {
                    use std::fmt::Write;
                    let mut writer = $crate::header::Writer::new();
                    let _ = write!(&mut writer, "{}", self);
                    $crate::header::HeaderValue::from_shared(writer.take())
                }
            }
        };

        // optional test module
        ($(#[$a:meta])*($id:ident, $name:expr) => ($item:ty)* $tm:ident{$($tf:item)*}) => {
            header! {
                $(#[$a])*
                ($id, $name) => ($item)*
            }

            __hyper__tm! { $id, $tm { $($tf)* }}
        };
        ($(#[$a:meta])*($id:ident, $n:expr) => ($item:ty)+ $tm:ident{$($tf:item)*}) => {
            header! {
                $(#[$a])*
                ($id, $n) => ($item)+
            }

            __hyper__tm! { $id, $tm { $($tf)* }}
        };
        ($(#[$a:meta])*($id:ident, $name:expr) => [$item:ty] $tm:ident{$($tf:item)*}) => {
            header! {
                $(#[$a])* ($id, $name) => [$item]
            }

            __hyper__tm! { $id, $tm { $($tf)* }}
        };
        ($(#[$a:meta])*($id:ident, $name:expr) => {Any / ($item:ty)+} $tm:ident{$($tf:item)*}) => {
            header! {
                $(#[$a])*
                ($id, $name) => {Any / ($item)+}
            }

            __hyper__tm! { $id, $tm { $($tf)* }}
        };
    }

    mod accept_charset;
    //mod accept_encoding;
    mod accept_language;
    mod accept;
    mod allow;
    mod cache_control;
    mod content_disposition;
    mod content_language;
    mod content_range;
    mod content_type;
    mod date;
    mod etag;
    mod expires;
    mod if_match;
    mod if_modified_since;
    mod if_none_match;
    mod if_range;
    mod if_unmodified_since;
    mod last_modified;
    //mod range;

# Help

## Keyboard Shortcuts

`?`
  Show this help dialog
`S`
  Focus the search field
`↑`
  Move up in search results
`↓`
  Move down in search results
`↹`
  Switch tab
`⏎`
  Go to active search result
`+`
  Expand all sections
`-`
  Collapse all sections

## Search Tricks

Prefix searches with a type followed by a colon (e.g. `fn:`) to restrict the search to a given type.

Accepted types are: `fn`, `mod`, `struct`, `enum`, `trait`, `type`, `macro`, and `const`.

Search functions by type signature (e.g. `vec -> usize` or `* -> vec`)

Search multiple things at once by splitting your query with comma (e.g. `str,u8` or `String,struct:Vec,test`)