mirror of
https://github.com/aler9/gortsplib
synced 2025-10-06 15:46:51 +08:00
add methods
This commit is contained in:
@@ -61,9 +61,9 @@ func NewAuthClient(header []string, user string, pass string) (*AuthClient, erro
|
||||
|
||||
// GenerateHeader generates an Authorization Header that allows to authenticate a request with
|
||||
// the given method and path.
|
||||
func (ac *AuthClient) GenerateHeader(method string, path string) []string {
|
||||
func (ac *AuthClient) GenerateHeader(method Method, path string) []string {
|
||||
ha1 := md5Hex(ac.user + ":" + ac.realm + ":" + ac.pass)
|
||||
ha2 := md5Hex(method + ":" + path)
|
||||
ha2 := md5Hex(string(method) + ":" + path)
|
||||
response := md5Hex(ha1 + ":" + ac.nonce + ":" + ha2)
|
||||
|
||||
return []string{fmt.Sprintf("Digest username=\"%s\", realm=\"%s\", nonce=\"%s\", uri=\"%s\", response=\"%s\"",
|
||||
|
@@ -16,7 +16,7 @@ type ConnClient struct {
|
||||
writeTimeout time.Duration
|
||||
session string
|
||||
curCSeq int
|
||||
authProv *AuthClient
|
||||
auth *AuthClient
|
||||
}
|
||||
|
||||
// NewConnClient allocates a ConnClient.
|
||||
@@ -44,7 +44,7 @@ func (c *ConnClient) SetSession(v string) {
|
||||
// The content of the header is computed with the given user, password, realm and nonce.
|
||||
func (c *ConnClient) SetCredentials(wwwAuthenticateHeader []string, user string, pass string) error {
|
||||
var err error
|
||||
c.authProv, err = NewAuthClient(wwwAuthenticateHeader, user, pass)
|
||||
c.auth, err = NewAuthClient(wwwAuthenticateHeader, user, pass)
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -57,11 +57,11 @@ func (c *ConnClient) WriteRequest(req *Request) (*Response, error) {
|
||||
req.Header["Session"] = []string{c.session}
|
||||
}
|
||||
|
||||
if c.authProv != nil {
|
||||
if c.auth != nil {
|
||||
if req.Header == nil {
|
||||
req.Header = make(Header)
|
||||
}
|
||||
req.Header["Authorization"] = c.authProv.GenerateHeader(req.Method, req.Url)
|
||||
req.Header["Authorization"] = c.auth.GenerateHeader(req.Method, req.Url)
|
||||
}
|
||||
|
||||
// automatically insert CSeq
|
||||
|
22
request.go
22
request.go
@@ -11,9 +11,25 @@ const (
|
||||
_MAX_PROTOCOL_LENGTH = 128
|
||||
)
|
||||
|
||||
// Method is a RTSP request method.
|
||||
type Method string
|
||||
|
||||
const (
|
||||
OPTIONS Method = "OPTIONS"
|
||||
DESCRIBE Method = "DESCRIBE"
|
||||
SETUP Method = "SETUP"
|
||||
PLAY Method = "PLAY"
|
||||
PLAY_NOTIFY Method = "PLAY_NOTIFY"
|
||||
PAUSE Method = "PAUSE"
|
||||
TEARDOWN Method = "TEARDOWN"
|
||||
GET_PARAMETER Method = "GET_PARAMETER"
|
||||
SET_PARAMETER Method = "SET_PARAMETER"
|
||||
REDIRECT Method = "REDIRECT"
|
||||
)
|
||||
|
||||
// Request is a RTSP request.
|
||||
type Request struct {
|
||||
Method string
|
||||
Method Method
|
||||
Url string
|
||||
Header Header
|
||||
Content []byte
|
||||
@@ -26,7 +42,7 @@ func readRequest(br *bufio.Reader) (*Request, error) {
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
req.Method = string(byts[:len(byts)-1])
|
||||
req.Method = Method(byts[:len(byts)-1])
|
||||
|
||||
if len(req.Method) == 0 {
|
||||
return nil, fmt.Errorf("empty method")
|
||||
@@ -71,7 +87,7 @@ func readRequest(br *bufio.Reader) (*Request, error) {
|
||||
}
|
||||
|
||||
func (req *Request) write(bw *bufio.Writer) error {
|
||||
_, err := bw.Write([]byte(req.Method + " " + req.Url + " " + _RTSP_PROTO + "\r\n"))
|
||||
_, err := bw.Write([]byte(string(req.Method) + " " + req.Url + " " + _RTSP_PROTO + "\r\n"))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
53
response.go
53
response.go
@@ -6,6 +6,59 @@ import (
|
||||
"strconv"
|
||||
)
|
||||
|
||||
// StatusCode is a RTSP response status code.
|
||||
type StatusCode int
|
||||
|
||||
const (
|
||||
StatusContinue StatusCode = 100
|
||||
StatusOK StatusCode = 200
|
||||
StatusMovedPermanently StatusCode = 301
|
||||
StatusFound StatusCode = 302
|
||||
StatusSeeOther StatusCode = 303
|
||||
StatusNotModified StatusCode = 304
|
||||
StatusUseProxy StatusCode = 305
|
||||
StatusBadRequest StatusCode = 400
|
||||
StatusUnauthorized StatusCode = 401
|
||||
StatusPaymentRequired StatusCode = 402
|
||||
StatusForbidden StatusCode = 403
|
||||
StatusNotFound StatusCode = 404
|
||||
StatusMethodNotAllowed StatusCode = 405
|
||||
StatusNotAcceptable StatusCode = 406
|
||||
StatusProxyAuthRequired StatusCode = 407
|
||||
StatusRequestTimeout StatusCode = 408
|
||||
StatusGone StatusCode = 410
|
||||
StatusPreconditionFailed StatusCode = 412
|
||||
StatusRequestEntityTooLarge StatusCode = 413
|
||||
StatusRequestURITooLong StatusCode = 414
|
||||
StatusUnsupportedMediaType StatusCode = 415
|
||||
StatusParameterNotUnderstood StatusCode = 451
|
||||
StatusNotEnoughBandwidth StatusCode = 453
|
||||
StatusSessionNotFound StatusCode = 454
|
||||
StatusMethodNotValidInThisState StatusCode = 455
|
||||
StatusHeaderFieldNotValidForResource StatusCode = 456
|
||||
StatusInvalidRange StatusCode = 457
|
||||
StatusParameterIsReadOnly StatusCode = 458
|
||||
StatusAggregateOperationNotAllowed StatusCode = 459
|
||||
StatusOnlyAggregateOperationAllowed StatusCode = 460
|
||||
StatusUnsupportedTransport StatusCode = 461
|
||||
StatusDestinationUnreachable StatusCode = 462
|
||||
StatusDestinationProhibited StatusCode = 463
|
||||
StatusDataTransportNotReadyYet StatusCode = 464
|
||||
StatusNotificationReasonUnknown StatusCode = 465
|
||||
StatusKeyManagementError StatusCode = 466
|
||||
StatusConnectionAuthorizationRequired StatusCode = 470
|
||||
StatusConnectionCredentialsNotAccepted StatusCode = 471
|
||||
StatusFailureToEstablishSecureConnection StatusCode = 472
|
||||
StatusInternalServerError StatusCode = 500
|
||||
StatusNotImplemented StatusCode = 501
|
||||
StatusBadGateway StatusCode = 502
|
||||
StatusServiceUnavailable StatusCode = 503
|
||||
StatusGatewayTimeout StatusCode = 504
|
||||
StatusRTSPVersionNotSupported StatusCode = 505
|
||||
StatusOptionNotSupported StatusCode = 551
|
||||
StatusProxyUnavailable StatusCode = 553
|
||||
)
|
||||
|
||||
// Response is a RTSP response.
|
||||
type Response struct {
|
||||
StatusCode StatusCode
|
||||
|
@@ -1,54 +0,0 @@
|
||||
package gortsplib
|
||||
|
||||
// StatusCode is a RTSP response status code.
|
||||
type StatusCode int
|
||||
|
||||
const (
|
||||
StatusContinue StatusCode = 100
|
||||
StatusOK StatusCode = 200
|
||||
StatusMovedPermanently StatusCode = 301
|
||||
StatusFound StatusCode = 302
|
||||
StatusSeeOther StatusCode = 303
|
||||
StatusNotModified StatusCode = 304
|
||||
StatusUseProxy StatusCode = 305
|
||||
StatusBadRequest StatusCode = 400
|
||||
StatusUnauthorized StatusCode = 401
|
||||
StatusPaymentRequired StatusCode = 402
|
||||
StatusForbidden StatusCode = 403
|
||||
StatusNotFound StatusCode = 404
|
||||
StatusMethodNotAllowed StatusCode = 405
|
||||
StatusNotAcceptable StatusCode = 406
|
||||
StatusProxyAuthRequired StatusCode = 407
|
||||
StatusRequestTimeout StatusCode = 408
|
||||
StatusGone StatusCode = 410
|
||||
StatusPreconditionFailed StatusCode = 412
|
||||
StatusRequestEntityTooLarge StatusCode = 413
|
||||
StatusRequestURITooLong StatusCode = 414
|
||||
StatusUnsupportedMediaType StatusCode = 415
|
||||
StatusParameterNotUnderstood StatusCode = 451
|
||||
StatusNotEnoughBandwidth StatusCode = 453
|
||||
StatusSessionNotFound StatusCode = 454
|
||||
StatusMethodNotValidInThisState StatusCode = 455
|
||||
StatusHeaderFieldNotValidForResource StatusCode = 456
|
||||
StatusInvalidRange StatusCode = 457
|
||||
StatusParameterIsReadOnly StatusCode = 458
|
||||
StatusAggregateOperationNotAllowed StatusCode = 459
|
||||
StatusOnlyAggregateOperationAllowed StatusCode = 460
|
||||
StatusUnsupportedTransport StatusCode = 461
|
||||
StatusDestinationUnreachable StatusCode = 462
|
||||
StatusDestinationProhibited StatusCode = 463
|
||||
StatusDataTransportNotReadyYet StatusCode = 464
|
||||
StatusNotificationReasonUnknown StatusCode = 465
|
||||
StatusKeyManagementError StatusCode = 466
|
||||
StatusConnectionAuthorizationRequired StatusCode = 470
|
||||
StatusConnectionCredentialsNotAccepted StatusCode = 471
|
||||
StatusFailureToEstablishSecureConnection StatusCode = 472
|
||||
StatusInternalServerError StatusCode = 500
|
||||
StatusNotImplemented StatusCode = 501
|
||||
StatusBadGateway StatusCode = 502
|
||||
StatusServiceUnavailable StatusCode = 503
|
||||
StatusGatewayTimeout StatusCode = 504
|
||||
StatusRTSPVersionNotSupported StatusCode = 505
|
||||
StatusOptionNotSupported StatusCode = 551
|
||||
StatusProxyUnavailable StatusCode = 553
|
||||
)
|
Reference in New Issue
Block a user