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

Some methods in Router need Http.Request as argument #253

Closed
cies opened this issue Sep 25, 2023 · 2 comments · Fixed by #255
Closed

Some methods in Router need Http.Request as argument #253

cies opened this issue Sep 25, 2023 · 2 comments · Fixed by #255
Assignees
Milestone

Comments

@cies
Copy link
Member

cies commented Sep 25, 2023

Going from Play1 to RePlay we found Router.getFullUrl was deprecated in favor of a method with the same name, but takes a Http.Request as argument. I think I get the reason for this change: the old Router.getFullUrl took some request data from thread local, and that's dangerous way to get an implicit dependency on the Http.Request.

In several cases we build full urls in our app without a request context: in the model code (not often, but sometimes we need to put a link somewhere) and in our background workers.

Since Router.getFullUrl only needs the base url (with getBaseUrl) from Http.Request, I think it is better to create another, overloaded, method in Router:

    public static String getFullUrl(String action, Map<String, Object> args, String baseUrl) {
        ...
    }

This method does not require the whole of a Request (that sometimes is not even available) and

Possibly deprecating the getFullUrl that takes Http.Request as an argument as well, as passing the whole request is a bit much when all we need it the baseUrl.

When doing this I suggest we do so for some other methods in Router that expect a Http.Request argument, namely:

  • Router.actionToUrl(String action, Map<String, Object> actionArgs, Http.Request request, Http.Response response) -- the response is only used for the character encoding, so a new overloaded method of could be created with the the reponse argument replaced with a @Nullable Charset encoding for which Play.defaultWebEncoding is picked with null was given.
  • Router.reverse(String action, Map<String, Object> args, Http.Request request, Http.Response response) -- same comment as the previous item
  • Router.getFullUrl(String action, Map<String, Object> args, Http.Request request)
  • Router.getBaseUrl(Http.Request request)
  • Router.getFullUrl(String action, Http.Request request)
  • Router.reverse(String action, Map<String, Object> args, Http.Request request, Http.Response response)

But not these (only used internally by the framework):

  • Router.routeOnlyStatic(Http.Request request)
  • Router.route(Http.Request request)
  • Router.processRoute(Http.Request request, MatchingRoute match)

I gladly make a PR implementing the above, but first I'd like to know if we all agree this is a good way fwd.

@cies cies self-assigned this Sep 25, 2023
@asolntsev
Copy link
Contributor

@cies I totally agree with all suggested changes. Yes, Request parameter was needed there only to get baseUrl. And yes, we could provide baseUrl as a parameter.

@cies
Copy link
Member Author

cies commented Sep 27, 2023

@asolntsev shall i create a PR?

Then I have the following questions:

  • Shall I deprecate the ones that user Http.*?
  • Shall I put the Http.Request.secure in a PR of it's own?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants