include RawLines in Response
This commit is contained in:
parent
a7a9158e85
commit
332fc001df
15
response.go
15
response.go
|
@ -11,6 +11,7 @@ import (
|
||||||
"log"
|
"log"
|
||||||
"net/textproto"
|
"net/textproto"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Response is a response to a control port command, or an asyncrhonous event.
|
// Response is a response to a control port command, or an asyncrhonous event.
|
||||||
|
@ -27,6 +28,9 @@ type Response struct {
|
||||||
// data is "decoded" and presented as a single string (terminal ".CRLF"
|
// data is "decoded" and presented as a single string (terminal ".CRLF"
|
||||||
// removed, all intervening CRs stripped).
|
// removed, all intervening CRs stripped).
|
||||||
Data []string
|
Data []string
|
||||||
|
|
||||||
|
// RawLines is all of the lines of a response, without CRLFs.
|
||||||
|
RawLines []string
|
||||||
}
|
}
|
||||||
|
|
||||||
// IsOk returns true if the response status code indicates success or
|
// IsOk returns true if the response status code indicates success or
|
||||||
|
@ -77,11 +81,15 @@ func (c *Conn) ReadResponse() (*Response, error) {
|
||||||
// lines.
|
// lines.
|
||||||
return nil, newProtocolError("status code changed: %03d != %03d", code, statusCode)
|
return nil, newProtocolError("status code changed: %03d != %03d", code, statusCode)
|
||||||
}
|
}
|
||||||
|
if resp.RawLines == nil {
|
||||||
|
resp.RawLines = make([]string, 0, 1)
|
||||||
|
}
|
||||||
|
|
||||||
if line[3] == ' ' {
|
if line[3] == ' ' {
|
||||||
// Final line in the response.
|
// Final line in the response.
|
||||||
resp.Reply = line[4:]
|
resp.Reply = line[4:]
|
||||||
resp.Err = statusCodeToError(statusCode, resp.Reply)
|
resp.Err = statusCodeToError(statusCode, resp.Reply)
|
||||||
|
resp.RawLines = append(resp.RawLines, line)
|
||||||
return resp, nil
|
return resp, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -92,9 +100,11 @@ func (c *Conn) ReadResponse() (*Response, error) {
|
||||||
case '-':
|
case '-':
|
||||||
// Continuation, keep reading.
|
// Continuation, keep reading.
|
||||||
resp.Data = append(resp.Data, line[4:])
|
resp.Data = append(resp.Data, line[4:])
|
||||||
|
resp.RawLines = append(resp.RawLines, line)
|
||||||
case '+':
|
case '+':
|
||||||
// A "dot-encoded" payload follows.
|
// A "dot-encoded" payload follows.
|
||||||
resp.Data = append(resp.Data, line[4:])
|
resp.Data = append(resp.Data, line[4:])
|
||||||
|
resp.RawLines = append(resp.RawLines, line)
|
||||||
dotBody, err := c.conn.ReadDotBytes()
|
dotBody, err := c.conn.ReadDotBytes()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
@ -103,6 +113,11 @@ func (c *Conn) ReadResponse() (*Response, error) {
|
||||||
log.Printf("S: [dot encoded data]")
|
log.Printf("S: [dot encoded data]")
|
||||||
}
|
}
|
||||||
resp.Data = append(resp.Data, string(dotBody))
|
resp.Data = append(resp.Data, string(dotBody))
|
||||||
|
dotLines := strings.Split(string(dotBody), "\n")
|
||||||
|
for _, dotLine := range dotLines[:len(dotLines)-1] {
|
||||||
|
resp.RawLines = append(resp.RawLines, dotLine)
|
||||||
|
}
|
||||||
|
resp.RawLines = append(resp.RawLines, ".")
|
||||||
default:
|
default:
|
||||||
return nil, newProtocolError("invalid separator: '%c'", line[3])
|
return nil, newProtocolError("invalid separator: '%c'", line[3])
|
||||||
}
|
}
|
||||||
|
|
Reference in New Issue