Skip to content

feat: add default_timeout support to config#1832

Open
Marias03 wants to merge 3 commits into
httpie:masterfrom
Marias03:feature/default-timeout
Open

feat: add default_timeout support to config#1832
Marias03 wants to merge 3 commits into
httpie:masterfrom
Marias03:feature/default-timeout

Conversation

@Marias03
Copy link
Copy Markdown

What does this PR do?

Adds support for default_timeout in HTTPie's config file.
Users can now set a global timeout that applies to all requests automatically.

How to use it?

Add to your config.json:

{
    "default_timeout": 30
}

This timeout will apply to all requests unless overridden with --timeout.

Changes

  • httpie/config.py: Added default_timeout to Config.DEFAULTS and a new property
  • httpie/client.py: Applied default_timeout from config in make_send_kwargs
  • tests/test_config.py: Added two tests for the new feature

Comment thread httpie/client.py
if base_headers:
headers.update(base_headers)
# Apply default headers from config (can be overridden by user)
if env.config.default_headers:
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion: safely guard the env reference to prevent NoneType attribute errors

While env is safely guarded up in make_send_kwargs, it is missing a guard here in make_request_kwargs on line 350:

if env and env.config.default_headers:

Comment thread tests/test_config.py
env.config['default_timeout'] = 30
env.config.save()
r = http('--timeout=60', httpbin + '/get', env=env)
assert HTTP_OK in r
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion: add a specific assertion to verify the timeout override value

While checking for HTTP_OK confirms the request succeeded, the test doesn't explicitly verify that the --timeout=60 argument successfully overrode the default_timeout setting of 30 during execution.

Adding an assertion for checking would make this test block significantly stronger.

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

Successfully merging this pull request may close these issues.

2 participants