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

Default header documentation is incomplete #2436

Closed
gilly3 opened this issue Sep 25, 2019 · 2 comments
Closed

Default header documentation is incomplete #2436

gilly3 opened this issue Sep 25, 2019 · 2 comments

Comments

@gilly3
Copy link

gilly3 commented Sep 25, 2019

Section/Content To Improve
Config defaults

Suggested Improvement
The documentation teases with a concept of common when setting default header values:

axios.defaults.headers.common['Authorization'] = AUTH_TOKEN;
axios.defaults.headers.post['Content-Type'] = 'application/x-www-form-urlencoded';

Presumably, that means for all request methods, but (playing devil's advocate here) maybe it's demonstrating that you can set default headers for custom request methods (like if your server accepts a custom request method of common).

Is common actually a keyword that means any request method?

Are there other keywords with special meaning? Like, for example, one that applies only to requests containing a payload?

Does any other non-keyword value apply to a method value? Even custom methods?

Is it possible to set a default header for requests to my server that understands common as a custom HTTP method?

If I set a common header and a get header, does get override common?

Is there a simple way to apply a header to requests of every method type except one?

axios.defaults.headers.common['Content-Type'] = 'application/json';
axios.defaults.headers.get['Content-Type'] = null;

What effect will that have?

Some of my questions are hypothetical. Forgive me.

Relevant File(s): README.md

@yasuf
Copy link
Collaborator

yasuf commented Oct 15, 2019

Is common actually a keyword that means any request method?

common is a word used in this library used for the headers that will be set by default on a request with any verb, you can see how this works here, when you have different headers for common and get for example, the get headers take priority, otherwise, the header property is used as the object to be used which contains all the headers.

config.headers = utils.merge(
config.headers.common || {},
config.headers[config.method] || {},
config.headers || {}
);

Is there a simple way to apply a header to requests of every method type except one?

You can set the headers for common and set it to null or an empty string in the verb that you're looking to exclude.

Let me know if this is helpful

@chinesedfan
Copy link
Collaborator

Closed in favor of #2618.

@axios axios locked and limited conversation to collaborators May 22, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants