Skip to content

Commit

Permalink
When copying headers from context copy by value instead of reference (#…
Browse files Browse the repository at this point in the history
…94)

Signed-off-by: Scott Nichols <nicholss@google.com>
  • Loading branch information
n3wscott authored and markpeek committed Mar 27, 2019
1 parent b88e53e commit e00e75c
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
5 changes: 3 additions & 2 deletions pkg/cloudevents/transport/http/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,11 +147,12 @@ func ContextWithHeader(ctx context.Context, key, value string) context.Context {

// HeaderFrom extracts the header oject in the given context. Always returns a non-nil Header.
func HeaderFrom(ctx context.Context) http.Header {
ch := http.Header{}
header := ctx.Value(headerKey)
if header != nil {
if h, ok := header.(http.Header); ok {
return h
copyHeaders(h, ch)
}
}
return http.Header{}
return ch
}
2 changes: 2 additions & 0 deletions pkg/cloudevents/transport/http/transport.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,9 +163,11 @@ func (t *Transport) obsSend(ctx context.Context, event cloudevents.Event) (*clou

if m, ok := msg.(*Message); ok {
copyHeaders(m.Header, req.Header)

req.Body = ioutil.NopCloser(bytes.NewBuffer(m.Body))
req.ContentLength = int64(len(m.Body))
req.Close = true

return httpDo(ctx, t.Client, &req, func(resp *http.Response, err error) (*cloudevents.Event, error) {
if err != nil {
return nil, err
Expand Down

0 comments on commit e00e75c

Please sign in to comment.