diff --git a/protocol/rtsp/rtsp.go b/protocol/rtsp/rtsp.go index 6789f428..1bcd55b1 100644 --- a/protocol/rtsp/rtsp.go +++ b/protocol/rtsp/rtsp.go @@ -31,7 +31,6 @@ package rtsp import ( "bufio" "errors" - "fmt" "io" "io/ioutil" "net/http" @@ -79,18 +78,19 @@ func (r *Request) Write(w io.Writer) error { // String returns a formatted string of the Request. func (r Request) String() string { - s := fmt.Sprintf("%s %s %s/%d.%d\r\n", r.Method, r.URL, r.Proto, r.ProtoMajor, r.ProtoMinor) + var b strings.Builder + b.WriteString(r.Method + " " + r.URL.String() + " " + r.Proto + "/" + strconv.Itoa(r.ProtoMajor) + "." + strconv.Itoa(r.ProtoMinor) + "\r\n") for k, v := range r.Header { for _, v := range v { - s += fmt.Sprintf("%s: %s\r\n", k, v) + b.WriteString(k + ": " + v + "\r\n") } } - s += "\r\n" + b.WriteString("\r\n") if r.Body != nil { - str, _ := ioutil.ReadAll(r.Body) - s += string(str) + s, _ := ioutil.ReadAll(r.Body) + b.WriteString(string(s)) } - return s + return b.String() } // Response describes an RTSP response. @@ -107,13 +107,14 @@ type Response struct { // String returns a formatted string of the Response. func (r Response) String() string { - s := fmt.Sprintf("%s/%d.%d %d %s\n", r.Proto, r.ProtoMajor, r.ProtoMinor, r.StatusCode, r.Status) + var b strings.Builder + b.WriteString(r.Proto + "/" + strconv.Itoa(r.ProtoMajor) + "." + strconv.Itoa(r.ProtoMinor) + " " + strconv.Itoa(r.StatusCode) + " " + r.Status + "\n") for k, v := range r.Header { for _, v := range v { - s += fmt.Sprintf("%s: %s\n", k, v) + b.WriteString(k + ": " + v + "\n") } } - return s + return b.String() } // ReadResponse will read the response of the RTSP request from the connection,