Skip to content

Commit

Permalink
feat: Add server response header for HTTP source node
Browse files Browse the repository at this point in the history
  • Loading branch information
Matovidlo authored and michaljurecko committed Sep 3, 2024
1 parent feb5746 commit 4da1cae
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ func Start(ctx context.Context, d dependencies, cfg Config) error {

// Route import requests to the dispatcher
router.Post("/stream/<projectID>/<sourceID>/<secret>", func(c *routing.Context) error {
c.Response.Header.Set("Server", "Keboola stream HTTP source")
// Get parameters
projectIDStr := c.Param("projectID")
projectIDInt, err := strconv.Atoi(projectIDStr)
Expand Down
17 changes: 15 additions & 2 deletions internal/pkg/service/stream/source/httpsource/httpsource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,7 @@ func testCases(t *testing.T, ts *testState) []TestCase {
ExpectedStatusCode: http.StatusAccepted,
ExpectedHeaders: map[string]string{
"Content-Type": "text/plain",
"Server": "Keboola stream HTTP source",
},
ExpectedBody: "OK",
},
Expand All @@ -395,6 +396,7 @@ func testCases(t *testing.T, ts *testState) []TestCase {
ExpectedStatusCode: http.StatusOK,
ExpectedHeaders: map[string]string{
"Content-Type": "text/plain",
"Server": "Keboola stream HTTP source",
},
ExpectedBody: "OK",
},
Expand All @@ -411,6 +413,9 @@ func testCases(t *testing.T, ts *testState) []TestCase {
Query: "verbose=true",
Body: strings.NewReader(strings.Repeat(".", ts.maxBodySize)),
ExpectedStatusCode: http.StatusAccepted,
ExpectedHeaders: map[string]string{
"Server": "Keboola stream HTTP source",
},
ExpectedBody: `
{
"statusCode": 202,
Expand Down Expand Up @@ -460,6 +465,9 @@ func testCases(t *testing.T, ts *testState) []TestCase {
Query: "verbose=true",
Body: strings.NewReader(strings.Repeat(".", ts.maxBodySize)),
ExpectedStatusCode: http.StatusOK,
ExpectedHeaders: map[string]string{
"Server": "Keboola stream HTTP source",
},
ExpectedBody: `
{
"statusCode": 200,
Expand Down Expand Up @@ -502,7 +510,8 @@ func testCases(t *testing.T, ts *testState) []TestCase {
Path: "/stream/123/my-source-1/" + ts.validSecret,
Headers: map[string]string{"foo": strings.Repeat(".", ts.maxHeaderSize+1)},
ExpectedStatusCode: http.StatusRequestEntityTooLarge,
ExpectedLogs: `{"level":"info","message":"request header size is over the maximum \"2000B\"","error.type":"%s/errors.HeaderTooLargeError"}`,
// No expected Server headers, fasthttp internal return
ExpectedLogs: `{"level":"info","message":"request header size is over the maximum \"2000B\"","error.type":"%s/errors.HeaderTooLargeError"}`,
ExpectedBody: `
{
"statusCode": 413,
Expand All @@ -516,7 +525,8 @@ func testCases(t *testing.T, ts *testState) []TestCase {
Path: "/stream/123/my-source/" + ts.validSecret,
Body: strings.NewReader(strings.Repeat(".", ts.maxBodySize+1)),
ExpectedStatusCode: http.StatusRequestEntityTooLarge,
ExpectedLogs: `{"level":"info","message":"request body size is over the maximum \"8000B\"","error.type":"%s/errors.BodyTooLargeError"}`,
// No expected Server headers, fasthttp internal return
ExpectedLogs: `{"level":"info","message":"request body size is over the maximum \"8000B\"","error.type":"%s/errors.BodyTooLargeError"}`,
ExpectedBody: `
{
"statusCode": 413,
Expand Down Expand Up @@ -544,6 +554,9 @@ func testCases(t *testing.T, ts *testState) []TestCase {
Query: "verbose=true",
Body: strings.NewReader("foo"),
ExpectedStatusCode: http.StatusOK,
ExpectedHeaders: map[string]string{
"Server": "Keboola stream HTTP source",
},
ExpectedBody: `
{
"statusCode": 200,
Expand Down

0 comments on commit 4da1cae

Please sign in to comment.