1
Fork 0
mirror of https://github.com/jech/galene.git synced 2024-12-22 15:25:48 +01:00

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) {
ctype := parseContentType(r.Header.Get("Content-Type"))
if !strings.EqualFold(ctype, "text/plain") {
w.Header().Set("Accept", "text/plain")
http.Error(w, "unsupported content type",
http.StatusUnsupportedMediaType)
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 {
ctype := parseContentType(r.Header.Get("Content-Type"))
if !strings.EqualFold(ctype, "application/json") {
w.Header().Set("Accept", "application/json")
http.Error(w, "unsupported content type",
http.StatusUnsupportedMediaType)
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
ctype := parseContentType(r.Header.Get("Content-Type"))
if !strings.EqualFold(ctype, "application/jwk-set+json") {
w.Header().Set("Accept", "application/jwk-set+json")
http.Error(w, "unsupported content type",
http.StatusUnsupportedMediaType)
return

View file

@ -192,7 +192,9 @@ func whipEndpointHandler(w http.ResponseWriter, r *http.Request) {
ctype := r.Header.Get("content-type")
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
}
@ -337,7 +339,9 @@ func whipResourceHandler(w http.ResponseWriter, r *http.Request) {
ctype := r.Header.Get("content-type")
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
}