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

Option to specify default scheme #296

Open
vszakats opened this issue May 7, 2024 · 2 comments
Open

Option to specify default scheme #296

vszakats opened this issue May 7, 2024 · 2 comments
Labels
enhancement New feature or request

Comments

@vszakats
Copy link
Member

vszakats commented May 7, 2024

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 vszakats added the enhancement New feature or request label May 8, 2024
@emanuele6
Copy link
Collaborator

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

@bagder
Copy link
Member

bagder commented May 13, 2024

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 curl/curl#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 added a commit that referenced this issue May 13, 2024
… set

Idea-by: @emanuele6 in #296

Due to missing support in the libcurl URL API, this is not really
working for the scheme component right now, as that will always be
considered set once a URL has been parsed. The scheme guessing the
parser thus sets it internally and there is currently no way provided by
the API to figure that out.
bagder added a commit that referenced this issue May 13, 2024
Idea-by: @emanuele6 in #296

Due to missing support in the libcurl URL API, this is not really
working for the scheme component right now, as that will always be
considered set once a URL has been parsed. The scheme guessing the
parser does sets it internally and there is currently no way provided by
the API to figure that out.
bagder added a commit that referenced this issue May 13, 2024
Idea-by: @emanuele6 in #296

Due to missing support in the libcurl URL API, this is not really
working for the scheme component right now, as that will always be
considered set once a URL has been parsed. The scheme guessing the
parser does sets it internally and there is currently no way provided by
the API to figure that out.

When the URL API has been extended, we can expand this functionality for
working better with scheme.

Closes #298
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants