Performing Preflight Requests Inside Middleware #1527
-
Hi! I'm trying to figure out a way to perform preflight requests within my middleware. Roughly speaking it would look something like this:
While I could simply do Is there a way to construct such a connection? I wouldn't mind manually moving everything in the env over, but I don't see any information about the middleware in use on the original connection there. Perhaps its part of the Thanks for any help! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
@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:
Based on the above, I don't think reusing the connection in your middleware is a good idea. So your original hunch of simply calling So a possible better alternative would be for the middleware to make a copy of Such a mechanism is hard to achieve with the standard |
Beta Was this translation helpful? Give feedback.
@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:
OPTIONS
, notHEAD
;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 forFaraday.new.head
) is in my opinion the way to go.The only downside I see is that this will effectively ope…