Waboodoo / HTTP-Shortcuts

Android app to create home screen shortcuts that trigger arbitrary HTTP requests
https://http-shortcuts.rmy.ch
MIT License
1.17k stars 113 forks source link

Make response.url accessible? #395

Closed Zottelchen closed 11 months ago

Zottelchen commented 11 months ago

Is your feature request related to a problem? Please describe.

I am using this awesome app to send links to my ntfy instance, so I can view them anywhere. Sometimes the links shared by apps are shortened and redirect and contain tracking queries - I would like to remove that and directly send the correct URL.

Describe the solution you'd like

I am currently trying to use an utility-request which gets invoked by the other shortcuts, but response.url does not seem to be available. I would like to have the final URL in that field, as would be the case with JavaScript, so that I can use:

setResult(response.url.split("?")[0]) // removes everything after ?, which is fine for my use case

Describe alternatives you've considered

None, if it is possible or I am just being stupid please tell me :) I've looked at the response.json object, but I've found no URL.

Waboodoo commented 11 months ago

You are correct, there's currently no response.url or similar that would let you programmatically access the final URL. However, here's an idea that you could try (haven't tried it myself, not sure if it would work): As I understand, you have a shortcut which you're only using to resolve the redirects to get the final URL, but you don't actually care about the content of the destination page at that point. So what you could do is configure that shortcut to not follow the redirect, by turning off the checkbox in the "Advanced Technical Settings" section. You can then programmatically read out the "Location" header to determine where the redirect would lead you. Assuming there's only a single redirect happening, this will give you the final URL. You can extract the URL with a code snippet like this:

const finalUrl = response.getHeader("Location");

The resulting URL might be a relative one, so you might need to manually convert it into an absolute one.

Let me know if the above suggestion doesn't work, then I can look into this some more.

Zottelchen commented 11 months ago

I have not thought about that, that is even better. Thank you, this works for me 👍