Skip to content
Open
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
23 changes: 17 additions & 6 deletions frankenphp.go
Original file line number Diff line number Diff line change
Expand Up @@ -588,17 +588,28 @@ func go_apache_request_headers(threadIndex C.uintptr_t) (*C.go_string, C.size_t)
return nil, 0
}

headers := make([]C.go_string, 0, len(fc.request.Header)*2)
headers := make([]C.go_string, 0, (len(fc.request.Header)+1)*2)

if fc.request.Host != "" {
hd := unsafe.StringData(fc.request.Host)
thread.Pin(hd)

headers = append(
headers,
C.go_string{C.size_t(len("Host")), toUnsafeChar("Host")},
C.go_string{C.size_t(len(fc.request.Host)), (*C.char)(unsafe.Pointer(hd))},
)
}

for field, val := range fc.request.Header {
if field == "Host" {
continue
}

fd := unsafe.StringData(field)
thread.Pin(fd)

cv := strings.Join(val, ", ")
if field == "Host" {
cv = fc.request.Host
}

vd := unsafe.StringData(cv)
thread.Pin(vd)

Expand All @@ -612,7 +623,7 @@ func go_apache_request_headers(threadIndex C.uintptr_t) (*C.go_string, C.size_t)
sd := unsafe.SliceData(headers)
thread.Pin(sd)

return sd, C.size_t(len(fc.request.Header))
return sd, C.size_t(len(headers) / 2)
}

func addHeader(fc *frankenPHPContext, h *C.sapi_header_struct) {
Expand Down
1 change: 1 addition & 0 deletions frankenphp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -918,6 +918,7 @@ func testRequestHeaders(t *testing.T, opts *testOptions) {

assert.Contains(t, body, "[Content-Type] => text/plain")
assert.Contains(t, body, fmt.Sprintf("[Frankenphp-I] => %d", i))
assert.Contains(t, body, "[Host] => example.com")
}, opts)
}

Expand Down
Loading