This issue is encountered when the server receives an OPTIONS request during a CORS pre-flight. When a browser is about to make a cross domain request that isn't a "basic" request (in this case, a non-basic POST request with json data), it first sends an OPTIONS request to the server for verification that the server supports the actual request. For more, see this link[1].
With snooze, attempting to create a route that handles the OPTIONS method results in an error:
;; the regular route I want to post data to
(defroute create-list (:post "application/json")
(do-some-stuff))
;; route to handle the options pre-flight request
(defroute create-list (:options :text/*))
Now the code compiles and loads. When trying to post json to my route, the pre-flight OPTIONS request sent by the browser receives a 204 response as seen below. I still run into a 400 Bad Request error, but I think that's an issue with my code, not with the snooze library.
There may be a better way to go about adding OPTIONS support. I tried creating the snooze-verb:options class as a subclass of http-verb, and content-verb but both had some issues.
The Issue
This issue is encountered when the server receives an OPTIONS request during a CORS pre-flight. When a browser is about to make a cross domain request that isn't a "basic" request (in this case, a non-basic POST request with json data), it first sends an OPTIONS request to the server for verification that the server supports the actual request. For more, see this link[1].
With snooze, attempting to create a route that handles the OPTIONS method results in an error:
On trying to load the code
I have set up hunchentoot to add the appropriate headers in responses:
My Workaround So Far
In snoozes common.lisp source file, I have made a small addition:
Now the code compiles and loads. When trying to post json to my route, the pre-flight OPTIONS request sent by the browser receives a 204 response as seen below. I still run into a 400 Bad Request error, but I think that's an issue with my code, not with the snooze library.
There may be a better way to go about adding OPTIONS support. I tried creating the
snooze-verb:options
class as a subclass ofhttp-verb
, andcontent-verb
but both had some issues.[1] https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS