Internal representation was changed from an enum back to a Struct again.
The raw representation *has* to stick around, even if parsed as a proper
typed header. The reason is that internally, hyper will access some
headers to know which parts of the http protocol to follow (such as if
the response has a length or is chunked). The raw value may still be
needed afterwards, such as for a DOM binding of
.getAllResponseHeaders().
Since the raw is kept around, the unsafety of get_raw is no longer true,
and so that is removed.
It's still more ergonomic to access the types, and safer as well, so
that is recommended when possible.
Latest 0.13.0-nightly gives this:
warning: static constant `phrase` should have an uppercase name such as
`PHRASE`, #[warn(non_upper_case_globals)] on by default
The old parser used a manually unrolled state machine
and was broken due to upstream rust issues with match
statements.
The new parser is a read into a stack-allocated buffer
followed by a single match on the contents of that
buffer.
This significantly improves the benchmarks for method
reads by almost 30%, in addition to working around
the upstream rust issues with reordering match blocks.
If two threads attempted to `get_ref` the same Header under two
representations, then it was possible that the second thread would
overwrite the work of the first thread, causing the first thread
to do an unchecked downcast to the wrong type.
In the case where they were the same Header representation, then the
only damage would be that it would be parsed twice and would possibly
return a false negative in one thread.
The new code checks that it was not a queued lock and will not override
the work of another thread, but will accept it if the other thread parsed
the header as the same type. This also prevents duplicate parsing.
This removes the need to receive `&mut self` in `get_ref` and `get.`
Since the interior mutability of the RWLock is needed only once,
it is safe to change the lifetime of the pointer given by read locks
as by then all mutation has been done.
Since `set` still requires `&mut self` there is no way to use the interior
mutability of the RWLock to modify an existing `&`-reference. However,
the use of interior mutability in `get_ref` means that `get_raw` is now
actually an unsafe operation because the (now `*const`) pointer could be
invalidated by a subsequent call to `get_ref.`
Fixes#47