-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(handler): do not apply cookies after flamingo ran
- Loading branch information
1 parent
7f139a5
commit fd28798
Showing
2 changed files
with
40 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package graphql | ||
|
||
import ( | ||
"context" | ||
"io" | ||
"net/http" | ||
"net/http/httptest" | ||
|
||
"flamingo.me/flamingo/v3/framework/web" | ||
) | ||
|
||
type ( | ||
gqlHandler struct { | ||
recorder *httptest.ResponseRecorder | ||
request *web.Request | ||
} | ||
) | ||
|
||
// wrapGqlHandler wraps an http.Handler to be used in the flamingo http package | ||
func wrapGqlHandler(handler http.Handler) web.Action { | ||
return func(ctx context.Context, req *web.Request) web.Result { | ||
rw := httptest.NewRecorder() | ||
handler.ServeHTTP(rw, req.Request().WithContext(ctx)) | ||
return &gqlHandler{ | ||
request: req, | ||
recorder: rw, | ||
} | ||
} | ||
} | ||
|
||
func (h *gqlHandler) Apply(ctx context.Context, rw http.ResponseWriter) error { | ||
for k, vs := range h.recorder.Header() { | ||
for _, v := range vs { | ||
rw.Header().Add(k, v) | ||
} | ||
} | ||
_, err := io.Copy(rw, h.recorder.Body) | ||
return err | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters