Skip to content

CORS Middleware help #908

@josh2112

Description

@josh2112

Please forgive the question, as I'm sure this is just a misunderstanding I have about CORS or Hug middleware...

As I understand it, a request involving CORS is actually two requests:

  1. A preflight request, using the OPTIONS method, where the server tells give us permission to make the 'real' request along with some headers.
  2. The actual request.

I've been having a problem with duplicate requests in one of my Hug APIs. It seems like the built-in CORS middleware is adding the appropriate headers to the OPTIONS request, but then passing it on through to the API. The client then gets the OPTIONS response and sends the real requests, which results in the same operation being performed twice in my API.

It is my understanding that a CORS middleware should entirely handle the OPTIONS request, sending a response itself and not passing it on to any other middleware or the API.

Is there a reason the Hug CORS middlware doesn't do this, and is there an easy way to accomplish it?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions