trurl icon indicating copy to clipboard operation
trurl copied to clipboard

Option to specify default scheme

Open vszakats opened this issue 1 year ago • 2 comments

For now the default scheme seems to be coming from libcurl, which is typically 'http'. It could be useful to override it to something else, such as 'https' to get secure-by-default URLs.

E.g. with --default-scheme https.

trurl --url example.org → http://example.org/ trurl --url example.org --default-scheme https → https://example.org/

vszakats avatar May 07 '24 23:05 vszakats

Maybe, instead of this, there could be a set-if-not-set syntax e.g. ?= (since := is already used); then you could use -s 'port?=1234' etc too

emanuele6 avatar May 08 '24 13:05 emanuele6

I started working on @emanuele6's proposal only to run into a minor issue:

When we parse a URL without a scheme, we must ask libcurl to guess the scheme because otherwise it does not accept the URL. When it guesses a scheme, it sets that for the URL and when we subsequently check the URL we can no longer figure out if the scheme is the result of a guess or not.

Therefore, we can't after the fact replace the scheme if it was not previously set, because we no longer have the information if the scheme was guessed or not.

All other parts of the URL can be polled if it exists or not before setting it again, and I will soon make a PR for that change.

I have created https://github.com/curl/curl/pull/13616 for curl, to allow us to query the URL proper if the set scheme was guessed or set. But that will take a little while until it lands there.

bagder avatar May 13 '24 11:05 bagder

CURLU_NO_GUESS_SCHEME has been merged into curl's git and will ship in the pending curl 8.9.0 release.

bagder avatar Jun 13 '24 15:06 bagder