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

How to use fasthttp TimeoutHandler #22

Closed
losingle opened this issue Jun 5, 2019 · 12 comments
Closed

How to use fasthttp TimeoutHandler #22

losingle opened this issue Jun 5, 2019 · 12 comments

Comments

@losingle
Copy link

losingle commented Jun 5, 2019

We need to give the timeout request a specific status code

https://godoc.org/github.com/valyala/fasthttp#TimeoutHandler

TimeoutErrorWithCode is discouraged

@savsgio
Copy link
Owner

savsgio commented Jun 5, 2019

Hi @losingle,

Do you need ctx.TimeoutErrorWithCode(...) or TimeoutHandler??

@savsgio
Copy link
Owner

savsgio commented Jun 5, 2019

You could call to ctx.TimeoutErrorWithCode() directly, as you would do in native fasthttp, in atreugo handler.

However, TimeoutHandler is not implemented yet. I will add it soon.

@losingle
Copy link
Author

losingle commented Jun 5, 2019

You could call to ctx.TimeoutErrorWithCode() directly, as you would do in native fasthttp, in atreugo handler.

However, TimeoutHandler is not implemented yet. I will add it soon.

Very much looking forward to this feature.
I can only use first eliminating CTX references in goroutines now

@savsgio
Copy link
Owner

savsgio commented Jun 5, 2019

Here you have the feature: https://godoc.org/github.com/savsgio/atreugo#Atreugo.TimeoutPath 😄

Thanks for your contribution.

@savsgio savsgio closed this as completed Jun 5, 2019
@losingle
Copy link
Author

losingle commented Jun 5, 2019

Here you have the feature: https://godoc.org/github.com/savsgio/atreugo#Atreugo.TimeoutPath 😄

Thanks for your contribution.

How do I change the status code ?
eg. valyala/fasthttp@38473d3

@savsgio
Copy link
Owner

savsgio commented Jun 5, 2019

TimeoutPath always return 408 if timeout is reached like fasthttp in https://godoc.org/github.com/valyala/fasthttp#TimeoutHandler

If you want to set a custom status code in response, use https://godoc.org/github.com/savsgio/atreugo#RequestCtx or ctx.SetStatusCode(<yourStatusCode>)

@savsgio
Copy link
Owner

savsgio commented Jun 5, 2019

I think you are supervising the timeout manually, right? with channels, selects, context or something similar.

if it's truth, not use PathTimeout or ctx.TimeoutErrorWithCode(...), just finish the handler and return the response with your own status code

@losingle
Copy link
Author

losingle commented Jun 5, 2019

well, as if only timeout manually
thank you

@savsgio
Copy link
Owner

savsgio commented Jun 5, 2019

So, why do you need to change the status code when timeout?

I see your PR valyala/fasthttp#589 in fasthttp.

I think so, it's not recommended to return another status code if timeout

@losingle
Copy link
Author

losingle commented Jun 5, 2019

Yes, normally, there is no need to change the status code, following the rules of HTTP.
However, some business scenarios may be needed, and I think fasthttp, as a network base library, should give control to the developers.
Because our business will need to timeout the request, return 204 status code

@savsgio
Copy link
Owner

savsgio commented Jun 7, 2019

I saw that erik merged your PR, when release a new version of fasthttp i will add it in atreugo. ;)

@savsgio
Copy link
Owner

savsgio commented Jul 17, 2019

I've just release a new version v8.1.0 with TimeoutWithCodePath support :)

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

No branches or pull requests

2 participants