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

Lowercase PATCH verb sent in CORS preflight request result in a rejected method when the server responds with an uppercase PATCH allow-methods #26

Closed
ane opened this issue Nov 28, 2014 · 3 comments

Comments

@ane
Copy link

ane commented Nov 28, 2014

For cross-origin requests the browser usually sends a preflight OPTIONS request. This request usually asks "Can I use method POST for this resource?" among other questions, by specifying a Access-Control-Request-Headers: POST.

The server will then respond with Access-Control-Allow-Methods: GET, POST allowing the method.

With axios, sending a patch request creates a Access-Control-Request-Headers: patch request, and if the server responds with Access-Control-Allow-Methods: PATCH, the created XmlHttpRequest does not send an uppercase PATCH verb, but sends a lowercase one, and the browser decides to disallow the request.

This occurs only with PATCH. The reason for this is unclear, but on Chrome 39 on Firefox 33 it seems that all verbs are auto-corrected to uppercase with the exception of PATCH.

Why is this an issue? Because according to the spec, HTTP verbs are case-sensitive, and should be uppercase by default.

http://www.ietf.org/rfc/rfc2616.txt

The Method token indicates the method to be performed on the resource identified by the Request-URI. The method is case-sensitive.
[list of HTTP methods, GET, POST ...]

Thus, the culprit is in fact both in axios and browsers: because browsers tend to uppercase the preflight verbs (but patch seems to be omitted, I have not tested other verbs), and axios sends a lowercase method parameter here.

I think the simplest fix would just be to set the line to method: method.toUpperCase(). This fixed it for me.

@mzabriskie
Copy link
Member

@ane thanks for filing the issue, and for the detailed explanation. I will take a look at getting it fixed.

@mzabriskie
Copy link
Member

Fixed with #30

@mzabriskie
Copy link
Member

This is resolved with version 0.4.2

2rist pushed a commit to 2rist/mappersmith that referenced this issue Dec 18, 2017
E.g. see an issue and a fix in axios
axios/axios#26
axios/axios#30
@axios axios locked and limited conversation to collaborators May 21, 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

2 participants