dotnet / WatsonWebserver

Watson is the fastest, easiest way to build scalable RESTful web servers and services in C#.
MIT License
403 stars 83 forks source link

Access-Control-Allow-Methods does not work #98

Closed gamerhost31 closed 2 years ago

gamerhost31 commented 2 years ago

I'm try to set Access-Control-Allow-Methods with a custom http request method types but it does not show on actual response headers

Custom Method : "RDSERVICE"

WebServer.Settings.Headers["Access-Control-Allow-Methods"] = "RDSERVICE";

gamerhost31 commented 2 years ago

I was setting the request header. Please guide me to set response header.

gamerhost31 commented 2 years ago

Update I have added Custom method to response headers in DefaultRoute using ctx.Response.Headers["Access-Control-Allow-Methods"] = "RDSERVICE"; It is working fine with GET Request but when i try sending OPTIONS request it shows default methods i.e OPTIONS, HEAD , GET, PUT, POST, DELETE

jchristn commented 2 years ago

Did you try overloading Routes.Preflight?

gamerhost31 commented 2 years ago

I didn't try that. please give an example for that

jchristn commented 2 years ago

You can see the default implementation here: https://github.com/jchristn/WatsonWebserver/blob/653fd49292faefe009a29acdcaaae81d715d69de/WatsonWebserver/WatsonWebserverRoutes.cs#L185