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

How can I get the response headers (specifically content-type) if I don't specify it? #111

Open
CodeWithOz opened this issue Jul 3, 2020 · 3 comments

Comments

@CodeWithOz
Copy link

CodeWithOz commented Jul 3, 2020

With the request library I can get the headers on the response object because the response object is provided in the callback.
This is what I mean:
request-example

How can I do that with this library?

@CodeWithOz CodeWithOz changed the title How can I get the response type if I don't specify it? How can I get the response headers (specifically content-type) if I don't specify it? Jul 3, 2020
@CodeWithOz
Copy link
Author

Based the docs about response encodings, would the correct thing be something like this?

const ajax = bent(200); // avoid specifying a response encoding
const response = await ajax(url);
const contentType = response.headers["content-type"];

@srl295
Copy link
Contributor

srl295 commented Sep 17, 2020

Based the docs about response encodings, would the correct thing be something like this?

const ajax = bent(200); // avoid specifying a response encoding
const response = await ajax(url);
const contentType = response.headers["content-type"];

That does, in fact, seem to work.

@mikeal
Copy link
Owner

mikeal commented Sep 18, 2020

Yup, that’s it 👍

If you then want a decoded response there are async methods attached to the response for decoding string, arrayBuffer and json.

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

No branches or pull requests

3 participants