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 <git@dw1.io>

---------

Signed-off-by: Dwi Siswanto <git@dw1.io>
Co-authored-by: Dwi Siswanto <git@dw1.io>
This commit is contained in:
poning 2025-08-01 15:35:03 -07:00 committed by Ice3man
parent 434f6d32fc
commit 078284936c
2 changed files with 3 additions and 3 deletions

View File

@ -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, " ")
}

View File

@ -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()