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
18 changes: 17 additions & 1 deletion runtimes/go/appruntime/apisdk/api/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"context"
"fmt"
"io"
"maps"
"net/http"
"net/url"
"reflect"
Expand Down Expand Up @@ -263,7 +264,7 @@ func (d *Desc[Req, Resp]) begin(c IncomingContext) (reqData Req, beginErr error)
NonRawPayload: nonRawPayload,
UserID: c.auth.UID,
AuthData: c.auth.UserData,
RequestHeaders: c.req.Header,
RequestHeaders: headersWithHost(c.req),
FromEncorePlatform: platformauth.IsEncorePlatformRequest(c.req.Context()),
ServiceToServiceCall: c.callMeta.IsServiceToService(),
},
Expand Down Expand Up @@ -859,6 +860,21 @@ func unmarshalErrorResponse(httpResp *http.Response) error {
}
}

// headersWithHost clones the request headers and adds the Host header from req.Host.
// This is needed because Go stores the Host header in req.Host, not in req.Header.
func headersWithHost(req *http.Request) http.Header {
var headers http.Header
if req.Header != nil {
headers = maps.Clone(req.Header)
} else {
headers = make(http.Header)
}
if req.Host != "" {
headers.Set("Host", req.Host)
}
return headers
}

// validate validates the request, and returns a validation error on failure.
// If the user payload does not implement Validator, it returns nil.
func (d *Desc[Req, Resp]) validate(req Req) error {
Expand Down
6 changes: 3 additions & 3 deletions runtimes/go/appruntime/apisdk/api/handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ func TestDescGeneratesTrace(t *testing.T) {
AuthData: nil,
TypedPayload: &mockReq{Body: "foo"},
NonRawPayload: []byte(`{"Body":"foo"}`),
RequestHeaders: http.Header{"Content-Type": []string{"application/json"}},
RequestHeaders: http.Header{"Content-Type": []string{"application/json"}, "Host": []string{"example.com"}},
},
},
},
Expand Down Expand Up @@ -233,7 +233,7 @@ func TestDescGeneratesTrace(t *testing.T) {
UserID: "",
AuthData: nil,
TypedPayload: nil,
RequestHeaders: nil,
RequestHeaders: http.Header{"Host": []string{"example.com"}},
},
},
},
Expand Down Expand Up @@ -270,7 +270,7 @@ func TestDescGeneratesTrace(t *testing.T) {
UserID: "",
AuthData: nil,
TypedPayload: nil,
RequestHeaders: http.Header{"Content-Type": []string{"application/json"}},
RequestHeaders: http.Header{"Content-Type": []string{"application/json"}, "Host": []string{"example.com"}},
},
},
},
Expand Down