forked from External/mediamtx
parent
575d3585fe
commit
5d0ebdef56
3 changed files with 15 additions and 5 deletions
8
internal/protocols/httpp/content_type.go
Normal file
8
internal/protocols/httpp/content_type.go
Normal file
|
|
@ -0,0 +1,8 @@
|
||||||
|
package httpp
|
||||||
|
|
||||||
|
import "strings"
|
||||||
|
|
||||||
|
// ParseContentType parses a Content-Type header and returns the content type.
|
||||||
|
func ParseContentType(v string) string {
|
||||||
|
return strings.TrimSpace(strings.Split(v, ";")[0])
|
||||||
|
}
|
||||||
|
|
@ -7,7 +7,6 @@ import (
|
||||||
"io"
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
"net/url"
|
||||||
"strings"
|
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/bluenviron/gortsplib/v4/pkg/format"
|
"github.com/bluenviron/gortsplib/v4/pkg/format"
|
||||||
|
|
@ -15,6 +14,7 @@ import (
|
||||||
"github.com/pion/webrtc/v3"
|
"github.com/pion/webrtc/v3"
|
||||||
|
|
||||||
"github.com/bluenviron/mediamtx/internal/logger"
|
"github.com/bluenviron/mediamtx/internal/logger"
|
||||||
|
"github.com/bluenviron/mediamtx/internal/protocols/httpp"
|
||||||
)
|
)
|
||||||
|
|
||||||
// WHIPClient is a WHIP client.
|
// WHIPClient is a WHIP client.
|
||||||
|
|
@ -286,8 +286,8 @@ func (c *WHIPClient) postOffer(
|
||||||
return nil, fmt.Errorf("bad status code: %v", res.StatusCode)
|
return nil, fmt.Errorf("bad status code: %v", res.StatusCode)
|
||||||
}
|
}
|
||||||
|
|
||||||
contentType := res.Header.Get("Content-Type")
|
contentType := httpp.ParseContentType(req.Header.Get("Content-Type"))
|
||||||
if strings.TrimSpace(strings.Split(contentType, ";")[0]) != "application/sdp" {
|
if contentType != "application/sdp" {
|
||||||
return nil, fmt.Errorf("bad Content-Type: expected 'application/sdp', got '%s'", contentType)
|
return nil, fmt.Errorf("bad Content-Type: expected 'application/sdp', got '%s'", contentType)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -165,7 +165,8 @@ func (s *httpServer) onWHIPOptions(ctx *gin.Context, pathName string, publish bo
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *httpServer) onWHIPPost(ctx *gin.Context, pathName string, publish bool) {
|
func (s *httpServer) onWHIPPost(ctx *gin.Context, pathName string, publish bool) {
|
||||||
if ctx.Request.Header.Get("Content-Type") != "application/sdp" {
|
contentType := httpp.ParseContentType(ctx.Request.Header.Get("Content-Type"))
|
||||||
|
if contentType != "application/sdp" {
|
||||||
writeError(ctx, http.StatusBadRequest, fmt.Errorf("invalid Content-Type"))
|
writeError(ctx, http.StatusBadRequest, fmt.Errorf("invalid Content-Type"))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
@ -215,7 +216,8 @@ func (s *httpServer) onWHIPPatch(ctx *gin.Context, pathName string, rawSecret st
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if ctx.Request.Header.Get("Content-Type") != "application/trickle-ice-sdpfrag" {
|
contentType := httpp.ParseContentType(ctx.Request.Header.Get("Content-Type"))
|
||||||
|
if contentType != "application/trickle-ice-sdpfrag" {
|
||||||
writeError(ctx, http.StatusBadRequest, fmt.Errorf("invalid Content-Type"))
|
writeError(ctx, http.StatusBadRequest, fmt.Errorf("invalid Content-Type"))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue