bwindels / wwwee

wwwee, the wee webserver: a small, robust, low-resource and fast web application server for low workloads (home server, personal cloud)
GNU General Public License v3.0
26 stars 1 forks source link

Support Accept header (parse header with multiple values into struct/iterator) #12

Open bwindels opened 6 years ago

bwindels commented 6 years ago

Accept is an example of a header that supports multiple values. A parser/iterator is needed to iterate over the values, and parse them into one or more structs while iterating.

It would be great to have a generic mechanism to parse headers with multiple values.

E.g. https://tools.ietf.org/html/rfc7231#section-5.3.2:

Accept: text/plain; q=0.5, text/html,
             text/x-dvi; q=0.8, text/x-c

Would become

struct MimeType<'a> {
  type: Option<&'a str>, //* becomes None
  sub_type: Option<&'a str>,
}
struct MediaRange<'a> {
  mime: MimeType<'a>,
  quality: f64,
  format: Option<&'a str>,
  level: u16
}

And the value of the header is an iterator of this. I haven't completely investigated whether this is feasible and desirable so good to discuss before picking this up.