1
Fork 0

Add Accept header to 415 replies.

Also fix return code in WHIP.
This commit is contained in:
Juliusz Chroboczek 2024-05-09 17:43:18 +02:00
parent 47528949e5
commit f3ceb05033
2 changed files with 9 additions and 2 deletions

View File

@ -75,6 +75,7 @@ func sendJSON(w http.ResponseWriter, r *http.Request, v any) {
func getText(w http.ResponseWriter, r *http.Request) ([]byte, bool) { func getText(w http.ResponseWriter, r *http.Request) ([]byte, bool) {
ctype := parseContentType(r.Header.Get("Content-Type")) ctype := parseContentType(r.Header.Get("Content-Type"))
if !strings.EqualFold(ctype, "text/plain") { if !strings.EqualFold(ctype, "text/plain") {
w.Header().Set("Accept", "text/plain")
http.Error(w, "unsupported content type", http.Error(w, "unsupported content type",
http.StatusUnsupportedMediaType) http.StatusUnsupportedMediaType)
return nil, true return nil, true
@ -92,6 +93,7 @@ func getText(w http.ResponseWriter, r *http.Request) ([]byte, bool) {
func getJSON(w http.ResponseWriter, r *http.Request, v any) bool { func getJSON(w http.ResponseWriter, r *http.Request, v any) bool {
ctype := parseContentType(r.Header.Get("Content-Type")) ctype := parseContentType(r.Header.Get("Content-Type"))
if !strings.EqualFold(ctype, "application/json") { if !strings.EqualFold(ctype, "application/json") {
w.Header().Set("Accept", "application/json")
http.Error(w, "unsupported content type", http.Error(w, "unsupported content type",
http.StatusUnsupportedMediaType) http.StatusUnsupportedMediaType)
return true return true
@ -458,6 +460,7 @@ func keysHandler(w http.ResponseWriter, r *http.Request, g string) {
// cannot use getJSON due to the weird content-type // cannot use getJSON due to the weird content-type
ctype := parseContentType(r.Header.Get("Content-Type")) ctype := parseContentType(r.Header.Get("Content-Type"))
if !strings.EqualFold(ctype, "application/jwk-set+json") { if !strings.EqualFold(ctype, "application/jwk-set+json") {
w.Header().Set("Accept", "application/jwk-set+json")
http.Error(w, "unsupported content type", http.Error(w, "unsupported content type",
http.StatusUnsupportedMediaType) http.StatusUnsupportedMediaType)
return return

View File

@ -192,7 +192,9 @@ func whipEndpointHandler(w http.ResponseWriter, r *http.Request) {
ctype := r.Header.Get("content-type") ctype := r.Header.Get("content-type")
if !strings.EqualFold(ctype, "application/sdp") { if !strings.EqualFold(ctype, "application/sdp") {
http.Error(w, "bad content type", http.StatusBadRequest) w.Header().Set("Accept", "application/sdp")
http.Error(w, "bad content type",
http.StatusUnsupportedMediaType)
return return
} }
@ -337,7 +339,9 @@ func whipResourceHandler(w http.ResponseWriter, r *http.Request) {
ctype := r.Header.Get("content-type") ctype := r.Header.Get("content-type")
if !strings.EqualFold(ctype, "application/trickle-ice-sdpfrag") { if !strings.EqualFold(ctype, "application/trickle-ice-sdpfrag") {
http.Error(w, "bad content type", http.StatusBadRequest) w.Header().Set("Accept", "application/trickle-ice-sdpfrag")
http.Error(w, "bad content type",
http.StatusUnsupportedMediaType)
return return
} }