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

feature: add ConvertRequest func #1024

Merged
merged 2 commits into from
May 17, 2021

Conversation

nicolascb
Copy link
Contributor

To easy method to convert ctx.RequestCtx to http.Request

To easy method to convert ctx.RequestCtx to http.Request
fasthttpadaptor/request.go Outdated Show resolved Hide resolved
fasthttpadaptor/request.go Outdated Show resolved Hide resolved
// ConvertRequest convert a fasthttp.Request to http.Request
// setURI is optionally because your use in client mode
func ConvertRequest(ctx *fasthttp.RequestCtx, setURI bool) (*http.Request, error) {
var r http.Request
Copy link

@savsgio savsgio May 14, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe, the http.Request could be part of the ConvertRequest() parameters to can use a sync.Pool if it's needed.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Somethig like this:

func ConvertRequest(ctx *fasthttp.RequestCtx, setURI bool, req *http.Request) error

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure I agree with this. http.Request contains unexported fields. It's not trivial to reuse an http.Request with sync.Pool and the standard library gives no guarantee that this might break in the future.

But I guess it's up to the user to make this work properly.

@nicolascb
Copy link
Contributor Author

@savsgio @erikdubbelboer Thanks for review!

Can you revise again?

@savsgio
Copy link

savsgio commented May 16, 2021

LGTM!

@erikdubbelboer erikdubbelboer merged commit 04cde74 into valyala:master May 17, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants