Skip to content

Commit

Permalink
Fix http client header duplicates
Browse files Browse the repository at this point in the history
  • Loading branch information
Jeffail committed Sep 30, 2022
1 parent 6915eaa commit fa80f4b
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 22 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ All notable changes to this project will be documented in this file.

## Unreleased

## 4.8.0 - 2022-09-30

### Added

- All `sql` components now support Oracle DB.
Expand All @@ -13,6 +15,7 @@ All notable changes to this project will be documented in this file.

- All SQL components now accept an empty or unspecified `args_mapping` as an alias for no arguments.
- Field `unsafe_dynamic_query` added to the `sql_raw` output.
- Fixed a regression in 4.7.0 where HTTP client components were sending duplicate request headers.

## 4.7.0 - 2022-09-27

Expand Down
22 changes: 0 additions & 22 deletions internal/httpclient/request.go
Original file line number Diff line number Diff line change
Expand Up @@ -224,28 +224,6 @@ func (r *RequestCreator) Create(refBatch message.Batch) (req *http.Request, err
req.Header.Add("Content-Type", overrideContentType)
}

if err = r.reqSigner(req); err != nil {
return
}

for k, v := range r.headers {
req.Header.Add(k, v.String(0, refBatch))
}
if len(refBatch) > 0 {
_ = r.metaInsertFilter.Iter(refBatch[0], func(k, v string) error {
req.Header.Add(k, v)
return nil
})
}

if r.host != nil {
req.Host = r.host.String(0, refBatch)
}
if overrideContentType != "" {
req.Header.Del("Content-Type")
req.Header.Add("Content-Type", overrideContentType)
}

err = r.reqSigner(req)
return
}
34 changes: 34 additions & 0 deletions internal/httpclient/request_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package httpclient

import (
"testing"

"github.com/benthosdev/benthos/v4/internal/httpclient/oldconfig"
"github.com/benthosdev/benthos/v4/internal/manager/mock"
"github.com/benthosdev/benthos/v4/internal/message"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)

func TestSingleMessageHeaders(t *testing.T) {
oldConf := oldconfig.NewOldConfig()
oldConf.Headers["Content-Type"] = "foo"
oldConf.Metadata.IncludePrefixes = []string{"more_"}

reqCreator, err := RequestCreatorFromOldConfig(oldConf, mock.NewManager())
require.NoError(t, err)

part := message.NewPart([]byte("hello world"))
part.MetaSet("more_bar", "barvalue")
part.MetaSet("ignore_baz", "bazvalue")

b := message.Batch{part}

req, err := reqCreator.Create(b)
require.NoError(t, err)

assert.Equal(t, []string{"foo"}, req.Header.Values("Content-Type"))
assert.Equal(t, []string{"barvalue"}, req.Header.Values("more_bar"))
assert.Equal(t, []string(nil), req.Header.Values("ignore_baz"))
}

0 comments on commit fa80f4b

Please sign in to comment.