Skip to content

Commit

Permalink
doc: fix wrong filter name
Browse files Browse the repository at this point in the history
fix: strict args handling
test: chaining should also work

Signed-off-by: Sandor Szücs <sandor.szuecs@zalando.de>
  • Loading branch information
szuecs committed Jan 5, 2024
1 parent 58db930 commit d5f360b
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 4 deletions.
6 changes: 3 additions & 3 deletions docs/reference/filters.md
Original file line number Diff line number Diff line change
Expand Up @@ -746,9 +746,9 @@ Parameters:
Example:

```
* -> logHeader("request") -> "https://www.example.org";
* -> logHeader("response") -> "https://www.example.org";
* -> logHeader("request", "response") -> "https://www.example.org";
* -> logBody("request") -> "https://www.example.org";
* -> logBody("response") -> "https://www.example.org";
* -> logBody("request", "response") -> "https://www.example.org";
```

## Timeout
Expand Down
2 changes: 1 addition & 1 deletion filters/diag/logbody.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ func (logBody) CreateFilter(args []interface{}) (filters.Filter, error) {
response = false
)

if len(args) == 0 {
if len(args) == 0 || len(args) > 2 {
return nil, filters.ErrInvalidFilterParameters
}

Expand Down
33 changes: 33 additions & 0 deletions filters/diag/logbody_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,39 @@ func TestLogBody(t *testing.T) {
io.Copy(io.Discard, rsp.Body)
log.SetOutput(os.Stderr)

got := logbuf.String()
if !strings.Contains(got, requestContent) {
t.Fatalf("Failed to find req %q log, got: %q", requestContent, got)
}
// repeatContent("a", 10)
if !strings.Contains(got, "aaaaaaaaaa") {
t.Fatalf("Failed to find %q log, got: %q", "aaaaaaaaaa", got)
}
})
t.Run("Request-response chaining", func(t *testing.T) {
beRoutes := eskip.MustParse(`r: * -> repeatContent("a", 10) -> <shunt>`)
fr := make(filters.Registry)
fr.Register(NewLogBody())
fr.Register(NewRepeat())
be := proxytest.New(fr, beRoutes...)
defer be.Close()

routes := eskip.MustParse(fmt.Sprintf(`r: * -> logBody("request") -> logBody("response") -> "%s"`, be.URL))
p := proxytest.New(fr, routes...)
defer p.Close()

requestContent := "testrequestresponsechain"
logbuf := bytes.NewBuffer(nil)
log.SetOutput(logbuf)
buf := bytes.NewBufferString(requestContent)
rsp, err := http.DefaultClient.Post(p.URL, "text/plain", buf)
if err != nil {
t.Fatalf("Failed to get respone: %v", err)
}
defer rsp.Body.Close()
io.Copy(io.Discard, rsp.Body)
log.SetOutput(os.Stderr)

got := logbuf.String()
if !strings.Contains(got, requestContent) {
t.Fatalf("Failed to find req %q log, got: %q", requestContent, got)
Expand Down

0 comments on commit d5f360b

Please sign in to comment.