diff options
author | clsr <clsr@clsr.net> | 2017-08-25 17:04:42 +0200 |
---|---|---|
committer | clsr <clsr@clsr.net> | 2017-08-25 17:04:44 +0200 |
commit | 9ca364d8753a5f2c7529c5b3dd7178bfd51effc6 (patch) | |
tree | dc5ab072ffbbd37da910d440e05b5bc56dc3f6da /message.go | |
parent | ba217ddeef9c6cd502a6f150bf59cf3ce329cc61 (diff) | |
download | cnp-go-9ca364d8753a5f2c7529c5b3dd7178bfd51effc6.tar.gz cnp-go-9ca364d8753a5f2c7529c5b3dd7178bfd51effc6.zip |
Add support for the draft/cnp-select "select" request/response parameterv0.1.2
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) |