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

Order of variables #3358

Open
Baklap4 opened this issue Oct 31, 2024 · 1 comment
Open

Order of variables #3358

Baklap4 opened this issue Oct 31, 2024 · 1 comment

Comments

@Baklap4
Copy link

Baklap4 commented Oct 31, 2024

We have a couple of ways to specify variables, however i'm not sure what the order is.

Variables can also be injected in a Hurl file:

by using --variable option
by using --variables-file option
by defining environment variables, for instance HURL_foo=bar
by defining variables in an [Options] section

By reading this --variable option on cli always supercedes everything then comes the variables-file option then the environment variables and last but not least the Options section in the file.

However i'd think that's kind of strange
A better order (in my opinion) would be:

  1. --variable option
  2. environment variables
  3. --variable-file option
  4. options section in specific file

This ensures system variables are prefered over local files. In my instance i'm sharing the .env files through git where the localhost.env contains a different value for every user. I can't specify it in the variable-file since it differs, so i'd add it to my environment

what's your take on this?

@jcamiel
Copy link
Collaborator

jcamiel commented Oct 31, 2024

Hi @Baklap4

Regarding options, the current behaviour is that options defined on a specific request take precedence over options defined on command line. For instance, given this file:

GET https://foo.com

GET https://bar.com
[Options]
insecure: false

GET https://baz.com
[Options]
insecure: true

With this command $ hurl --insecure test.hurl, will run:

We have debated a lot about this behaviour and both behaviour have its pros and cons.

Personnaly, I would really dislike if, given this file:

GET https://foo.com
HTTP 200

GET https://bar.com
[Options]
insecure: false

GET https://baz.com
[Options]
insecure: true

Hurl could execute a insecure request on bar.com (in this model, the source code overrides the model, options on requests are more "specific").

Variables work like options. Given this Hurl file:

GET https://foo.com
[Options]
variable token=foo

With this command $ hurl --variable token=bar, the variable value resolved is "foo". Like any other options, variable defined on requests override variable defined in command line. Variable can also be obtain from capture:

GET https://foo.com

GET https://bar.com
HTTP 200
[Captures]
token: body 

In this case, token variable is resolved dynamically when requesting <bar.com> Once again, I would find it hard to understand that running this file with $ hurl --variable token=foo will not change the value of token variable on the second HTTP response.

Regarding variable vs variable-file, we have not specified exactly in which order we read variables, it depedent on the actual code!

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

No branches or pull requests

2 participants