Skip to content

Commit

Permalink
Merge pull request #616 from krakendio/check_req_body
Browse files Browse the repository at this point in the history
check that the request body is passed to the backend
  • Loading branch information
kpacha authored Nov 3, 2022
2 parents db4fb37 + 1864c69 commit e61271c
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 5 deletions.
2 changes: 1 addition & 1 deletion tests/fixtures/krakend.json
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@
"backend": [
{
"host": [ "http://127.0.0.1:8081" ],
"url_pattern": "/param_forwarding/{bar}?foo={foo}"
"url_pattern": "/param_forwarding/{bar}?foo={foo}&dump_body=1"
}
]
},
Expand Down
20 changes: 18 additions & 2 deletions tests/fixtures/specs/param_forwarding_4.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,27 @@
"autHoriZatiOn": "bearer 123456",
"x-y-Z": "true",
"a-b-c": "ignore"
}
},
"body": {"foo":"bar"}
},
"out": {
"status_code": 200,
"body": "{\"foo\":42,\"headers\":{\"Accept-Encoding\":[\"gzip\"],\"Authorization\":[\"bearer 123456\"],\"Content-Length\":[\"0\"],\"User-Agent\":[\"KrakenD Version 2.1.2\"],\"X-Forwarded-Host\":[\"localhost:8080\"],\"X-Y-Z\":[\"true\"]},\"path\":\"/param_forwarding/bar\",\"query\":{\"foo\":[\"foo\"]}}",
"body": {
"body": "{\"foo\":\"bar\"}",
"foo":42,
"headers":{
"Accept-Encoding":["gzip"],
"Authorization":["bearer 123456"],
"User-Agent":["KrakenD Version 2.1.2"],
"X-Forwarded-Host":["localhost:8080"],
"X-Y-Z":["true"]
},
"path":"/param_forwarding/bar",
"query":{
"dump_body":["1"],
"foo":["foo"]
}
},
"header": {
"content-type": ["application/json; charset=utf-8"],
"Cache-Control": ["public, max-age=3600"],
Expand Down
12 changes: 10 additions & 2 deletions tests/integration.go
Original file line number Diff line number Diff line change
Expand Up @@ -478,12 +478,20 @@ func echoEndpoint(rw http.ResponseWriter, r *http.Request) {
rw.Header().Add("Set-Cookie", "test1=test1")
rw.Header().Add("Set-Cookie", "test2=test2")
r.Header.Del("X-Forwarded-For")
json.NewEncoder(rw).Encode(map[string]interface{}{
resp := map[string]interface{}{
"path": r.URL.Path,
"query": r.URL.Query(),
"headers": r.Header,
"foo": 42,
})
}

if r.URL.Query().Get("dump_body") == "1" {
b, _ := io.ReadAll(r.Body)
r.Body.Close()
resp["body"] = string(b)
}

json.NewEncoder(rw).Encode(resp)
}

func redirectEndpoint(rw http.ResponseWriter, r *http.Request) {
Expand Down

0 comments on commit e61271c

Please sign in to comment.