Skip to content
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

🐛 [Bug]: Adaptor + otelfiber issue #2641 #2772

Merged
merged 1 commit into from
Dec 22, 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: 2 additions & 0 deletions middleware/adaptor/adaptor.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ func HTTPMiddleware(mw func(http.Handler) http.Handler) fiber.Handler {
c.Request().Header.SetMethod(r.Method)
c.Request().SetRequestURI(r.RequestURI)
c.Request().SetHost(r.Host)
c.Request().Header.SetHost(r.Host)
for key, val := range r.Header {
for _, v := range val {
c.Request().Header.Set(key, v)
Expand Down Expand Up @@ -128,6 +129,7 @@ func handlerFunc(app *fiber.App, h ...fiber.Handler) http.HandlerFunc {
req.Header.SetMethod(r.Method)
req.SetRequestURI(r.RequestURI)
req.SetHost(r.Host)
req.Header.SetHost(r.Host)
for key, val := range r.Header {
for _, v := range val {
req.Header.Set(key, v)
Expand Down
6 changes: 6 additions & 0 deletions middleware/adaptor/adaptor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ var (
)

func Test_HTTPMiddleware(t *testing.T) {
const expectedHost = "foobar.com"
tests := []struct {
name string
url string
Expand Down Expand Up @@ -148,6 +149,7 @@ func Test_HTTPMiddleware(t *testing.T) {
w.WriteHeader(http.StatusMethodNotAllowed)
return
}

r = r.WithContext(context.WithValue(r.Context(), TestContextKey, "okay"))
r = r.WithContext(context.WithValue(r.Context(), TestContextSecondKey, "not_okay"))
r = r.WithContext(context.WithValue(r.Context(), TestContextSecondKey, "okay"))
Expand Down Expand Up @@ -180,6 +182,7 @@ func Test_HTTPMiddleware(t *testing.T) {

for _, tt := range tests {
req, err := http.NewRequestWithContext(context.Background(), tt.method, tt.url, nil)
req.Host = expectedHost
utils.AssertEqual(t, nil, err)

resp, err := app.Test(req)
Expand All @@ -188,6 +191,7 @@ func Test_HTTPMiddleware(t *testing.T) {
}

req, err := http.NewRequestWithContext(context.Background(), fiber.MethodPost, "/", nil)
req.Host = expectedHost
utils.AssertEqual(t, nil, err)

resp, err := app.Test(req)
Expand Down Expand Up @@ -239,6 +243,8 @@ func testFiberToHandlerFunc(t *testing.T, checkDefaultPort bool, app ...*fiber.A
utils.AssertEqual(t, expectedRequestURI, string(c.Context().RequestURI()), "RequestURI")
utils.AssertEqual(t, expectedContentLength, c.Context().Request.Header.ContentLength(), "ContentLength")
utils.AssertEqual(t, expectedHost, c.Hostname(), "Host")
utils.AssertEqual(t, expectedHost, string(c.Request().Header.Host()), "Host")
utils.AssertEqual(t, "http://"+expectedHost, c.BaseURL(), "BaseURL")
utils.AssertEqual(t, expectedRemoteAddr, c.Context().RemoteAddr().String(), "RemoteAddr")

body := string(c.Body())
Expand Down
Loading