A delivery set Content-Type from the event's ContentType and then added the inbound Content-Type from the event's stored headers, so a target could receive two values. The inbound Content-Type is no longer forwarded from the stored headers; the receiver already saves it as the event's ContentType. Which value is sent is now stated at applyRequestHeaders: a Content-Type configured on the target, otherwise the event's ContentType, otherwise none. A configured one still survives a cross-origin 307/308 with its body. Model: opus-5-5
This commit was merged in pull request #331.
This commit is contained in:
@@ -1166,6 +1166,10 @@ func TestIsForwardableHeader(t *testing.T) {
|
||||
assert.False(t,
|
||||
delivery.ExportIsForwardableHeader("Content-Length"),
|
||||
)
|
||||
|
||||
assert.False(t,
|
||||
delivery.ExportIsForwardableHeader("Content-Type"),
|
||||
)
|
||||
}
|
||||
|
||||
func TestTruncate(t *testing.T) {
|
||||
@@ -1247,6 +1251,81 @@ func TestDoHTTPRequest_ForwardsHeaders(t *testing.T) {
|
||||
)
|
||||
}
|
||||
|
||||
// The event's stored inbound headers carry the same Content-Type the
|
||||
// receiver saved as the event's ContentType, so a delivery could send
|
||||
// it twice. It must go out exactly once, with a Content-Type configured
|
||||
// on the target winning, then the event's ContentType.
|
||||
func TestApplyRequestHeaders_SendsOneContentType(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
cases := map[string]struct {
|
||||
inbound string
|
||||
event string
|
||||
configured string
|
||||
want []string
|
||||
}{
|
||||
"inbound and event agree": {
|
||||
inbound: testContentType,
|
||||
event: testContentType,
|
||||
want: []string{testContentType},
|
||||
},
|
||||
"inbound and event disagree": {
|
||||
inbound: "text/plain",
|
||||
event: testContentType,
|
||||
want: []string{testContentType},
|
||||
},
|
||||
"event has none": {
|
||||
inbound: testContentType,
|
||||
want: nil,
|
||||
},
|
||||
"target configures its own": {
|
||||
inbound: testContentType,
|
||||
event: testContentType,
|
||||
configured: "application/xml",
|
||||
want: []string{"application/xml"},
|
||||
},
|
||||
}
|
||||
|
||||
for name, tc := range cases {
|
||||
t.Run(name, func(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
inbound, err := json.Marshal(map[string][]string{
|
||||
headerContentType: {tc.inbound},
|
||||
})
|
||||
require.NoError(t, err)
|
||||
|
||||
cfg := &delivery.HTTPTargetConfig{}
|
||||
if tc.configured != "" {
|
||||
cfg.Headers = map[string]string{
|
||||
headerContentType: tc.configured,
|
||||
}
|
||||
}
|
||||
|
||||
req, err := http.NewRequestWithContext(
|
||||
context.Background(),
|
||||
http.MethodPost,
|
||||
"https://target.example.com/hook",
|
||||
http.NoBody,
|
||||
)
|
||||
require.NoError(t, err)
|
||||
|
||||
delivery.ExportApplyRequestHeaders(
|
||||
req,
|
||||
&database.Event{
|
||||
Headers: string(inbound),
|
||||
ContentType: tc.event,
|
||||
},
|
||||
cfg,
|
||||
)
|
||||
|
||||
assert.Equal(t,
|
||||
tc.want, req.Header.Values(headerContentType),
|
||||
)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestProcessDelivery_RoutesToCorrectHandler(
|
||||
t *testing.T,
|
||||
) {
|
||||
|
||||
Reference in New Issue
Block a user