diff options
Diffstat (limited to 'message.go')
-rw-r--r-- | message.go | 15 |
1 files changed, 8 insertions, 7 deletions
@@ -31,7 +31,7 @@ func NewMessage(intent string, body io.Reader) *Message { // ParseMessage parses a CNP message. // -// The message's Body field is set to a bufio.Reader wrapping r. If r is a +// The message's Body field is set to a bufio.Reader wrapping r. If r is an // io.Closer, it is also stored separately for usage with Message.Close(). func ParseMessage(r io.Reader) (*Message, error) { br := bufio.NewReader(r) @@ -77,7 +77,7 @@ func (msg *Message) Close() error { // ComputeLength sets the length header parameter based on the message body. // First, msg.TryComputeLength() is attempted; if that fails, the request is -// fully read into a buffer and msg.Body is set to a bytes.Reader. +// fully read into a bytes.Buffer and msg.Body is set to it. func (msg *Message) ComputeLength() error { if !msg.TryComputeLength() { buf, err := ioutil.ReadAll(msg.Body) @@ -94,9 +94,10 @@ func (msg *Message) ComputeLength() error { } // TryComputeLength sets the length header parameter to the length of the -// message body if it's one of *bytes.Buffer, *bytes.Reader or *strings.Reader -// and returns true. If msg.Body is nil, the length parameter is unset and the -// function returns true. Otherwise, false is returned. +// message body if the body's type is one of *bytes.Buffer, *bytes.Reader or +// *strings.Reader and returns true. If msg.Body is nil, the length parameter +// is unset and the function returns true. Otherwise, false is returned and the +// length parameter remains unchanged. func (msg *Message) TryComputeLength() bool { switch v := msg.Body.(type) { case *bytes.Buffer: @@ -131,13 +132,13 @@ func (msg *Message) Length() int64 { return n } -// Param retrieves a header parameter. +// Param retrieves a header parameter. It performs no value validation. func (msg *Message) Param(key string) string { return msg.Header.Parameters[key] } // SetParam sets a header parameter. If the value is empty, the parameter is -// unset. +// unset. It performs no value validation. func (msg *Message) SetParam(key, value string) { if len(value) == 0 { delete(msg.Header.Parameters, key) |