Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

XmlHttpRequest add get_all_response_headers method #381

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

izissise
Copy link

get_all_response_headers allow one to retrieve all response
headers and so they can be iterated over.

Example converting headers to hyper::http::HeaderMap

let xhr = XmlHttpRequest::new();
let raw_headers = xhr.get_all_response_headers();
let headers = match raw_headers {
    Some(rh) => {
        let mut headers = http::header::HeaderMap::new();
        for h in rh.split("\r\n") {
            if h.len() == 0 {
                continue;
            }
            let parts: Vec<&str> = h.split(": ").collect();
            let k = parts[0];
            let k = http::header::HeaderName::from_bytes(k.as_bytes()).unwrap();
            let v = parts[1..].join(": ");
            let v = http::header::HeaderValue::from_str(&v).unwrap();
            headers.append(k, v);
        }
        headers
    },
    None => http::header::HeaderMap::new(),
};

get_all_response_headers allow one to retrieve all response
headers and so they can be iterated over.

Example converting headers to hyper::http::HeaderMap
```
let xhr = XmlHttpRequest::new();
let raw_headers = xhr.get_all_response_headers();
let headers = match raw_headers {
    Some(rh) => {
        let mut headers = http::header::HeaderMap::new();
        for h in rh.split("\r\n") {
            if h.len() == 0 {
                continue;
            }
            let parts: Vec<&str> = h.split(": ").collect();
            let k = parts[0];
            let k = http::header::HeaderName::from_bytes(k.as_bytes()).unwrap();
            let v = parts[1..].join(": ");
            let v = http::header::HeaderValue::from_str(&v).unwrap();
            headers.append(k, v);
        }
        headers
    },
    None => http::header::HeaderMap::new(),
};
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant