From d3bca27e8a65668e70f65be997743aac505610c2 Mon Sep 17 00:00:00 2001 From: Jonathan Reem Date: Sun, 7 Sep 2014 09:57:55 +0200 Subject: [PATCH] Add a get_raw method, which allows users to access the raw value of a header This method is marked unsafe, as it should not be used in normal code because it can easily invalidate header representations. Fixes #10 --- src/header.rs | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/header.rs b/src/header.rs index 1834929b..01937595 100644 --- a/src/header.rs +++ b/src/header.rs @@ -127,6 +127,27 @@ impl Headers { self.get_ref().map(|v: &H| v.clone()) } + /// Access the raw value of a header, if it exists and has not + /// been already parsed. + /// + /// If the header field has already been parsed into a typed header, + /// then you *must* access it through that representation. + /// + /// Example: + /// ``` + /// # use hyper::header::{Headers, ContentType}; + /// # let mut headers = Headers::new(); + /// let raw_content_type = unsafe { headers.get_raw("content-type") }; + /// ``` + pub unsafe fn get_raw(&self, name: &'static str) -> Option<&[Vec]> { + self.data.find(&name).and_then(|item| { + match *item { + Raw(ref raw) => Some(raw.as_slice()), + _ => None + } + }) + } + /// Get a reference to the header field's value, if it exists. pub fn get_ref(&mut self) -> Option<&H> { self.data.find_mut(&header_name::()).and_then(|item| {