client: allow UserAgent to be set (#119)

* client: allow UserAgent to be set

* client: fix out of date comment
This commit is contained in:
Tristan Matthews
2022-04-15 07:32:34 -04:00
committed by GitHub
parent 9070fde205
commit 2f8186c11a

View File

@@ -184,8 +184,11 @@ type Client struct {
ReadBufferCount int ReadBufferCount int
// write buffer count. // write buffer count.
// It allows to queue packets before sending them. // It allows to queue packets before sending them.
// It defaults to 8. // It defaults to 256.
WriteBufferCount int WriteBufferCount int
// user agent header
// It defaults to "gortsplib"
UserAgent string
// //
// system functions // system functions
@@ -285,6 +288,9 @@ func (c *Client) Start(scheme string, host string) error {
if c.WriteBufferCount == 0 { if c.WriteBufferCount == 0 {
c.WriteBufferCount = 256 c.WriteBufferCount = 256
} }
if c.UserAgent == "" {
c.UserAgent = "gortsplib"
}
// system functions // system functions
if c.DialContext == nil { if c.DialContext == nil {
@@ -1037,7 +1043,7 @@ func (c *Client) do(req *base.Request, skipResponse bool, allowFrames bool) (*ba
c.cseq++ c.cseq++
req.Header["CSeq"] = base.HeaderValue{strconv.FormatInt(int64(c.cseq), 10)} req.Header["CSeq"] = base.HeaderValue{strconv.FormatInt(int64(c.cseq), 10)}
req.Header["User-Agent"] = base.HeaderValue{"gortsplib"} req.Header["User-Agent"] = base.HeaderValue{c.UserAgent}
if c.sender != nil { if c.sender != nil {
c.sender.AddAuthorization(req) c.sender.AddAuthorization(req)