Skip to content

Performing Preflight Requests Inside Middleware #1527

Answered by iMacTia
AndrewCEmil asked this question in Help
Discussion options

You must be logged in to vote

@AndrewCEmil interesting request, I never found myself wanting to do this, but it should definitely be possible.

I checked how preflight requests are performed (MDN docs) and I noticed the following:

  • The method used should be OPTIONS, not HEAD;
  • The request should contain no body
  • The request should have only 3 headers

Based on the above, I don't think reusing the connection in your middleware is a good idea.
Connections normally contain middleware that add headers and modify the body, among other things.

So your original hunch of simply calling Faraday.head (this is a shorthand for Faraday.new.head) is in my opinion the way to go.
The only downside I see is that this will effectively ope…

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@AndrewCEmil
Comment options

Answer selected by AndrewCEmil
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Help
Labels
None yet
2 participants