Skip to content

Adding filenames from the zip to the response for httpjson #34044

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Dec 15, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.next.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,7 @@ https://github.com/elastic/beats/compare/v8.2.0\...main[Check the HEAD diff]
- Add metrics for UDP packet processing. {pull}33870[33870]
- Convert UDP input to v2 input. {pull}33930[33930]
- Improve collection of risk information from Okta debug data. {issue}33677[33677] {pull}34030[34030]
- Adding filename details from zip to response for httpjson {issue}33952[33952] {pull}34044[34044]

*Auditbeat*

Expand Down
7 changes: 7 additions & 0 deletions x-pack/filebeat/input/httpjson/encoding.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"encoding/json"
"errors"
"io"
"net/http"

"github.com/elastic/elastic-agent-libs/logp"
)
Expand Down Expand Up @@ -188,11 +189,13 @@ func decodeAsZip(p []byte, dst *response) error {
return err
}

names := make([]string, 0, len(r.File))
for _, f := range r.File {
rc, err := f.Open()
if err != nil {
return err
}
names = append(names, f.Name)

dec := json.NewDecoder(rc)
for dec.More() {
Expand All @@ -207,6 +210,10 @@ func decodeAsZip(p []byte, dst *response) error {
}

dst.body = results
if dst.header == nil { //nolint:errorlint // golangci-lint-action #624
dst.header = http.Header{}
}
dst.header["X-Zip-Files"] = names

return nil
}
4 changes: 3 additions & 1 deletion x-pack/filebeat/input/httpjson/encoding_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import (
func TestDecodeZip(t *testing.T) {
buf := new(bytes.Buffer)
w := zip.NewWriter(buf)
var files = []struct {
files := []struct {
Name, Body string
}{
{
Expand Down Expand Up @@ -57,6 +57,8 @@ func TestDecodeZip(t *testing.T) {
}

assert.Equal(t, expected, string(j))

assert.Equal(t, []string{"a.json", "b.ndjson", "c.ndjson"}, resp.header["X-Zip-Files"])
}

func TestDecodeNdjson(t *testing.T) {
Expand Down