Skip to content

Add support for project-local config directories (.httpie/config.json)#1906

Open
kova1max wants to merge 1 commit into
httpie:masterfrom
kova1max:local-config-dir
Open

Add support for project-local config directories (.httpie/config.json)#1906
kova1max wants to merge 1 commit into
httpie:masterfrom
kova1max:local-config-dir

Conversation

@kova1max

Copy link
Copy Markdown

Closes #1229.

This PR adds discovery of a project-local config directory: a .httpie directory containing config.json, looked up from the current working directory upwards (nearest match wins) β€” the same discovery convention as .git or .npmrc.

Motivation

The global config applies to every invocation, which pollutes unrelated requests (see #1229). $HTTPIE_CONFIG_DIR solves this only partially β€” it has to be exported in every shell, which is cumbersome and doesn't work well in teams. A per-project config that is simply picked up when working inside the project directory tree solves both #1229 and, indirectly, the per-host use case of #809 without the localhost collision problem described in #1229.

Design decisions

  • A directory (.httpie/) rather than a single .httpierc file, so the existing Config machinery works unchanged and sessions/plugins get project scoping for free.
  • config.json must exist inside β€” a bare .httpie directory is ignored, so stray directories can't silently hijack configuration (and the legacy ~/.httpie behavior is preserved unchanged).
  • Explicit $HTTPIE_CONFIG_DIR always wins, keeping the current escape hatch.

Resolution order: $HTTPIE_CONFIG_DIR β†’ nearest .httpie/config.json upwards from cwd β†’ platform defaults (unchanged).

Security consideration

Auto-loading config from a directory tree means a cloned repository can inject default_options (e.g. --proxy, --verify=no). This mirrors the long-standing behavior of npm's .npmrc. If you'd prefer, discovery could be gated behind an opt-in global setting β€” happy to adjust.

Checklist

  • Tests added (tests/test_config.py)
  • Full test suite passes (the two test_encoding.py big5 failures reproduce on clean master and are unrelated)
  • Docs updated (docs/README.md)
  • Changelog updated

Look for a `.httpie` directory containing `config.json` in the current
working directory and its parents (nearest match wins), before falling
back to the global config location. An explicitly set
`$HTTPIE_CONFIG_DIR` still takes precedence.
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.

per-directory config file (.httpierc)

1 participant