ServiceStack gibt bei einer OPTIONEN-Anforderung 405 zurück
Ich erstelle einen REST-Webservice mit ServiceStack. Ich möchte domänenübergreifende Anfragen zulassen und habe daher das CorsFeature-Plugin registriert.
Mein AppHost sieht wie folgt aus:
public class HomeAppHost : AppHostHttpListenerBase
{
public Context Context { get; set; }
public HomeAppHost(Context context)
: base("HomeAutomation", typeof(HomeInterfaceService).Assembly)
{
Context = context;
}
public override void Configure(Funq.Container container)
{
Plugins.Add(new CorsFeature());
Routes
.Add<HomeInterface>("/HomeInterface")
.Add<HomeInterface>("/HomeInterface/{Id}")
.Add<ViewModel>("/ViewModel")
.Add<FunctionInput>("/Function")
;
}
}
Wenn dann eine OPTIONEN-Anforderung an den Dienst gestellt wird, führt dies zu einer 405-Methode, die nicht zulässig ist:
Anfordern:
OPTIONS /Function HTTP/1.1
Host: localhost:1337
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:18.0) Gecko/20100101 Firefox/18.0 FirePHP/0.7.1
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: nl,en-us;q=0.7,en;q=0.3
Accept-Encoding: gzip, deflate
DNT: 1
Origin: http://localhost
Access-Control-Request-Method: POST
Access-Control-Request-Headers: content-type
x-insight: activate
Connection: keep-alive
Pragma: no-cache
Cache-Control: no-cache
Antwort:
HTTP/1.1 405 Method Not Allowed
Content-Length: 1837
Content-Type: application/xml
Server: Microsoft-HTTPAPI/2.0
Date: Fri, 15 Feb 2013 20:19:33 GMT
Bearbeiten
Das Hinzufügen einer leeren Options-Methode zum Dienst verhindert in der Tat, dass der 405 ausgelöst wird. Die Antwort scheint jedoch leer zu sein:
HTTP/1.1 200 OK
Transfer-Encoding: chunked
Server: Microsoft-HTTPAPI/2.0
Date: Sat, 16 Feb 2013 08:44:21 GMT
Wenn ich Folgendes hinzufüge, erhalte ich auch eine leere Antwort:
RequestFilters.Add((httpReq, httpRes, requestDto) =>
{
//Handles Request and closes Responses after emitting global HTTP Headers
if (httpReq.HttpMethod == "OPTIONS")
httpRes.End();
});
Ich musste httpReq.Method in httpReq.HttpMethod und httpRes.EndServiceStackRequest () in httpRes.End () ändern. Ist das richtig?