Don't create new message

This commit is contained in:
Asim 2016-10-29 21:33:04 +01:00
parent b3cdbaae1a
commit 6d35a663a4

View File

@ -155,6 +155,10 @@ func (h *httpTransportClient) Send(m *Message) error {
} }
func (h *httpTransportClient) Recv(m *Message) error { func (h *httpTransportClient) Recv(m *Message) error {
if m == nil {
return errors.New("message passed in is nil")
}
var r *http.Request var r *http.Request
if !h.dialOpts.Stream { if !h.dialOpts.Stream {
rc, ok := <-h.r rc, ok := <-h.r
@ -190,20 +194,20 @@ func (h *httpTransportClient) Recv(m *Message) error {
return errors.New(rsp.Status + ": " + string(b)) return errors.New(rsp.Status + ": " + string(b))
} }
mr := &Message{ m.Body = b
Header: make(map[string]string),
Body: b, if m.Header == nil {
m.Header = make(map[string]string)
} }
for k, v := range rsp.Header { for k, v := range rsp.Header {
if len(v) > 0 { if len(v) > 0 {
mr.Header[k] = v[0] m.Header[k] = v[0]
} else { } else {
mr.Header[k] = "" m.Header[k] = ""
} }
} }
*m = *mr
return nil return nil
} }
@ -239,17 +243,17 @@ func (h *httpTransportSocket) Recv(m *Message) error {
return err return err
} }
r.Body.Close() r.Body.Close()
m.Body = b
mr := &Message{ if m.Header == nil {
Header: make(map[string]string), m.Header = make(map[string]string)
Body: b,
} }
for k, v := range r.Header { for k, v := range r.Header {
if len(v) > 0 { if len(v) > 0 {
mr.Header[k] = v[0] m.Header[k] = v[0]
} else { } else {
mr.Header[k] = "" m.Header[k] = ""
} }
} }
@ -258,7 +262,6 @@ func (h *httpTransportSocket) Recv(m *Message) error {
default: default:
} }
*m = *mr
return nil return nil
} }