mirror of https://bitbucket.org/ausocean/av.git
protocol/rtsp: using Fprintf with strings.Builder in Request.String() and Response.String()
This commit is contained in:
parent
960d0b4477
commit
a025d55d81
|
@ -81,10 +81,10 @@ func (r *Request) Write(w io.Writer) error {
|
||||||
// String returns a formatted string of the Request.
|
// String returns a formatted string of the Request.
|
||||||
func (r Request) String() string {
|
func (r Request) String() string {
|
||||||
var b strings.Builder
|
var b strings.Builder
|
||||||
b.WriteString(r.Method + " " + r.URL.String() + " " + r.Proto + "/" + strconv.Itoa(r.ProtoMajor) + "." + strconv.Itoa(r.ProtoMinor) + "\r\n")
|
fmt.Fprintf(&b, "%s %s %s/%d.%d\r\n", r.Method, r.URL.String(), r.Proto, r.ProtoMajor, r.ProtoMinor)
|
||||||
for k, v := range r.Header {
|
for k, v := range r.Header {
|
||||||
for _, v := range v {
|
for _, v := range v {
|
||||||
b.WriteString(k + ": " + v + "\r\n")
|
fmt.Fprintf(&b, "%s: %s\r\n", k, v)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
b.WriteString("\r\n")
|
b.WriteString("\r\n")
|
||||||
|
@ -109,10 +109,10 @@ type Response struct {
|
||||||
// String returns a formatted string of the Response.
|
// String returns a formatted string of the Response.
|
||||||
func (r Response) String() string {
|
func (r Response) String() string {
|
||||||
var b strings.Builder
|
var b strings.Builder
|
||||||
b.WriteString(r.Proto + "/" + strconv.Itoa(r.ProtoMajor) + "." + strconv.Itoa(r.ProtoMinor) + " " + strconv.Itoa(r.StatusCode) + "\n")
|
fmt.Fprintf(&b, "%s/%d.%d %d\n", r.Proto, r.ProtoMajor, r.ProtoMinor, r.StatusCode)
|
||||||
for k, v := range r.Header {
|
for k, v := range r.Header {
|
||||||
for _, v := range v {
|
for _, v := range v {
|
||||||
b.WriteString(k + ": " + v + "\n")
|
fmt.Fprintf(&b, "%s: %s", k, v)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return b.String()
|
return b.String()
|
||||||
|
|
Loading…
Reference in New Issue