Skip to content

Fix missing handler headers in resp #26

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 3 commits into from
Apr 12, 2023
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
2 changes: 1 addition & 1 deletion local/core.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ func CoreProcessing(httpResp http.ResponseWriter, httpReq *http.Request, handler

InjectEgressHeaders(httpResp)

// Exeute generated by subrt layer
core.SetHeaders(recorderResp.Header, httpResp.Header())

core.HydrateHTTPResponse(httpResp, responseBody, coreResp.StatusCode)
}
23 changes: 23 additions & 0 deletions local/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package local_test
import (
"fmt"
"io"
"math/rand"
"net/http"
"net/http/httputil"
"testing"
Expand All @@ -16,9 +17,15 @@ import (
func TestServSimpleResponse(t *testing.T) {
t.Parallel()

rand.Seed(time.Now().UnixNano())

const testingMessage = "simple test"

randHeaderKey := randStringRunes(t, 32)
randHeaderVal := randStringRunes(t, 32)

handler := func(w http.ResponseWriter, r *http.Request) {
w.Header().Add(randHeaderKey, randHeaderVal)
_, _ = w.Write([]byte(testingMessage))

assert.NotEmpty(t, r)
Expand Down Expand Up @@ -54,6 +61,7 @@ func TestServSimpleResponse(t *testing.T) {
assert.NotEmpty(t, resp.Header.Get("X-Envoy-External-Address"))
assert.Equal(t, "Content-Type", resp.Header.Get("Access-Control-Allow-Headers"))
assert.Equal(t, fmt.Sprintf("%d", (len(testingMessage))), resp.Header.Get("Content-Length"))
assert.Equal(t, randHeaderVal, resp.Header.Get(randHeaderKey))

bodyBytes, err := io.ReadAll(resp.Body)
assert.NoError(t, err)
Expand Down Expand Up @@ -95,3 +103,18 @@ func TestServDumpResponse(t *testing.T) {
assert.Contains(t, respStr, "X-Forwarded-Proto: http")
assert.Contains(t, respStr, "X-Request-Id")
}

var letterRunes = []rune("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ")

//nolint:gosec
func randStringRunes(t *testing.T, n int) string {
t.Helper()

b := make([]rune, n)

for i := range b {
b[i] = letterRunes[rand.Intn(len(letterRunes))]
}

return string(b)
}