Use 200 OK in responses for preflight requests

Some browsers only accept 200 OK and not 204 No Content as respones codes
for preflight requests.

See tus/tus-js-client#34
This commit is contained in:
Marius 2016-05-10 11:58:43 +02:00
parent 3e6ea68d07
commit d6bc50ff12
5 changed files with 12 additions and 5 deletions

View File

@ -48,7 +48,7 @@ func TestConcatPartial(t *testing.T) {
ResHeader: map[string]string{ ResHeader: map[string]string{
"Tus-Extension": "creation,concatenation", "Tus-Extension": "creation,concatenation",
}, },
Code: http.StatusNoContent, Code: http.StatusOK,
}).Run(handler, t) }).Run(handler, t)
(&httpTest{ (&httpTest{

View File

@ -20,7 +20,7 @@ func TestCORS(t *testing.T) {
ReqHeader: map[string]string{ ReqHeader: map[string]string{
"Origin": "tus.io", "Origin": "tus.io",
}, },
Code: http.StatusNoContent, Code: http.StatusOK,
ResHeader: map[string]string{ ResHeader: map[string]string{
"Access-Control-Allow-Headers": "", "Access-Control-Allow-Headers": "",
"Access-Control-Allow-Methods": "", "Access-Control-Allow-Methods": "",

View File

@ -18,7 +18,7 @@ func TestOptions(t *testing.T) {
(&httpTest{ (&httpTest{
Name: "Successful request", Name: "Successful request",
Method: "OPTIONS", Method: "OPTIONS",
Code: http.StatusNoContent, Code: http.StatusOK,
ResHeader: map[string]string{ ResHeader: map[string]string{
"Tus-Extension": "creation", "Tus-Extension": "creation",
"Tus-Version": "1.0.0", "Tus-Version": "1.0.0",

View File

@ -46,7 +46,7 @@ func TestTerminate(t *testing.T) {
ResHeader: map[string]string{ ResHeader: map[string]string{
"Tus-Extension": "creation,termination", "Tus-Extension": "creation,termination",
}, },
Code: http.StatusNoContent, Code: http.StatusOK,
}).Run(handler, t) }).Run(handler, t)
(&httpTest{ (&httpTest{

View File

@ -158,7 +158,14 @@ func (handler *UnroutedHandler) Middleware(h http.Handler) http.Handler {
header.Set("Tus-Version", "1.0.0") header.Set("Tus-Version", "1.0.0")
header.Set("Tus-Extension", handler.extensions) header.Set("Tus-Extension", handler.extensions)
w.WriteHeader(http.StatusNoContent) // Although the 204 No Content status code is a better fit in this case,
// since we do not have a response body included, we cannot use it here
// as some browsers only accept 200 OK as successful response to a
// preflight request. If we send them the 204 No Content the response
// will be ignored or interpreted as a rejection.
// For example, the Presto engine, which is used in older versions of
// Opera, Opera Mobile and Opera Mini, handles CORS this way.
w.WriteHeader(http.StatusOK)
return return
} }