From 078284936cd866552d4cde728c82ff0c9e4f4ba5 Mon Sep 17 00:00:00 2001 From: poning Date: Fri, 1 Aug 2025 15:35:03 -0700 Subject: [PATCH] fix(offlinehttp): Replace "-" in headers with "_" for DSL variables (#6363) * Replace "-" in headers with "_" for DSL variables in passive mode * test(offlinehttp): adjust haystack & needle in `TestHTTPOperatorExtract` Signed-off-by: Dwi Siswanto --------- Signed-off-by: Dwi Siswanto Co-authored-by: Dwi Siswanto --- pkg/protocols/offlinehttp/operators.go | 2 +- pkg/protocols/offlinehttp/operators_test.go | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/pkg/protocols/offlinehttp/operators.go b/pkg/protocols/offlinehttp/operators.go index cbce83cb6..3164c086a 100644 --- a/pkg/protocols/offlinehttp/operators.go +++ b/pkg/protocols/offlinehttp/operators.go @@ -109,7 +109,7 @@ func (request *Request) responseToDSLMap(resp *http.Response, host, matched, raw data[strings.ToLower(cookie.Name)] = cookie.Value } for k, v := range resp.Header { - k = strings.ToLower(strings.TrimSpace(k)) + k = strings.ToLower(strings.ReplaceAll(strings.TrimSpace(k), "-", "_")) data[k] = strings.Join(v, " ") } diff --git a/pkg/protocols/offlinehttp/operators_test.go b/pkg/protocols/offlinehttp/operators_test.go index 21bb86939..4fb8c39f7 100644 --- a/pkg/protocols/offlinehttp/operators_test.go +++ b/pkg/protocols/offlinehttp/operators_test.go @@ -134,7 +134,7 @@ func TestHTTPOperatorExtract(t *testing.T) { event := request.responseToDSLMap(resp, host, matched, exampleRawRequest, exampleRawResponse, exampleResponseBody, exampleResponseHeader, 1*time.Second, map[string]interface{}{}) require.Len(t, event, 14, "could not get correct number of items in dsl map") require.Equal(t, exampleRawResponse, event["response"], "could not get correct resp") - require.Equal(t, "Test-Response", event["test-header"], "could not get correct resp for header") + require.Equal(t, "Test-Response", event["test_header"], "could not get correct resp for header") t.Run("extract", func(t *testing.T) { extractor := &extractors.Extractor{ @@ -153,7 +153,7 @@ func TestHTTPOperatorExtract(t *testing.T) { t.Run("kval", func(t *testing.T) { extractor := &extractors.Extractor{ Type: extractors.ExtractorTypeHolder{ExtractorType: extractors.KValExtractor}, - KVal: []string{"test-header"}, + KVal: []string{"test_header"}, Part: "header", } err = extractor.CompileExtractors()