Skip to content

Commit

Permalink
Address pull request review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
adatzer committed Mar 27, 2024
1 parent f3c68b6 commit eed385b
Show file tree
Hide file tree
Showing 9 changed files with 298 additions and 269 deletions.
5 changes: 2 additions & 3 deletions pkg/models/message.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import (
type Message struct {
PartitionKey string
Data []byte
HTTPHeaders map[string][]string
HTTPHeaders map[string]string

// TimeCreated is when the message was created originally
TimeCreated time.Time
Expand Down Expand Up @@ -54,12 +54,11 @@ func (m *Message) GetError() error {

func (m *Message) String() string {
return fmt.Sprintf(
"PartitionKey:%s,TimeCreated:%v,TimePulled:%v,TimeTransformed:%v,HttpHeaders:%v,Data:%s",
"PartitionKey:%s,TimeCreated:%v,TimePulled:%v,TimeTransformed:%v,Data:%s",
m.PartitionKey,
m.TimeCreated,
m.TimePulled,
m.TimeTransformed,
m.HTTPHeaders,
string(m.Data),
)
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/models/message_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ func TestMessageString(t *testing.T) {
PartitionKey: "some-key",
}

assert.Equal("PartitionKey:some-key,TimeCreated:0001-01-01 00:00:00 +0000 UTC,TimePulled:0001-01-01 00:00:00 +0000 UTC,TimeTransformed:0001-01-01 00:00:00 +0000 UTC,HttpHeaders:map[],Data:Hello World!", msg.String())
assert.Equal("PartitionKey:some-key,TimeCreated:0001-01-01 00:00:00 +0000 UTC,TimePulled:0001-01-01 00:00:00 +0000 UTC,TimeTransformed:0001-01-01 00:00:00 +0000 UTC,Data:Hello World!", msg.String())
assert.Nil(msg.GetError())
assert.Nil(msg.HTTPHeaders)

Expand Down
10 changes: 4 additions & 6 deletions pkg/target/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,15 +78,13 @@ func getHeaders(headers string) (map[string]string, error) {
return parsed, nil
}

func addHeadersToRequest(request *http.Request, headers map[string]string, dynamicHeaders map[string][]string) {
func addHeadersToRequest(request *http.Request, headers map[string]string, dynamicHeaders map[string]string) {
for key, value := range headers {
request.Header.Add(key, value)
}

for key, values := range dynamicHeaders {
for _, val := range values {
request.Header.Add(key, val)
}
for key, value := range dynamicHeaders {
request.Header.Add(key, value)
}
}

Expand Down Expand Up @@ -258,7 +256,7 @@ func (ht *HTTPTarget) GetID() string {
return ht.httpURL
}

func (ht *HTTPTarget) retrieveHeaders(msg *models.Message) map[string][]string {
func (ht *HTTPTarget) retrieveHeaders(msg *models.Message) map[string]string {
if !ht.dynamicHeaders {
return nil
}
Expand Down
43 changes: 21 additions & 22 deletions pkg/target/http_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ func TestRetrieveHeaders(t *testing.T) {
Name string
Msg *models.Message
Dynamic bool
Expected map[string][]string
Expected map[string]string
}{
{
Name: "message_headers_nil_dynamic_false",
Expand All @@ -110,24 +110,24 @@ func TestRetrieveHeaders(t *testing.T) {
{
Name: "message_headers_empty_dynamic_false",
Msg: &models.Message{
HTTPHeaders: map[string][]string{},
HTTPHeaders: map[string]string{},
},
Dynamic: false,
Expected: nil,
},
{
Name: "message_headers_empty_dynamic_true",
Msg: &models.Message{
HTTPHeaders: map[string][]string{},
HTTPHeaders: map[string]string{},
},
Dynamic: true,
Expected: map[string][]string{},
Expected: map[string]string{},
},
{
Name: "message_headers_non_empty_dynamic_false",
Msg: &models.Message{
HTTPHeaders: map[string][]string{
"foo": {"bar"},
HTTPHeaders: map[string]string{
"foo": "bar",
},
},
Dynamic: false,
Expand All @@ -136,12 +136,12 @@ func TestRetrieveHeaders(t *testing.T) {
{
Name: "message_headers_non_empty_dynamic_true",
Msg: &models.Message{
HTTPHeaders: map[string][]string{
"foo": {"bar", "baz"},
HTTPHeaders: map[string]string{
"foo": "bar",
},
},
Dynamic: true,
Expected: map[string][]string{"foo": {"bar", "baz"}},
Expected: map[string]string{"foo": "bar"},
},
}

Expand Down Expand Up @@ -203,7 +203,7 @@ func TestAddHeadersToRequest_WithDynamicHeaders(t *testing.T) {
testCases := []struct {
Name string
ConfigHeaders map[string]string
DynamicHeaders map[string][]string
DynamicHeaders map[string]string
ExpectedHeader http.Header
}{
{
Expand All @@ -215,17 +215,17 @@ func TestAddHeadersToRequest_WithDynamicHeaders(t *testing.T) {
{
Name: "config_nil_dynamic_empty",
ConfigHeaders: nil,
DynamicHeaders: map[string][]string{},
DynamicHeaders: map[string]string{},
ExpectedHeader: http.Header{},
},
{
Name: "config_nil_dynamic_yes",
ConfigHeaders: nil,
DynamicHeaders: map[string][]string{
"Content-Length": {"0", "1"},
DynamicHeaders: map[string]string{
"Content-Length": "0",
},
ExpectedHeader: http.Header{
"Content-Length": {"0", "1"},
"Content-Length": {"0"},
},
},
{
Expand All @@ -243,7 +243,7 @@ func TestAddHeadersToRequest_WithDynamicHeaders(t *testing.T) {
ConfigHeaders: map[string]string{
"Max Forwards": "10",
},
DynamicHeaders: map[string][]string{},
DynamicHeaders: map[string]string{},
ExpectedHeader: http.Header{
"Max Forwards": {"10"},
},
Expand All @@ -253,13 +253,12 @@ func TestAddHeadersToRequest_WithDynamicHeaders(t *testing.T) {
ConfigHeaders: map[string]string{
"Max Forwards": "10",
},
DynamicHeaders: map[string][]string{
"Content-Length": {"0", "1"},
"Empty": {},
DynamicHeaders: map[string]string{
"Content-Length": "0",
},
ExpectedHeader: http.Header{
"Max Forwards": {"10"},
"Content-Length": {"0", "1"},
"Content-Length": {"0"},
},
},
{
Expand All @@ -268,9 +267,9 @@ func TestAddHeadersToRequest_WithDynamicHeaders(t *testing.T) {
"Max Forwards": "10",
"Content-Length": "0",
},
DynamicHeaders: map[string][]string{
"Content-Length": {"1"},
"Test-Header": {"test"},
DynamicHeaders: map[string]string{
"Content-Length": "1",
"Test-Header": "test",
},
ExpectedHeader: http.Header{
"Max Forwards": {"10"},
Expand Down
2 changes: 1 addition & 1 deletion pkg/transform/engine/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,5 +41,5 @@ type engineProtocol struct {
FilterOut bool
PartitionKey string
Data interface{}
HTTPHeaders map[string][]string
HTTPHeaders map[string]string
}
4 changes: 3 additions & 1 deletion pkg/transform/engine/engine_javascript.go
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,9 @@ func (e *JSEngine) MakeFunction(funcName string) transform.TransformationFunctio
}

// HTTPHeaders
message.HTTPHeaders = protocol.HTTPHeaders
if len(protocol.HTTPHeaders) > 0 {
message.HTTPHeaders = protocol.HTTPHeaders
}

return message, nil, nil, protocol
}
Expand Down
Loading

0 comments on commit eed385b

Please sign in to comment.