Explorar o código

add Allow header to "method not allowed" responses on v1/chat/completions

Docs mention use of the api as `curl ch.at/v1/chat/completions` which
will trigger a GET request, resulting in a 405 response.
Returning an `Allow: POST` header will let clients know they're expected
to post data instead.

The specification as published by the http working group requires it.
https://httpwg.org/specs/rfc9110.html#status.405
msladecek hai 4 meses
pai
achega
ea2273efff
Modificáronse 1 ficheiros con 1 adicións e 0 borrados
  1. 1 0
      http.go

+ 1 - 0
http.go

@@ -320,6 +320,7 @@ func handleChatCompletions(w http.ResponseWriter, r *http.Request) {
 	}
 
 	if r.Method != "POST" {
+		w.Header().Set("Allow", "POST")
 		http.Error(w, "Method not allowed", http.StatusMethodNotAllowed)
 		return
 	}