Skip to content

XmlHttpRequest add get_all_response_headers method #381

New issue

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

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

Already on GitHub? # to your account

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(),
};
```
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant