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

Improved documentation for forward() #831

Open
JosiahParry opened this issue Sep 30, 2021 · 5 comments · May be fixed by #978
Open

Improved documentation for forward() #831

JosiahParry opened this issue Sep 30, 2021 · 5 comments · May be fixed by #978

Comments

@JosiahParry
Copy link
Contributor

#' Forward Request to The Next Handler

The documentation for forward() is rather slim. Upon reading the function documentation it is unclear how the function is to be used.

For more about this function I navigated to the article "Routing and Input" which states "...then calls forward() to pass control to the next handler in the pipeline (another filter or an endpoint)" which makes me believe that you can use foward() to pass to another endpoint.

The example provides no clear description as to what is being forwarded and to where. Further all examples of forward() are within the context of filter.

Further documentation or examples would be helpful.

There's also the possibility that this is a uniquely me problem.

@meztez
Copy link
Collaborator

meztez commented Oct 1, 2021

@JosiahParry nah. I'm with you on forward(). It's an us problem :)

@schloerke
Copy link
Collaborator

I agree it is confusing. I have been leaving that alone as I don't like the design (and therefore don't want to promote it with docs). I hope sooner than later we can get middleware and just silently ignore filters/forward() forever. (I don't have enough time to implement this in the next 6 months)

Few notes to hopefully clear things up:

  • forward() can be called at anytime during a filter. (I'd prefer it to be the last thing returned if the next filter should be processed.)
  • If forward() is called during the current filter execution, the next filter in the router will be executed. If there are no more filters left, then the endpoint will be processed.

@JosiahParry
Copy link
Contributor Author

Thanks, Barret! So to be clear, forward() does not enable the passing to another endpoint? Say from a get to a post?

@schloerke
Copy link
Collaborator

Correct. It does not enable passing the route.

It is more of "if forward() is not called within the filter, then the return value of the filter is used to respond to the request"

@schloerke
Copy link
Collaborator

To answer your specific question...

Say from a get to a post?

By the time the filter is being executed, httpuv / rook have already processed all of the headers and information. There would be no body to parse even if you changed the information in the req object for follow up filters to use

@thomasp85 thomasp85 linked a pull request Jan 24, 2025 that will close this issue
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 a pull request may close this issue.

3 participants