Skip to content

Commit f5051e5

Browse files
committed
fix: handle fiber body and request uri correctly
1 parent f1e7dda commit f5051e5

File tree

2 files changed

+8
-5
lines changed

2 files changed

+8
-5
lines changed

adapter/fiber.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ func (a fiberAdapter) adapterFunc(ctx context.Context, r *http.Request, w http.R
2828
// protocol, method, uri, host
2929
httpReq.Header.SetProtocol(r.Proto)
3030
httpReq.Header.SetMethod(r.Method)
31-
httpReq.SetRequestURI(r.RequestURI)
31+
httpReq.SetRequestURI(r.URL.Scheme + "://" + r.RequestURI)
3232
httpReq.SetHost(r.Host)
3333

3434
// body
@@ -82,7 +82,7 @@ func (a fiberAdapter) adapterFunc(ctx context.Context, r *http.Request, w http.R
8282

8383
w.WriteHeader(fctx.Response.StatusCode())
8484
// release handled in defer
85-
_, err = io.Copy(w, fctx.Response.BodyStream())
85+
err = fctx.Response.BodyWriteTo(w)
8686

8787
return err
8888
}

functionurl_test.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,13 @@ func newFunctionURLRequest() events.LambdaFunctionURLRequest {
2929
Authorizer: nil,
3030
APIID: "0dhg9709da0dhg9709da0dhg9709da",
3131
DomainName: "0dhg9709da0dhg9709da0dhg9709da.lambda-url.eu-central-1.on.aws",
32-
DomainPrefix: "",
32+
DomainPrefix: "0dhg9709da0dhg9709da0dhg9709da",
3333
Time: "",
3434
TimeEpoch: 0,
3535
HTTP: events.LambdaFunctionURLRequestContextHTTPDescription{
3636
Method: "POST",
3737
Path: "/example",
38-
Protocol: "",
38+
Protocol: "HTTP/1.1",
3939
SourceIP: "127.0.0.1",
4040
UserAgent: "Go-http-client/1.1",
4141
},
@@ -95,7 +95,7 @@ func newFiberAdapter() handler.AdapterFunc {
9595
result := make(map[string]string)
9696
result["Method"] = ctx.Method()
9797
result["URL"] = ctx.Request().URI().String()
98-
result["RemoteAddr"] = ctx.IP()
98+
result["RemoteAddr"] = ctx.IP() + ":http" // fiber uses net.ResolveTCPAddr which resolves :http to :80
9999
result["Body"] = string(ctx.Body())
100100

101101
return ctx.JSON(result)
@@ -108,6 +108,7 @@ func TestFunctionURLGET(t *testing.T) {
108108
adapters := map[string]handler.AdapterFunc{
109109
"vanilla": newVanillaAdapter(),
110110
"echo": newEchoAdapter(),
111+
"fiber": newFiberAdapter(),
111112
}
112113

113114
for name, a := range adapters {
@@ -143,6 +144,8 @@ func TestFunctionURLGET(t *testing.T) {
143144
}
144145

145146
if !reflect.DeepEqual(body, expectedBody) {
147+
t.Logf("expected: %v", expectedBody)
148+
t.Logf("actual: %v", body)
146149
t.Error("request/response didnt match")
147150
}
148151
})

0 commit comments

Comments
 (0)