[ 
https://issues.apache.org/jira/browse/SLING-1629?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Alexander Klimetschek updated SLING-1629:
-----------------------------------------

    Description: 
When creating links in responses there are two cases:

1) create it for use by the browser: URLs relative to the current request
2) link used by external apps: absolute URL including hostname etc.

For 1), you can already use ResourceResolver.map(request, path) (important to 
use the request-based here).

For 2), when you explicitly want absolute URLs (eg. for rss feeds, links in 
emails, etc.), the ResourceResolver map methods will only add a host/port if 
such a configuration is part of /etc/map. There is no default to use the 
host/port from the current request.

Also, if a hostname is configured and you use map(request, path), because that 
is required for adding the context path, it will _strip_ it from the map call 
if the current request goes to that hostname, which is probably the normal 
case. The map(request, path) call is clearly aimed at relative URLs, case 1).

In order to provide convenient short access to those features, an externalize 
method on the sling request object is better for both cases:

case 1) relative url

    slingRequest.externalize("/my/path")

same as slingRequest.getResourceResolver().map(slingRequest, "/my/path"))

case 2) absolute url

    slingRequest.externalize("http", "/my/path")

produces e.g. http://localhost:8080/my/path

  was:
When creating links in responses there are two cases:

1) create it for use by the browser: URLs relative to the current request
2) link used by external apps: absolute URL including hostname etc.

For 1), you can already use ResourceResolver.map(request, path) (important to 
use the request-based here).

For 2), when you explicitly want absolute URLs (eg. for rss feeds, links in 
emails, etc.), the ResourceResolver map methods will only add a host/port if 
such a configuration is part of /etc/map. There is no default to use the 
host/port from the current request.

In order to provide convenient short access to those features, an externalize 
method on the sling request object is better for both cases:

case 1) relative url

    slingRequest.externalize("/my/path")

same as slingRequest.getResourceResolver().map(slingRequest, "/my/path"))

case 2) absolute url

    slingRequest.externalize("http", "/my/path")

produces e.g. http://localhost:8080/my/path


> Add methods for externalizing links to SlingHttpServletRequest
> --------------------------------------------------------------
>
>                 Key: SLING-1629
>                 URL: https://issues.apache.org/jira/browse/SLING-1629
>             Project: Sling
>          Issue Type: New Feature
>          Components: API, Engine
>            Reporter: Alexander Klimetschek
>            Priority: Minor
>         Attachments: SLING-1629.patch
>
>
> When creating links in responses there are two cases:
> 1) create it for use by the browser: URLs relative to the current request
> 2) link used by external apps: absolute URL including hostname etc.
> For 1), you can already use ResourceResolver.map(request, path) (important to 
> use the request-based here).
> For 2), when you explicitly want absolute URLs (eg. for rss feeds, links in 
> emails, etc.), the ResourceResolver map methods will only add a host/port if 
> such a configuration is part of /etc/map. There is no default to use the 
> host/port from the current request.
> Also, if a hostname is configured and you use map(request, path), because 
> that is required for adding the context path, it will _strip_ it from the map 
> call if the current request goes to that hostname, which is probably the 
> normal case. The map(request, path) call is clearly aimed at relative URLs, 
> case 1).
> In order to provide convenient short access to those features, an externalize 
> method on the sling request object is better for both cases:
> case 1) relative url
>     slingRequest.externalize("/my/path")
> same as slingRequest.getResourceResolver().map(slingRequest, "/my/path"))
> case 2) absolute url
>     slingRequest.externalize("http", "/my/path")
> produces e.g. http://localhost:8080/my/path

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.

Reply via email to