mirror of
https://github.com/httpie/cli.git
synced 2025-08-10 08:08:41 +02:00
Compare commits
97 Commits
Author | SHA1 | Date | |
---|---|---|---|
4eaa4d67c5 | |||
9764cc74a4 | |||
778360cde1 | |||
60a7ed4e7b | |||
185af7c9f1 | |||
7e9e7c783f | |||
6039bd8582 | |||
e7d8b9cece | |||
a62391e789 | |||
41666d897f | |||
71008bbedb | |||
85110643e7 | |||
fdd486415a | |||
6c501d23c3 | |||
d10e108b5f | |||
8618f12fce | |||
dac0d716c1 | |||
0340f8caf5 | |||
d7caeaf372 | |||
54c8612452 | |||
4ff22defe4 | |||
c50e287c57 | |||
6bd6648545 | |||
6633b5ae9b | |||
c6cbc7dfa5 | |||
11399dde76 | |||
da47e37c44 | |||
a66af2497a | |||
a94d6d807c | |||
de13423839 | |||
04d05a8abd | |||
2f8d7f77bd | |||
aee77a23af | |||
64c31d554a | |||
41c251ec7c | |||
147a066dbe | |||
b7300c1096 | |||
5d4e7a9a18 | |||
5717fb1ad5 | |||
9c38da96b0 | |||
e5bda98ee7 | |||
c8d70e8c0b | |||
ae6f57dc76 | |||
b4c94e0f26 | |||
7ceb313ccf | |||
3228e74df5 | |||
dc4309771e | |||
07a0359316 | |||
2d55c01c7e | |||
1470ca0c77 | |||
9857693ebf | |||
da03a0656e | |||
61f1ffd0eb | |||
9792513c68 | |||
350f973f70 | |||
8d35a12d27 | |||
8374a9ed83 | |||
a61f9e1114 | |||
611b278b63 | |||
175e36da6b | |||
19e1e26d97 | |||
9b5aedb02d | |||
3865fabf09 | |||
355befcbfc | |||
fc7a349d36 | |||
06ef27c576 | |||
0e556ec3a8 | |||
464b5b4c1d | |||
264d45cdf5 | |||
0ff0874fa3 | |||
39314887c4 | |||
f9a488d47e | |||
0001297f41 | |||
e2d43c14ce | |||
a3a08a9a22 | |||
7cbdf2c608 | |||
1274d869f6 | |||
611bcdaab1 | |||
fc45bf0fe3 | |||
56c4ba1794 | |||
8f83bfe767 | |||
a32ad344dd | |||
c53fbe5ae3 | |||
070ba9fa5a | |||
82ee071362 | |||
97dffb35a2 | |||
18af03ac18 | |||
904dd4107a | |||
8efabc86e6 | |||
cc20488f49 | |||
b918972862 | |||
84c7327057 | |||
e944dbd7fa | |||
157f3a1840 | |||
61dbadb730 | |||
7be25d0751 | |||
5d5a8b4091 |
40
.github/ISSUE_TEMPLATE/bug_report.md
vendored
Normal file
40
.github/ISSUE_TEMPLATE/bug_report.md
vendored
Normal file
@ -0,0 +1,40 @@
|
||||
---
|
||||
name: Bug report
|
||||
about: Report a possible bug in HTTPie
|
||||
title: ''
|
||||
labels: "new, bug"
|
||||
assignees: ''
|
||||
|
||||
---
|
||||
|
||||
**Checklist**
|
||||
|
||||
- [ ] I've searched for similar issues.
|
||||
- [ ] I'm using the latest version of HTTPie.
|
||||
|
||||
---
|
||||
|
||||
**What are the steps to reproduce the problem?**
|
||||
|
||||
1.
|
||||
2.
|
||||
3.
|
||||
|
||||
|
||||
**What is the expected result?**
|
||||
|
||||
|
||||
**What happens instead?**
|
||||
|
||||
|
||||
**Debug output**
|
||||
|
||||
Please re-run the command with `--debug`, then copy the entire command & output and paste both below:
|
||||
|
||||
```
|
||||
$ http --debug <COMPLETE ARGUMENT LIST THAT TRIGGERS THE ERROR>
|
||||
<COMPLETE OUTPUT>
|
||||
```
|
||||
|
||||
|
||||
**Provide any additional information, screenshots, or code examples below:**
|
24
.github/ISSUE_TEMPLATE/feature_request.md
vendored
Normal file
24
.github/ISSUE_TEMPLATE/feature_request.md
vendored
Normal file
@ -0,0 +1,24 @@
|
||||
---
|
||||
name: Feature request
|
||||
about: Suggest an enhancement for HTTPie
|
||||
title: ''
|
||||
labels: "new, enhancement"
|
||||
assignees: ''
|
||||
|
||||
---
|
||||
**Checklist**
|
||||
|
||||
- [ ] I've searched for similar feature requests.
|
||||
|
||||
---
|
||||
|
||||
**What enhancement would you like to see?**
|
||||
|
||||
|
||||
**What problem does it solve?**
|
||||
|
||||
E.g. “I'm always frustrated when [...]”, “I’m trying to do […] so that […]”.
|
||||
|
||||
|
||||
**Provide any additional information, screenshots, or code examples below:**
|
||||
|
10
.github/ISSUE_TEMPLATE/other.md
vendored
Normal file
10
.github/ISSUE_TEMPLATE/other.md
vendored
Normal file
@ -0,0 +1,10 @@
|
||||
---
|
||||
name: Other
|
||||
about: Anything else that isn't a feature or a bug
|
||||
title: ''
|
||||
labels: "new"
|
||||
assignees: ''
|
||||
|
||||
---
|
||||
|
||||
If you have a general question, please consider asking on Discord: https://httpie.io/chat
|
9
.github/dependabot.yml
vendored
Normal file
9
.github/dependabot.yml
vendored
Normal file
@ -0,0 +1,9 @@
|
||||
version: 2
|
||||
updates:
|
||||
# GitHub Actions
|
||||
- package-ecosystem: github-actions
|
||||
directory: /
|
||||
schedule:
|
||||
interval: daily
|
||||
assignees:
|
||||
- BoboTiG
|
17
.github/workflows/build.yml
vendored
17
.github/workflows/build.yml
vendored
@ -5,13 +5,13 @@ jobs:
|
||||
# Run coverage and extra tests only once
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v1
|
||||
- uses: actions/setup-python@v1
|
||||
- uses: actions/checkout@v2
|
||||
- uses: actions/setup-python@v2
|
||||
with:
|
||||
python-version: 3.9
|
||||
- run: python -m pip install --upgrade pip setuptools wheel
|
||||
- run: make install
|
||||
- run: make pycodestyle
|
||||
- run: make codestyle
|
||||
- run: make test-cover
|
||||
- run: make codecov-upload
|
||||
env:
|
||||
@ -21,14 +21,15 @@ jobs:
|
||||
# Run core HTTPie tests everywhere
|
||||
runs-on: ${{ matrix.os }}
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
os: [ubuntu-latest, macOS-latest, windows-latest]
|
||||
python-version: [3.6, 3.7, 3.8, 3.9]
|
||||
python-version: [3.6, 3.7, 3.8, 3.9, "3.10.0-rc.1"]
|
||||
steps:
|
||||
- uses: actions/checkout@v1
|
||||
- uses: actions/setup-python@v1
|
||||
- uses: actions/checkout@v2
|
||||
- uses: actions/setup-python@v2
|
||||
with:
|
||||
python-version: ${{ matrix.python-version }}
|
||||
- run: python -m pip install --upgrade pip setuptools wheel
|
||||
- run: python -m pip install --upgrade --editable .
|
||||
- run: python setup.py test
|
||||
- run: python -m pip install --upgrade '.[dev]'
|
||||
- run: python -m pytest --verbose ./httpie ./tests
|
||||
|
5
.gitignore
vendored
5
.gitignore
vendored
@ -139,3 +139,8 @@ dmypy.json
|
||||
|
||||
# Pyre type checker
|
||||
.pyre/
|
||||
|
||||
# Packit
|
||||
/httpie.spec
|
||||
/httpie-*.rpm
|
||||
/httpie-*.tar.gz
|
||||
|
21
.packit.yaml
Normal file
21
.packit.yaml
Normal file
@ -0,0 +1,21 @@
|
||||
# See the documentation for more information:
|
||||
# https://packit.dev/docs/configuration/
|
||||
specfile_path: httpie.spec
|
||||
actions:
|
||||
# the current Fedora Rawhide specfile has some patches
|
||||
# so we get it from @hroncok's (= churchyard in Fedora) fork for now
|
||||
# once we have a new release, we'll use: https://src.fedoraproject.org/rpms/httpie/raw/rawhide/f/httpie.spec
|
||||
post-upstream-clone: "wget https://src.fedoraproject.org/fork/churchyard/rpms/httpie/raw/packit/f/httpie.spec -O httpie.spec"
|
||||
jobs:
|
||||
- job: copr_build
|
||||
trigger: pull_request
|
||||
metadata:
|
||||
targets:
|
||||
- fedora-all
|
||||
additional_repos:
|
||||
- "https://kojipkgs.fedoraproject.org/repos/f$releasever-build/latest/$basearch/"
|
||||
- job: propose_downstream
|
||||
trigger: release
|
||||
metadata:
|
||||
dist_git_branches:
|
||||
- rawhide
|
41
AUTHORS.md
Normal file
41
AUTHORS.md
Normal file
@ -0,0 +1,41 @@
|
||||
# HTTPie authors
|
||||
|
||||
- [Jakub Roztocil](https://github.com/jakubroztocil)
|
||||
|
||||
## Patches, features, ideas
|
||||
|
||||
[Complete list of contributors on GitHub](https://github.com/httpie/httpie/graphs/contributors)
|
||||
|
||||
- [Cláudia T. Delgado](https://github.com/claudiatd)
|
||||
- [Hank Gay](https://github.com/gthank)
|
||||
- [Jake Basile](https://github.com/jakebasile)
|
||||
- [Vladimir Berkutov](https://github.com/dair-targ)
|
||||
- [Jakob Kramer](https://github.com/gandaro)
|
||||
- [Chris Faulkner](https://github.com/faulkner)
|
||||
- [Alen Mujezinovic](https://github.com/flashingpumpkin)
|
||||
- [Praful Mathur](https://github.com/tictactix)
|
||||
- [Marc Abramowitz](https://github.com/msabramo)
|
||||
- [Ismail Badawi](https://github.com/isbadawi)
|
||||
- [Laurent Bachelier](https://github.com/laurentb)
|
||||
- [Isman Firmansyah](https://github.com/iromli)
|
||||
- [Simon Olofsson](https://github.com/simono)
|
||||
- [Churkin Oleg](https://github.com/Bahus)
|
||||
- [Jökull Sólberg Auðunsson](https://github.com/jokull)
|
||||
- [Matthew M. Boedicker](https://github.com/mmb)
|
||||
- [marblar](https://github.com/marblar)
|
||||
- [Tomek Wójcik](https://github.com/tomekwojcik)
|
||||
- [Davey Shafik](https://github.com/dshafik)
|
||||
- [cido](https://github.com/cido)
|
||||
- [Justin Bonnar](https://github.com/jargonjustin)
|
||||
- [Nathan LaFreniere](https://github.com/nlf)
|
||||
- [Matthias Lehmann](https://github.com/matleh)
|
||||
- [Dennis Brakhane](https://github.com/brakhane)
|
||||
- [Matt Layman](https://github.com/mblayman)
|
||||
- [Edward Yang](https://github.com/honorabrutroll)
|
||||
- [Aleksandr Vinokurov](https://github.com/aleksandr-vin)
|
||||
- [Jeff Byrnes](https://github.com/jeffbyrnes)
|
||||
- [Denis Belavin](https://github.com/LuckyDenis)
|
||||
- [Mickaël Schoentgen](https://github.com/BoboTiG)
|
||||
- [Elena Lape](https://github.com/elenalape)
|
||||
- [Rohit Sehgal](https://github.com/r0hi7)
|
||||
- [Bartłomiej Jacak](https://github.com/bartekjacak)
|
43
AUTHORS.rst
43
AUTHORS.rst
@ -1,43 +0,0 @@
|
||||
==============
|
||||
HTTPie authors
|
||||
==============
|
||||
|
||||
* `Jakub Roztocil <https://github.com/jakubroztocil>`_
|
||||
|
||||
|
||||
Patches and ideas
|
||||
-----------------
|
||||
|
||||
`Complete list of contributors on GitHub <https://github.com/httpie/httpie/graphs/contributors>`_
|
||||
|
||||
* `Cláudia T. Delgado <https://github.com/claudiatd>`_ (logo)
|
||||
* `Hank Gay <https://github.com/gthank>`_
|
||||
* `Jake Basile <https://github.com/jakebasile>`_
|
||||
* `Vladimir Berkutov <https://github.com/dair-targ>`_
|
||||
* `Jakob Kramer <https://github.com/gandaro>`_
|
||||
* `Chris Faulkner <https://github.com/faulkner>`_
|
||||
* `Alen Mujezinovic <https://github.com/flashingpumpkin>`_
|
||||
* `Praful Mathur <https://github.com/tictactix>`_
|
||||
* `Marc Abramowitz <https://github.com/msabramo>`_
|
||||
* `Ismail Badawi <https://github.com/isbadawi>`_
|
||||
* `Laurent Bachelier <https://github.com/laurentb>`_
|
||||
* `Isman Firmansyah <https://github.com/iromli>`_
|
||||
* `Simon Olofsson <https://github.com/simono>`_
|
||||
* `Churkin Oleg <https://github.com/Bahus>`_
|
||||
* `Jökull Sólberg Auðunsson <https://github.com/jokull>`_
|
||||
* `Matthew M. Boedicker <https://github.com/mmb>`_
|
||||
* `marblar <https://github.com/marblar>`_
|
||||
* `Tomek Wójcik <https://github.com/tomekwojcik>`_
|
||||
* `Davey Shafik <https://github.com/dshafik>`_
|
||||
* `cido <https://github.com/cido>`_
|
||||
* `Justin Bonnar <https://github.com/jargonjustin>`_
|
||||
* `Nathan LaFreniere <https://github.com/nlf>`_
|
||||
* `Matthias Lehmann <https://github.com/matleh>`_
|
||||
* `Dennis Brakhane <https://github.com/brakhane>`_
|
||||
* `Matt Layman <https://github.com/mblayman>`_
|
||||
* `Edward Yang <https://github.com/honorabrutroll>`_
|
||||
* `Aleksandr Vinokurov <https://github.com/aleksandr-vin>`_
|
||||
* `Jeff Byrnes <https://github.com/jeffbyrnes>`_
|
||||
* `Denis Belavin <https://github.com/LuckyDenis>`_
|
||||
|
||||
|
367
CHANGELOG.md
Normal file
367
CHANGELOG.md
Normal file
@ -0,0 +1,367 @@
|
||||
# Change Log
|
||||
|
||||
This document records all notable changes to [HTTPie](https://httpie.io).
|
||||
This project adheres to [Semantic Versioning](https://semver.org/).
|
||||
|
||||
## [2.5.0](https://github.com/httpie/httpie/compare/2.4.0...2.5.0) (2021-09-06)
|
||||
|
||||
- Added `--raw` to allow specifying the raw request body without extra processing as
|
||||
an alternative to `stdin`. ([#534](https://github.com/httpie/httpie/issues/534))
|
||||
- Added support for XML formatting. ([#1129](https://github.com/httpie/httpie/issues/1129))
|
||||
- Added internal support for file-like object responses to improve adapter plugin support. ([#1094](https://github.com/httpie/httpie/issues/1094))
|
||||
- Fixed `--continue --download` with a single byte to be downloaded left. ([#1032](https://github.com/httpie/httpie/issues/1032))
|
||||
- Fixed `--verbose` HTTP 307 redirects with streamed request body. ([#1088](https://github.com/httpie/httpie/issues/1088))
|
||||
- Fixed handling of session files with `Cookie:` followed by other headers. ([#1126](https://github.com/httpie/httpie/issues/1126))
|
||||
|
||||
## [2.4.0](https://github.com/httpie/httpie/compare/2.3.0...2.4.0) (2021-02-06)
|
||||
|
||||
- Added support for `--session` cookie expiration based on `Set-Cookie: max-age=<n>`. ([#1029](https://github.com/httpie/httpie/issues/1029))
|
||||
- Show a `--check-status` warning with `--quiet` as well, not only when the output is redirected. ([#1026](https://github.com/httpie/httpie/issues/1026))
|
||||
- Fixed upload with `--session` ([#1020](https://github.com/httpie/httpie/issues/1020)).
|
||||
- Fixed a missing blank line between request and response ([#1006](https://github.com/httpie/httpie/issues/1006)).
|
||||
|
||||
## [2.3.0](https://github.com/httpie/httpie/compare/2.2.0...2.3.0) (2020-10-25)
|
||||
|
||||
- Added support for streamed uploads ([#201](https://github.com/httpie/httpie/issues/201)).
|
||||
- Added support for multipart upload streaming ([#684](https://github.com/httpie/httpie/issues/684)).
|
||||
- Added support for body-from-file upload streaming (`http pie.dev/post @file`).
|
||||
- Added `--chunked` to enable chunked transfer encoding ([#753](https://github.com/httpie/httpie/issues/753)).
|
||||
- Added `--multipart` to allow `multipart/form-data` encoding for non-file `--form` requests as well.
|
||||
- Added support for preserving field order in multipart requests ([#903](https://github.com/httpie/httpie/issues/903)).
|
||||
- Added `--boundary` to allow a custom boundary string for `multipart/form-data` requests.
|
||||
- Added support for combining cookies specified on the CLI and in a session file ([#932](https://github.com/httpie/httpie/issues/932)).
|
||||
- Added out of the box SOCKS support with no extra installation ([#904](https://github.com/httpie/httpie/issues/904)).
|
||||
- Added `--quiet, -q` flag to enforce silent behaviour.
|
||||
- Fixed the handling of invalid `expires` dates in `Set-Cookie` headers ([#963](https://github.com/httpie/httpie/issues/963)).
|
||||
- Removed Tox testing entirely ([#943](https://github.com/httpie/httpie/issues/943)).
|
||||
|
||||
## [2.2.0](https://github.com/httpie/httpie/compare/2.1.0...2.2.0) (2020-06-18)
|
||||
|
||||
- Added support for custom content types for uploaded files ([#668](https://github.com/httpie/httpie/issues/668)).
|
||||
- Added support for `$XDG_CONFIG_HOME` ([#920](https://github.com/httpie/httpie/issues/920)).
|
||||
- Added support for `Set-Cookie`-triggered cookie expiration ([#853](https://github.com/httpie/httpie/issues/853)).
|
||||
- Added `--format-options` to allow disabling sorting, etc. ([#128](https://github.com/httpie/httpie/issues/128))
|
||||
- Added `--sorted` and `--unsorted` shortcuts for (un)setting all sorting-related `--format-options`. ([#128](https://github.com/httpie/httpie/issues/128))
|
||||
- Added `--ciphers` to allow configuring OpenSSL ciphers ([#870](https://github.com/httpie/httpie/issues/870)).
|
||||
- Added `netrc` support for auth plugins. Enabled for `--auth-type=basic`
|
||||
and `digest`, 3rd parties may opt in ([#718](https://github.com/httpie/httpie/issues/718), [#719](https://github.com/httpie/httpie/issues/719), [#852](https://github.com/httpie/httpie/issues/852), [#934](https://github.com/httpie/httpie/issues/934)).
|
||||
- Fixed built-in plugins-related circular imports ([#925](https://github.com/httpie/httpie/issues/925)).
|
||||
|
||||
## [2.1.0](https://github.com/httpie/httpie/compare/2.0.0...2.1.0) (2020-04-18)
|
||||
|
||||
- Added `--path-as-is` to bypass dot segment (`/../` or `/./`)
|
||||
URL squashing ([#895](https://github.com/httpie/httpie/issues/895)).
|
||||
- Changed the default `Accept` header value for JSON requests from
|
||||
`application/json, */*` to `application/json, */*;q=0.5`
|
||||
to clearly indicate preference ([#488](https://github.com/httpie/httpie/issues/488)).
|
||||
- Fixed `--form` file upload mixed with redirected `stdin` error handling
|
||||
([#840](https://github.com/httpie/httpie/issues/840)).
|
||||
|
||||
## [2.0.0](https://github.com/httpie/httpie/compare/1.0.3...2.0.0) (2020-01-12)
|
||||
|
||||
- Removed Python 2.7 support ([EOL Jan 2020](https://www.python.org/doc/sunset-python-2/).
|
||||
- Added `--offline` to allow building an HTTP request and printing it but not
|
||||
actually sending it over the network.
|
||||
- Replaced the old collect-all-then-process handling of HTTP communication
|
||||
with one-by-one processing of each HTTP request or response as they become
|
||||
available. This means that you can see headers immediately,
|
||||
see what is being sent even if the request fails, etc.
|
||||
- Removed automatic config file creation to avoid concurrency issues.
|
||||
- Removed the default 30-second connection `--timeout` limit.
|
||||
- Removed Python’s default limit of 100 response headers.
|
||||
- Added `--max-headers` to allow setting the max header limit.
|
||||
- Added `--compress` to allow request body compression.
|
||||
- Added `--ignore-netrc` to allow bypassing credentials from `.netrc`.
|
||||
- Added `https` alias command with `https://` as the default scheme.
|
||||
- Added `$ALL_PROXY` documentation.
|
||||
- Added type annotations throughout the codebase.
|
||||
- Added `tests/` to the PyPi package for the convenience of
|
||||
downstream package maintainers.
|
||||
- Fixed an error when `stdin` was a closed fd.
|
||||
- Improved `--debug` output formatting.
|
||||
|
||||
## [1.0.3](https://github.com/httpie/httpie/compare/1.0.2...1.0.3) (2019-08-26)
|
||||
|
||||
- Fixed CVE-2019-10751 — the way the output filename is generated for
|
||||
`--download` requests without `--output` resulting in a redirect has
|
||||
been changed to only consider the initial URL as the base for the generated
|
||||
filename, and not the final one. This fixes a potential security issue under
|
||||
the following scenario:
|
||||
|
||||
1. A `--download` request with no explicit `--output` is made (e.g.,
|
||||
`$ http -d example.org/file.txt`), instructing httpie to
|
||||
[generate the output filename](https://httpie.org/doc#downloaded-filename)
|
||||
from the `Content-Disposition` response header, or from the URL if the header
|
||||
is not provided.
|
||||
2. The server handling the request has been modified by an attacker and
|
||||
instead of the expected response the URL returns a redirect to another
|
||||
URL, e.g., `attacker.example.org/.bash_profile`, whose response does
|
||||
not provide a `Content-Disposition` header (i.e., the base for the
|
||||
generated filename becomes `.bash_profile` instead of `file.txt`).
|
||||
3. Your current directory doesn’t already contain `.bash_profile`
|
||||
(i.e., no unique suffix is added to the generated filename).
|
||||
4. You don’t notice the potentially unexpected output filename
|
||||
as reported by httpie in the console output
|
||||
(e.g., `Downloading 100.00 B to ".bash_profile"`).
|
||||
|
||||
Reported by Raul Onitza and Giulio Comi.
|
||||
|
||||
## [1.0.2](https://github.com/httpie/httpie/compare/1.0.1...1.0.2) (2018-11-14)
|
||||
|
||||
- Fixed tests for installation with pyOpenSSL.
|
||||
|
||||
## [1.0.1](https://github.com/httpie/httpie/compare/1.0.0...1.0.1) (2018-11-14)
|
||||
|
||||
- Removed external URL calls from tests.
|
||||
|
||||
## [1.0.0](https://github.com/httpie/httpie/compare/0.9.9...1.0.0) (2018-11-02)
|
||||
|
||||
- Added `--style=auto` which follows the terminal ANSI color styles.
|
||||
- Added support for selecting TLS 1.3 via `--ssl=tls1.3`
|
||||
(available once implemented in upstream libraries).
|
||||
- Added `true`/`false` as valid values for `--verify`
|
||||
(in addition to `yes`/`no`) and the boolean value is case-insensitive.
|
||||
- Changed the default `--style` from `solarized` to `auto` (on Windows it stays `fruity`).
|
||||
- Fixed default headers being incorrectly case-sensitive.
|
||||
- Removed Python 2.6 support.
|
||||
|
||||
## [0.9.9](https://github.com/httpie/httpie/compare/0.9.8...0.9.9) (2016-12-08)
|
||||
|
||||
- Fixed README.
|
||||
|
||||
## [0.9.8](https://github.com/httpie/httpie/compare/0.9.6...0.9.8) (2016-12-08)
|
||||
|
||||
- Extended auth plugin API.
|
||||
- Added exit status code `7` for plugin errors.
|
||||
- Added support for `curses`-less Python installations.
|
||||
- Fixed `REQUEST_ITEM` arg incorrectly being reported as required.
|
||||
- Improved `CTRL-C` interrupt handling.
|
||||
- Added the standard exit status code `130` for keyboard interrupts.
|
||||
|
||||
## [0.9.6](https://github.com/httpie/httpie/compare/0.9.4...0.9.6) (2016-08-13)
|
||||
|
||||
- Added Python 3 as a dependency for Homebrew installations
|
||||
to ensure some of the newer HTTP features work out of the box
|
||||
for macOS users (starting with HTTPie 0.9.4.).
|
||||
- Added the ability to unset a request header with `Header:`, and send an
|
||||
empty value with `Header;`.
|
||||
- Added `--default-scheme <URL_SCHEME>` to enable things like
|
||||
`$ alias https='http --default-scheme=https`.
|
||||
- Added `-I` as a shortcut for `--ignore-stdin`.
|
||||
- Added fish shell completion (located in `extras/httpie-completion.fish`
|
||||
in the GitHub repo).
|
||||
- Updated `requests` to 2.10.0 so that SOCKS support can be added via
|
||||
`pip install requests[socks]`.
|
||||
- Changed the default JSON `Accept` header from `application/json`
|
||||
to `application/json, */*`.
|
||||
- Changed the pre-processing of request HTTP headers so that any leading
|
||||
and trailing whitespace is removed.
|
||||
|
||||
## [0.9.4](https://github.com/httpie/httpie/compare/0.9.3...0.9.4) (2016-07-01)
|
||||
|
||||
- Added `Content-Type` of files uploaded in `multipart/form-data` requests
|
||||
- Added `--ssl=<PROTOCOL>` to specify the desired SSL/TLS protocol version
|
||||
to use for HTTPS requests.
|
||||
- Added JSON detection with `--json, -j` to work around incorrect
|
||||
`Content-Type`
|
||||
- Added `--all` to show intermediate responses such as redirects (with `--follow`)
|
||||
- Added `--history-print, -P WHAT` to specify formatting of intermediate responses
|
||||
- Added `--max-redirects=N` (default 30)
|
||||
- Added `-A` as short name for `--auth-type`
|
||||
- Added `-F` as short name for `--follow`
|
||||
- Removed the `implicit_content_type` config option
|
||||
(use `"default_options": ["--form"]` instead)
|
||||
- Redirected `stdout` doesn't trigger an error anymore when `--output FILE`
|
||||
is set
|
||||
- Changed the default `--style` back to `solarized` for better support
|
||||
of light and dark terminals
|
||||
- Improved `--debug` output
|
||||
- Fixed `--session` when used with `--download`
|
||||
- Fixed `--download` to trim too long filenames before saving the file
|
||||
- Fixed the handling of `Content-Type` with multiple `+subtype` parts
|
||||
- Removed the XML formatter as the implementation suffered from multiple issues
|
||||
|
||||
## [0.9.3](https://github.com/httpie/httpie/compare/0.9.2...0.9.3) (2016-01-01)
|
||||
|
||||
- Changed the default color `--style` from `solarized` to `monokai`
|
||||
- Added basic Bash autocomplete support (need to be installed manually)
|
||||
- Added request details to connection error messages
|
||||
- Fixed `'requests.packages.urllib3' has no attribute 'disable_warnings'`
|
||||
errors that occurred in some installations
|
||||
- Fixed colors and formatting on Windows
|
||||
- Fixed `--auth` prompt on Windows
|
||||
|
||||
## [0.9.2](https://github.com/httpie/httpie/compare/0.9.1...0.9.2) (2015-02-24)
|
||||
|
||||
- Fixed compatibility with Requests 2.5.1
|
||||
- Changed the default JSON `Content-Type` to `application/json` as UTF-8
|
||||
is the default JSON encoding
|
||||
|
||||
## [0.9.1](https://github.com/httpie/httpie/compare/0.9.0...0.9.1) (2015-02-07)
|
||||
|
||||
- Added support for Requests transport adapter plugins
|
||||
(see [httpie-unixsocket](https://github.com/httpie/httpie-unixsocket)
|
||||
and [httpie-http2](https://github.com/httpie/httpie-http2))
|
||||
|
||||
## [0.9.0](https://github.com/httpie/httpie/compare/0.8.0...0.9.0) (2015-01-31)
|
||||
|
||||
- Added `--cert` and `--cert-key` parameters to specify a client side
|
||||
certificate and private key for SSL
|
||||
- Improved unicode support
|
||||
- Improved terminal color depth detection via `curses`
|
||||
- To make it easier to deal with Windows paths in request items, `\`
|
||||
now only escapes special characters (the ones that are used as key-value
|
||||
separators by HTTPie)
|
||||
- Switched from `unittest` to `pytest`
|
||||
- Added Python `wheel` support
|
||||
- Various test suite improvements
|
||||
- Added `CONTRIBUTING`
|
||||
- Fixed `User-Agent` overwriting when used within a session
|
||||
- Fixed handling of empty passwords in URL credentials
|
||||
- Fixed multiple file uploads with the same form field name
|
||||
- Fixed `--output=/dev/null` on Linux
|
||||
- Miscellaneous bugfixes
|
||||
|
||||
## [0.8.0](https://github.com/httpie/httpie/compare/0.7.1...0.8.0) (2014-01-25)
|
||||
|
||||
- Added `field=@file.txt` and `field:=@file.json` for embedding
|
||||
the contents of text and JSON files into request data
|
||||
- Added curl-style shorthand for localhost
|
||||
- Fixed request `Host` header value output so that it doesn't contain
|
||||
credentials, if included in the URL
|
||||
|
||||
## [0.7.1](https://github.com/httpie/httpie/compare/0.6.0...0.7.1) (2013-09-24)
|
||||
|
||||
- Added `--ignore-stdin`
|
||||
- Added support for auth plugins
|
||||
- Improved `--help` output
|
||||
- Improved `Content-Disposition` parsing for `--download` mode
|
||||
- Update to Requests 2.0.0
|
||||
|
||||
## [0.6.0](https://github.com/httpie/httpie/compare/0.5.1...0.6.0) (2013-06-03)
|
||||
|
||||
- XML data is now formatted
|
||||
- `--session` and `--session-read-only` now also accept paths to
|
||||
session files (eg. `http --session=/tmp/session.json example.org`)
|
||||
|
||||
## [0.5.1](https://github.com/httpie/httpie/compare/0.5.0...0.5.1) (2013-05-13)
|
||||
|
||||
- `Content-*` and `If-*` request headers are not stored in sessions
|
||||
anymore as they are request-specific
|
||||
|
||||
## [0.5.0](https://github.com/httpie/httpie/compare/0.4.1...0.5.0) (2013-04-27)
|
||||
|
||||
- Added a download mode via `--download`
|
||||
- Fixes miscellaneous bugs
|
||||
|
||||
## [0.4.1](https://github.com/httpie/httpie/compare/0.4.0...0.4.1) (2013-02-26)
|
||||
|
||||
- Fixed `setup.py`
|
||||
|
||||
## [0.4.0](https://github.com/httpie/httpie/compare/0.3.0...0.4.0) (2013-02-22)
|
||||
|
||||
- Added Python 3.3 compatibility
|
||||
- Added Requests >= v1.0.4 compatibility
|
||||
- Added support for credentials in URL
|
||||
- Added `--no-option` for every `--option` to be config-friendly
|
||||
- Mutually exclusive arguments can be specified multiple times. The
|
||||
last value is used
|
||||
|
||||
## [0.3.0](https://github.com/httpie/httpie/compare/0.2.7...0.3.0) (2012-09-21)
|
||||
|
||||
- Allow output redirection on Windows
|
||||
- Added configuration file
|
||||
- Added persistent session support
|
||||
- Renamed `--allow-redirects` to `--follow`
|
||||
- Improved the usability of `http --help`
|
||||
- Fixed installation on Windows with Python 3
|
||||
- Fixed colorized output on Windows with Python 3
|
||||
- CRLF HTTP header field separation in the output
|
||||
- Added exit status code `2` for timed-out requests
|
||||
- Added the option to separate colorizing and formatting
|
||||
(`--pretty=all`, `--pretty=colors` and `--pretty=format`)
|
||||
`--ugly` has bee removed in favor of `--pretty=none`
|
||||
|
||||
## [0.2.7](https://github.com/httpie/httpie/compare/0.2.5...0.2.7) (2012-08-07)
|
||||
|
||||
- Added compatibility with Requests 0.13.6
|
||||
- Added streamed terminal output. `--stream, -S` can be used to enable
|
||||
streaming also with `--pretty` and to ensure a more frequent output
|
||||
flushing
|
||||
- Added support for efficient large file downloads
|
||||
- Sort headers by name (unless `--pretty=none`)
|
||||
- Response body is fetched only when needed (e.g., not with `--headers`)
|
||||
- Improved content type matching
|
||||
- Updated Solarized color scheme
|
||||
- Windows: Added `--output FILE` to store output into a file
|
||||
(piping results in corrupted data on Windows)
|
||||
- Proper handling of binary requests and responses
|
||||
- Fixed printing of `multipart/form-data` requests
|
||||
- Renamed `--traceback` to `--debug`
|
||||
|
||||
## [0.2.6](https://github.com/httpie/httpie/compare/0.2.5...0.2.6) (2012-07-26)
|
||||
|
||||
- The short option for `--headers` is now `-h` (`-t` has been
|
||||
removed, for usage use `--help`)
|
||||
- Form data and URL parameters can have multiple fields with the same name
|
||||
(e.g.,`http -f url a=1 a=2`)
|
||||
- Added `--check-status` to exit with an error on HTTP 3xx, 4xx and
|
||||
5xx (3, 4, and 5, respectively)
|
||||
- If the output is piped to another program or redirected to a file,
|
||||
the default behaviour is to only print the response body
|
||||
(It can still be overwritten via the `--print` flag.)
|
||||
- Improved highlighting of HTTP headers
|
||||
- Added query string parameters (`param==value`)
|
||||
- Added support for terminal colors under Windows
|
||||
|
||||
## [0.2.5](https://github.com/httpie/httpie/compare/0.2.2...0.2.5) (2012-07-17)
|
||||
|
||||
- Unicode characters in prettified JSON now don't get escaped for
|
||||
improved readability
|
||||
- --auth now prompts for a password if only a username provided
|
||||
- Added support for request payloads from a file path with automatic
|
||||
`Content-Type` (`http URL @/path`)
|
||||
- Fixed missing query string when displaying the request headers via
|
||||
`--verbose`
|
||||
- Fixed Content-Type for requests with no data
|
||||
|
||||
## [0.2.2](https://github.com/httpie/httpie/compare/0.2.1...0.2.2) (2012-06-24)
|
||||
|
||||
- The `METHOD` positional argument can now be omitted (defaults to
|
||||
`GET`, or to `POST` with data)
|
||||
- Fixed --verbose --form
|
||||
- Added support for Tox
|
||||
|
||||
## [0.2.1](https://github.com/httpie/httpie/compare/0.2.0...0.2.1) (2012-06-13)
|
||||
|
||||
- Added compatibility with `requests-0.12.1`
|
||||
- Dropped custom JSON and HTTP lexers in favor of the ones newly included
|
||||
in `pygments-1.5`
|
||||
|
||||
## [0.2.0](https://github.com/httpie/httpie/compare/0.1.6...0.2.0) (2012-04-25)
|
||||
|
||||
- Added Python 3 support
|
||||
- Added the ability to print the HTTP request as well as the response
|
||||
(see `--print` and `--verbose`)
|
||||
- Added support for Digest authentication
|
||||
- Added file upload support
|
||||
(`http -f POST file_field_name@/path/to/file`)
|
||||
- Improved syntax highlighting for JSON
|
||||
- Added support for field name escaping
|
||||
- Many bug fixes
|
||||
|
||||
## [0.1.6](https://github.com/httpie/httpie/compare/0.1.5...0.1.6) (2012-03-04)
|
||||
|
||||
- Fixed `setup.py`
|
||||
|
||||
## [0.1.5](https://github.com/httpie/httpie/compare/0.1.4...0.1.5) (2012-03-04)
|
||||
|
||||
- Many improvements and bug fixes
|
||||
|
||||
## [0.1.4](https://github.com/httpie/httpie/compare/b966efa...0.1.4) (2012-02-28)
|
||||
|
||||
- Many improvements and bug fixes
|
||||
|
||||
## [0.1.0](https://github.com/httpie/httpie/commit/b966efa) (2012-02-25)
|
||||
|
||||
- Initial public release
|
494
CHANGELOG.rst
494
CHANGELOG.rst
@ -1,494 +0,0 @@
|
||||
==========
|
||||
Change Log
|
||||
==========
|
||||
|
||||
This document records all notable changes to `HTTPie <https://httpie.org>`_.
|
||||
This project adheres to `Semantic Versioning <https://semver.org/>`_.
|
||||
|
||||
|
||||
|
||||
`2.4.0`_ (2021-02-06)
|
||||
---------------------
|
||||
* Added support for ``--session`` cookie expiration based on ``Set-Cookie: max-age=<n>``. (`#1029`_)
|
||||
* Show a ``--check-status`` warning with ``--quiet`` as well, not only when the output si redirected. (`#1026`_)
|
||||
* Fixed upload with ``--session`` (`#1020`_).
|
||||
* Fixed a missing blank line between request and response (`#1006`_).
|
||||
|
||||
|
||||
`2.3.0`_ (2020-10-25)
|
||||
-------------------------
|
||||
|
||||
* Added support for streamed uploads (`#201`_).
|
||||
* Added support for multipart upload streaming (`#684`_).
|
||||
* Added support for body-from-file upload streaming (``http pie.dev/post @file``).
|
||||
* Added ``--chunked`` to enable chunked transfer encoding (`#753`_).
|
||||
* Added ``--multipart`` to allow ``multipart/form-data`` encoding for non-file ``--form`` requests as well.
|
||||
* Added support for preserving field order in multipart requests (`#903`_).
|
||||
* Added ``--boundary`` to allow a custom boundary string for ``multipart/form-data`` requests.
|
||||
* Added support for combining cookies specified on the CLI and in a session file (`#932`_).
|
||||
* Added out of the box SOCKS support with no extra installation (`#904`_).
|
||||
* Added ``--quiet, -q`` flag to enforce silent behaviour.
|
||||
* Fixed the handling of invalid ``expires`` dates in ``Set-Cookie`` headers (`#963`_).
|
||||
* Removed Tox testing entirely (`#943`_).
|
||||
|
||||
|
||||
`2.2.0`_ (2020-06-18)
|
||||
-------------------------
|
||||
|
||||
* Added support for custom content types for uploaded files (`#668`_).
|
||||
* Added support for ``$XDG_CONFIG_HOME`` (`#920`_).
|
||||
* Added support for ``Set-Cookie``-triggered cookie expiration (`#853`_).
|
||||
* Added ``--format-options`` to allow disabling sorting, etc. (`#128`_)
|
||||
* Added ``--sorted`` and ``--unsorted`` shortcuts for (un)setting all sorting-related ``--format-options``. (`#128`_)
|
||||
* Added ``--ciphers`` to allow configuring OpenSSL ciphers (`#870`_).
|
||||
* Added ``netrc`` support for auth plugins. Enabled for ``--auth-type=basic``
|
||||
and ``digest``, 3rd parties may opt in (`#718`_, `#719`_, `#852`_, `#934`_).
|
||||
* Fixed built-in plugins-related circular imports (`#925`_).
|
||||
|
||||
|
||||
`2.1.0`_ (2020-04-18)
|
||||
---------------------
|
||||
|
||||
* Added ``--path-as-is`` to bypass dot segment (``/../`` or ``/./``)
|
||||
URL squashing (`#895`_).
|
||||
* Changed the default ``Accept`` header value for JSON requests from
|
||||
``application/json, */*`` to ``application/json, */*;q=0.5``
|
||||
to clearly indicate preference (`#488`_).
|
||||
* Fixed ``--form`` file upload mixed with redirected ``stdin`` error handling
|
||||
(`#840`_).
|
||||
|
||||
|
||||
`2.0.0`_ (2020-01-12)
|
||||
-------------------------
|
||||
* Removed Python 2.7 support (`EOL Jan 2020 <https://www.python.org/doc/sunset-python-2/>`_).
|
||||
* Added ``--offline`` to allow building an HTTP request and printing it but not
|
||||
actually sending it over the network.
|
||||
* Replaced the old collect-all-then-process handling of HTTP communication
|
||||
with one-by-one processing of each HTTP request or response as they become
|
||||
available. This means that you can see headers immediately,
|
||||
see what is being sent even if the request fails, etc.
|
||||
* Removed automatic config file creation to avoid concurrency issues.
|
||||
* Removed the default 30-second connection ``--timeout`` limit.
|
||||
* Removed Python’s default limit of 100 response headers.
|
||||
* Added ``--max-headers`` to allow setting the max header limit.
|
||||
* Added ``--compress`` to allow request body compression.
|
||||
* Added ``--ignore-netrc`` to allow bypassing credentials from ``.netrc``.
|
||||
* Added ``https`` alias command with ``https://`` as the default scheme.
|
||||
* Added ``$ALL_PROXY`` documentation.
|
||||
* Added type annotations throughout the codebase.
|
||||
* Added ``tests/`` to the PyPi package for the convenience of
|
||||
downstream package maintainers.
|
||||
* Fixed an error when ``stdin`` was a closed fd.
|
||||
* Improved ``--debug`` output formatting.
|
||||
|
||||
|
||||
`1.0.3`_ (2019-08-26)
|
||||
---------------------
|
||||
|
||||
* Fixed CVE-2019-10751 — the way the output filename is generated for
|
||||
``--download`` requests without ``--output`` resulting in a redirect has
|
||||
been changed to only consider the initial URL as the base for the generated
|
||||
filename, and not the final one. This fixes a potential security issue under
|
||||
the following scenario:
|
||||
|
||||
1. A ``--download`` request with no explicit ``--output`` is made (e.g.,
|
||||
``$ http -d example.org/file.txt``), instructing httpie to
|
||||
`generate the output filename <https://httpie.org/doc#downloaded-filename>`_
|
||||
from the ``Content-Disposition`` response header, or from the URL if the header
|
||||
is not provided.
|
||||
2. The server handling the request has been modified by an attacker and
|
||||
instead of the expected response the URL returns a redirect to another
|
||||
URL, e.g., ``attacker.example.org/.bash_profile``, whose response does
|
||||
not provide a ``Content-Disposition`` header (i.e., the base for the
|
||||
generated filename becomes ``.bash_profile`` instead of ``file.txt``).
|
||||
3. Your current directory doesn’t already contain ``.bash_profile``
|
||||
(i.e., no unique suffix is added to the generated filename).
|
||||
4. You don’t notice the potentially unexpected output filename
|
||||
as reported by httpie in the console output
|
||||
(e.g., ``Downloading 100.00 B to ".bash_profile"``).
|
||||
|
||||
Reported by Raul Onitza and Giulio Comi.
|
||||
|
||||
|
||||
`1.0.2`_ (2018-11-14)
|
||||
-------------------------
|
||||
|
||||
* Fixed tests for installation with pyOpenSSL.
|
||||
|
||||
|
||||
`1.0.1`_ (2018-11-14)
|
||||
-------------------------
|
||||
|
||||
* Removed external URL calls from tests.
|
||||
|
||||
|
||||
`1.0.0`_ (2018-11-02)
|
||||
-------------------------
|
||||
|
||||
* Added ``--style=auto`` which follows the terminal ANSI color styles.
|
||||
* Added support for selecting TLS 1.3 via ``--ssl=tls1.3``
|
||||
(available once implemented in upstream libraries).
|
||||
* Added ``true``/``false`` as valid values for ``--verify``
|
||||
(in addition to ``yes``/``no``) and the boolean value is case-insensitive.
|
||||
* Changed the default ``--style`` from ``solarized`` to ``auto`` (on Windows it stays ``fruity``).
|
||||
* Fixed default headers being incorrectly case-sensitive.
|
||||
* Removed Python 2.6 support.
|
||||
|
||||
|
||||
|
||||
`0.9.9`_ (2016-12-08)
|
||||
---------------------
|
||||
|
||||
* Fixed README.
|
||||
|
||||
|
||||
`0.9.8`_ (2016-12-08)
|
||||
---------------------
|
||||
|
||||
* Extended auth plugin API.
|
||||
* Added exit status code ``7`` for plugin errors.
|
||||
* Added support for ``curses``-less Python installations.
|
||||
* Fixed ``REQUEST_ITEM`` arg incorrectly being reported as required.
|
||||
* Improved ``CTRL-C`` interrupt handling.
|
||||
* Added the standard exit status code ``130`` for keyboard interrupts.
|
||||
|
||||
|
||||
`0.9.6`_ (2016-08-13)
|
||||
---------------------
|
||||
|
||||
* Added Python 3 as a dependency for Homebrew installations
|
||||
to ensure some of the newer HTTP features work out of the box
|
||||
for macOS users (starting with HTTPie 0.9.4.).
|
||||
* Added the ability to unset a request header with ``Header:``, and send an
|
||||
empty value with ``Header;``.
|
||||
* Added ``--default-scheme <URL_SCHEME>`` to enable things like
|
||||
``$ alias https='http --default-scheme=https``.
|
||||
* Added ``-I`` as a shortcut for ``--ignore-stdin``.
|
||||
* Added fish shell completion (located in ``extras/httpie-completion.fish``
|
||||
in the GitHub repo).
|
||||
* Updated ``requests`` to 2.10.0 so that SOCKS support can be added via
|
||||
``pip install requests[socks]``.
|
||||
* Changed the default JSON ``Accept`` header from ``application/json``
|
||||
to ``application/json, */*``.
|
||||
* Changed the pre-processing of request HTTP headers so that any leading
|
||||
and trailing whitespace is removed.
|
||||
|
||||
|
||||
`0.9.4`_ (2016-07-01)
|
||||
---------------------
|
||||
|
||||
* Added ``Content-Type`` of files uploaded in ``multipart/form-data`` requests
|
||||
* Added ``--ssl=<PROTOCOL>`` to specify the desired SSL/TLS protocol version
|
||||
to use for HTTPS requests.
|
||||
* Added JSON detection with ``--json, -j`` to work around incorrect
|
||||
``Content-Type``
|
||||
* Added ``--all`` to show intermediate responses such as redirects (with ``--follow``)
|
||||
* Added ``--history-print, -P WHAT`` to specify formatting of intermediate responses
|
||||
* Added ``--max-redirects=N`` (default 30)
|
||||
* Added ``-A`` as short name for ``--auth-type``
|
||||
* Added ``-F`` as short name for ``--follow``
|
||||
* Removed the ``implicit_content_type`` config option
|
||||
(use ``"default_options": ["--form"]`` instead)
|
||||
* Redirected ``stdout`` doesn't trigger an error anymore when ``--output FILE``
|
||||
is set
|
||||
* Changed the default ``--style`` back to ``solarized`` for better support
|
||||
of light and dark terminals
|
||||
* Improved ``--debug`` output
|
||||
* Fixed ``--session`` when used with ``--download``
|
||||
* Fixed ``--download`` to trim too long filenames before saving the file
|
||||
* Fixed the handling of ``Content-Type`` with multiple ``+subtype`` parts
|
||||
* Removed the XML formatter as the implementation suffered from multiple issues
|
||||
|
||||
|
||||
|
||||
`0.9.3`_ (2016-01-01)
|
||||
---------------------
|
||||
|
||||
* Changed the default color ``--style`` from ``solarized`` to ``monokai``
|
||||
* Added basic Bash autocomplete support (need to be installed manually)
|
||||
* Added request details to connection error messages
|
||||
* Fixed ``'requests.packages.urllib3' has no attribute 'disable_warnings'``
|
||||
errors that occurred in some installations
|
||||
* Fixed colors and formatting on Windows
|
||||
* Fixed ``--auth`` prompt on Windows
|
||||
|
||||
|
||||
`0.9.2`_ (2015-02-24)
|
||||
---------------------
|
||||
|
||||
* Fixed compatibility with Requests 2.5.1
|
||||
* Changed the default JSON ``Content-Type`` to ``application/json`` as UTF-8
|
||||
is the default JSON encoding
|
||||
|
||||
|
||||
`0.9.1`_ (2015-02-07)
|
||||
---------------------
|
||||
|
||||
* Added support for Requests transport adapter plugins
|
||||
(see `httpie-unixsocket <https://github.com/httpie/httpie-unixsocket>`_
|
||||
and `httpie-http2 <https://github.com/httpie/httpie-http2>`_)
|
||||
|
||||
|
||||
`0.9.0`_ (2015-01-31)
|
||||
---------------------
|
||||
|
||||
* Added ``--cert`` and ``--cert-key`` parameters to specify a client side
|
||||
certificate and private key for SSL
|
||||
* Improved unicode support
|
||||
* Improved terminal color depth detection via ``curses``
|
||||
* To make it easier to deal with Windows paths in request items, ``\``
|
||||
now only escapes special characters (the ones that are used as key-value
|
||||
separators by HTTPie)
|
||||
* Switched from ``unittest`` to ``pytest``
|
||||
* Added Python `wheel` support
|
||||
* Various test suite improvements
|
||||
* Added ``CONTRIBUTING``
|
||||
* Fixed ``User-Agent`` overwriting when used within a session
|
||||
* Fixed handling of empty passwords in URL credentials
|
||||
* Fixed multiple file uploads with the same form field name
|
||||
* Fixed ``--output=/dev/null`` on Linux
|
||||
* Miscellaneous bugfixes
|
||||
|
||||
|
||||
`0.8.0`_ (2014-01-25)
|
||||
---------------------
|
||||
|
||||
* Added ``field=@file.txt`` and ``field:=@file.json`` for embedding
|
||||
the contents of text and JSON files into request data
|
||||
* Added curl-style shorthand for localhost
|
||||
* Fixed request ``Host`` header value output so that it doesn't contain
|
||||
credentials, if included in the URL
|
||||
|
||||
|
||||
`0.7.1`_ (2013-09-24)
|
||||
---------------------
|
||||
|
||||
* Added ``--ignore-stdin``
|
||||
* Added support for auth plugins
|
||||
* Improved ``--help`` output
|
||||
* Improved ``Content-Disposition`` parsing for ``--download`` mode
|
||||
* Update to Requests 2.0.0
|
||||
|
||||
|
||||
`0.6.0`_ (2013-06-03)
|
||||
---------------------
|
||||
|
||||
* XML data is now formatted
|
||||
* ``--session`` and ``--session-read-only`` now also accept paths to
|
||||
session files (eg. ``http --session=/tmp/session.json example.org``)
|
||||
|
||||
|
||||
`0.5.1`_ (2013-05-13)
|
||||
---------------------
|
||||
|
||||
* ``Content-*`` and ``If-*`` request headers are not stored in sessions
|
||||
anymore as they are request-specific
|
||||
|
||||
|
||||
`0.5.0`_ (2013-04-27)
|
||||
---------------------
|
||||
|
||||
* Added a download mode via ``--download``
|
||||
* Fixes miscellaneous bugs
|
||||
|
||||
|
||||
`0.4.1`_ (2013-02-26)
|
||||
---------------------
|
||||
|
||||
* Fixed ``setup.py``
|
||||
|
||||
|
||||
`0.4.0`_ (2013-02-22)
|
||||
---------------------
|
||||
|
||||
* Added Python 3.3 compatibility
|
||||
* Added Requests >= v1.0.4 compatibility
|
||||
* Added support for credentials in URL
|
||||
* Added ``--no-option`` for every ``--option`` to be config-friendly
|
||||
* Mutually exclusive arguments can be specified multiple times. The
|
||||
last value is used
|
||||
|
||||
|
||||
`0.3.0`_ (2012-09-21)
|
||||
---------------------
|
||||
|
||||
* Allow output redirection on Windows
|
||||
* Added configuration file
|
||||
* Added persistent session support
|
||||
* Renamed ``--allow-redirects`` to ``--follow``
|
||||
* Improved the usability of ``http --help``
|
||||
* Fixed installation on Windows with Python 3
|
||||
* Fixed colorized output on Windows with Python 3
|
||||
* CRLF HTTP header field separation in the output
|
||||
* Added exit status code ``2`` for timed-out requests
|
||||
* Added the option to separate colorizing and formatting
|
||||
(``--pretty=all``, ``--pretty=colors`` and ``--pretty=format``)
|
||||
``--ugly`` has bee removed in favor of ``--pretty=none``
|
||||
|
||||
|
||||
`0.2.7`_ (2012-08-07)
|
||||
---------------------
|
||||
|
||||
* Added compatibility with Requests 0.13.6
|
||||
* Added streamed terminal output. ``--stream, -S`` can be used to enable
|
||||
streaming also with ``--pretty`` and to ensure a more frequent output
|
||||
flushing
|
||||
* Added support for efficient large file downloads
|
||||
* Sort headers by name (unless ``--pretty=none``)
|
||||
* Response body is fetched only when needed (e.g., not with ``--headers``)
|
||||
* Improved content type matching
|
||||
* Updated Solarized color scheme
|
||||
* Windows: Added ``--output FILE`` to store output into a file
|
||||
(piping results in corrupted data on Windows)
|
||||
* Proper handling of binary requests and responses
|
||||
* Fixed printing of ``multipart/form-data`` requests
|
||||
* Renamed ``--traceback`` to ``--debug``
|
||||
|
||||
|
||||
`0.2.6`_ (2012-07-26)
|
||||
---------------------
|
||||
|
||||
* The short option for ``--headers`` is now ``-h`` (``-t`` has been
|
||||
removed, for usage use ``--help``)
|
||||
* Form data and URL parameters can have multiple fields with the same name
|
||||
(e.g.,``http -f url a=1 a=2``)
|
||||
* Added ``--check-status`` to exit with an error on HTTP 3xx, 4xx and
|
||||
5xx (3, 4, and 5, respectively)
|
||||
* If the output is piped to another program or redirected to a file,
|
||||
the default behaviour is to only print the response body
|
||||
(It can still be overwritten via the ``--print`` flag.)
|
||||
* Improved highlighting of HTTP headers
|
||||
* Added query string parameters (``param==value``)
|
||||
* Added support for terminal colors under Windows
|
||||
|
||||
|
||||
`0.2.5`_ (2012-07-17)
|
||||
---------------------
|
||||
|
||||
* Unicode characters in prettified JSON now don't get escaped for
|
||||
improved readability
|
||||
* --auth now prompts for a password if only a username provided
|
||||
* Added support for request payloads from a file path with automatic
|
||||
``Content-Type`` (``http URL @/path``)
|
||||
* Fixed missing query string when displaying the request headers via
|
||||
``--verbose``
|
||||
* Fixed Content-Type for requests with no data
|
||||
|
||||
|
||||
`0.2.2`_ (2012-06-24)
|
||||
---------------------
|
||||
|
||||
* The ``METHOD`` positional argument can now be omitted (defaults to
|
||||
``GET``, or to ``POST`` with data)
|
||||
* Fixed --verbose --form
|
||||
* Added support for Tox
|
||||
|
||||
|
||||
`0.2.1`_ (2012-06-13)
|
||||
---------------------
|
||||
|
||||
* Added compatibility with ``requests-0.12.1``
|
||||
* Dropped custom JSON and HTTP lexers in favor of the ones newly included
|
||||
in ``pygments-1.5``
|
||||
|
||||
|
||||
`0.2.0`_ (2012-04-25)
|
||||
---------------------
|
||||
|
||||
* Added Python 3 support
|
||||
* Added the ability to print the HTTP request as well as the response
|
||||
(see ``--print`` and ``--verbose``)
|
||||
* Added support for Digest authentication
|
||||
* Added file upload support
|
||||
(``http -f POST file_field_name@/path/to/file``)
|
||||
* Improved syntax highlighting for JSON
|
||||
* Added support for field name escaping
|
||||
* Many bug fixes
|
||||
|
||||
|
||||
`0.1.6`_ (2012-03-04)
|
||||
---------------------
|
||||
|
||||
* Fixed ``setup.py``
|
||||
|
||||
|
||||
`0.1.5`_ (2012-03-04)
|
||||
---------------------
|
||||
|
||||
* Many improvements and bug fixes
|
||||
|
||||
|
||||
`0.1.4`_ (2012-02-28)
|
||||
---------------------
|
||||
|
||||
* Many improvements and bug fixes
|
||||
|
||||
|
||||
`0.1.0`_ (2012-02-25)
|
||||
---------------------
|
||||
|
||||
* Initial public release
|
||||
|
||||
|
||||
.. _`0.1.0`: https://github.com/httpie/httpie/commit/b966efa
|
||||
.. _0.1.4: https://github.com/httpie/httpie/compare/b966efa...0.1.4
|
||||
.. _0.1.5: https://github.com/httpie/httpie/compare/0.1.4...0.1.5
|
||||
.. _0.1.6: https://github.com/httpie/httpie/compare/0.1.5...0.1.6
|
||||
.. _0.2.0: https://github.com/httpie/httpie/compare/0.1.6...0.2.0
|
||||
.. _0.2.1: https://github.com/httpie/httpie/compare/0.2.0...0.2.1
|
||||
.. _0.2.2: https://github.com/httpie/httpie/compare/0.2.1...0.2.2
|
||||
.. _0.2.5: https://github.com/httpie/httpie/compare/0.2.2...0.2.5
|
||||
.. _0.2.6: https://github.com/httpie/httpie/compare/0.2.5...0.2.6
|
||||
.. _0.2.7: https://github.com/httpie/httpie/compare/0.2.5...0.2.7
|
||||
.. _0.3.0: https://github.com/httpie/httpie/compare/0.2.7...0.3.0
|
||||
.. _0.4.0: https://github.com/httpie/httpie/compare/0.3.0...0.4.0
|
||||
.. _0.4.1: https://github.com/httpie/httpie/compare/0.4.0...0.4.1
|
||||
.. _0.5.0: https://github.com/httpie/httpie/compare/0.4.1...0.5.0
|
||||
.. _0.5.1: https://github.com/httpie/httpie/compare/0.5.0...0.5.1
|
||||
.. _0.6.0: https://github.com/httpie/httpie/compare/0.5.1...0.6.0
|
||||
.. _0.7.1: https://github.com/httpie/httpie/compare/0.6.0...0.7.1
|
||||
.. _0.8.0: https://github.com/httpie/httpie/compare/0.7.1...0.8.0
|
||||
.. _0.9.0: https://github.com/httpie/httpie/compare/0.8.0...0.9.0
|
||||
.. _0.9.1: https://github.com/httpie/httpie/compare/0.9.0...0.9.1
|
||||
.. _0.9.2: https://github.com/httpie/httpie/compare/0.9.1...0.9.2
|
||||
.. _0.9.3: https://github.com/httpie/httpie/compare/0.9.2...0.9.3
|
||||
.. _0.9.4: https://github.com/httpie/httpie/compare/0.9.3...0.9.4
|
||||
.. _0.9.6: https://github.com/httpie/httpie/compare/0.9.4...0.9.6
|
||||
.. _0.9.8: https://github.com/httpie/httpie/compare/0.9.6...0.9.8
|
||||
.. _0.9.9: https://github.com/httpie/httpie/compare/0.9.8...0.9.9
|
||||
.. _1.0.0: https://github.com/httpie/httpie/compare/0.9.9...1.0.0
|
||||
.. _1.0.1: https://github.com/httpie/httpie/compare/1.0.0...1.0.1
|
||||
.. _1.0.2: https://github.com/httpie/httpie/compare/1.0.1...1.0.2
|
||||
.. _1.0.3: https://github.com/httpie/httpie/compare/1.0.2...1.0.3
|
||||
.. _2.0.0: https://github.com/httpie/httpie/compare/1.0.3...2.0.0
|
||||
.. _2.1.0: https://github.com/httpie/httpie/compare/2.0.0...2.1.0
|
||||
.. _2.2.0: https://github.com/httpie/httpie/compare/2.1.0...2.2.0
|
||||
.. _2.3.0: https://github.com/httpie/httpie/compare/2.2.0...2.3.0
|
||||
.. _2.4.0: https://github.com/httpie/httpie/compare/2.3.0...2.4.0
|
||||
.. _2.5.0-dev: https://github.com/httpie/httpie/compare/2.4.0...master
|
||||
|
||||
.. _#128: https://github.com/httpie/httpie/issues/128
|
||||
.. _#201: https://github.com/httpie/httpie/issues/201
|
||||
.. _#488: https://github.com/httpie/httpie/issues/488
|
||||
.. _#668: https://github.com/httpie/httpie/issues/668
|
||||
.. _#684: https://github.com/httpie/httpie/issues/684
|
||||
.. _#718: https://github.com/httpie/httpie/issues/718
|
||||
.. _#719: https://github.com/httpie/httpie/issues/719
|
||||
.. _#753: https://github.com/httpie/httpie/issues/753
|
||||
.. _#840: https://github.com/httpie/httpie/issues/840
|
||||
.. _#853: https://github.com/httpie/httpie/issues/853
|
||||
.. _#852: https://github.com/httpie/httpie/issues/852
|
||||
.. _#870: https://github.com/httpie/httpie/issues/870
|
||||
.. _#895: https://github.com/httpie/httpie/issues/895
|
||||
.. _#903: https://github.com/httpie/httpie/issues/903
|
||||
.. _#920: https://github.com/httpie/httpie/issues/920
|
||||
.. _#904: https://github.com/httpie/httpie/issues/904
|
||||
.. _#925: https://github.com/httpie/httpie/issues/925
|
||||
.. _#932: https://github.com/httpie/httpie/issues/932
|
||||
.. _#934: https://github.com/httpie/httpie/issues/934
|
||||
.. _#943: https://github.com/httpie/httpie/issues/943
|
||||
.. _#963: https://github.com/httpie/httpie/issues/963
|
||||
.. _#1006: https://github.com/httpie/httpie/issues/1006
|
||||
.. _#1020: https://github.com/httpie/httpie/issues/1020
|
||||
.. _#1026: https://github.com/httpie/httpie/issues/1026
|
||||
.. _#1029: https://github.com/httpie/httpie/issues/1029
|
@ -14,22 +14,22 @@ appearance, race, religion, or sexual identity and orientation.
|
||||
Examples of behavior that contributes to creating a positive environment
|
||||
include:
|
||||
|
||||
* Using welcoming and inclusive language
|
||||
* Being respectful of differing viewpoints and experiences
|
||||
* Gracefully accepting constructive criticism
|
||||
* Focusing on what is best for the community
|
||||
* Showing empathy towards other community members
|
||||
- Using welcoming and inclusive language
|
||||
- Being respectful of differing viewpoints and experiences
|
||||
- Gracefully accepting constructive criticism
|
||||
- Focusing on what is best for the community
|
||||
- Showing empathy towards other community members
|
||||
|
||||
Examples of unacceptable behavior by participants include:
|
||||
|
||||
* The use of sexualized language or imagery and unwelcome sexual attention or
|
||||
advances
|
||||
* Trolling, insulting/derogatory comments, and personal or political attacks
|
||||
* Public or private harassment
|
||||
* Publishing others' private information, such as a physical or electronic
|
||||
address, without explicit permission
|
||||
* Other conduct which could reasonably be considered inappropriate in a
|
||||
professional setting
|
||||
- The use of sexualized language or imagery and unwelcome sexual attention or
|
||||
advances
|
||||
- Trolling, insulting/derogatory comments, and personal or political attacks
|
||||
- Public or private harassment
|
||||
- Publishing others' private information, such as a physical or electronic
|
||||
address, without explicit permission
|
||||
- Other conduct which could reasonably be considered inappropriate in a
|
||||
professional setting
|
||||
|
||||
## Our Responsibilities
|
||||
|
||||
@ -67,10 +67,8 @@ members of the project's leadership.
|
||||
|
||||
## Attribution
|
||||
|
||||
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
|
||||
available at https://www.contributor-covenant.org/version/1/4/code-of-conduct.html
|
||||
|
||||
[homepage]: https://www.contributor-covenant.org
|
||||
This Code of Conduct is adapted from the [Contributor Covenant](https://www.contributor-covenant.org),
|
||||
version 1.4, available at https://www.contributor-covenant.org/version/1/4/code-of-conduct.html
|
||||
|
||||
For answers to common questions about this code of conduct, see
|
||||
https://www.contributor-covenant.org/faq
|
||||
|
196
CONTRIBUTING.md
Normal file
196
CONTRIBUTING.md
Normal file
@ -0,0 +1,196 @@
|
||||
# Contributing to HTTPie
|
||||
|
||||
Bug reports and code and documentation patches are welcome. You can
|
||||
help this project also by using the development version of HTTPie
|
||||
and by reporting any bugs you might encounter.
|
||||
|
||||
## 1. Reporting bugs
|
||||
|
||||
**It's important that you provide the full command argument list
|
||||
as well as the output of the failing command.**
|
||||
|
||||
Use the `--debug` flag and copy&paste both the command and its output
|
||||
to your bug report, e.g.:
|
||||
|
||||
```bash
|
||||
$ http --debug <COMPLETE ARGUMENT LIST THAT TRIGGERS THE ERROR>
|
||||
<COMPLETE OUTPUT>
|
||||
```
|
||||
|
||||
## 2. Contributing Code and Docs
|
||||
|
||||
Before working on a new feature or a bug, please browse [existing issues](https://github.com/httpie/httpie/issues)
|
||||
to see whether it has previously been discussed.
|
||||
|
||||
If your change alters HTTPie’s behaviour or interface, it's a good idea to
|
||||
discuss it before you start working on it.
|
||||
|
||||
If you are fixing an issue, the first step should be to create a test case that
|
||||
reproduces the incorrect behaviour. That will also help you to build an
|
||||
understanding of the issue at hand.
|
||||
|
||||
**Pull requests introducing code changes without tests
|
||||
will generally not get merged. The same goes for PRs changing HTTPie’s
|
||||
behaviour and not providing documentation.**
|
||||
|
||||
Conversely, PRs consisting of documentation improvements or tests
|
||||
for existing-yet-previously-untested behavior will very likely be merged.
|
||||
Therefore, docs and tests improvements are a great candidate for your first
|
||||
contribution.
|
||||
|
||||
Consider also adding a [CHANGELOG](https://github.com/httpie/httpie/blob/master/CHANGELOG.md) entry for your changes.
|
||||
|
||||
### Development Environment
|
||||
|
||||
#### Getting the code
|
||||
|
||||
Go to https://github.com/httpie/httpie and fork the project repository.
|
||||
|
||||
```bash
|
||||
# Clone your fork
|
||||
$ git clone git@github.com:<YOU>/httpie.git
|
||||
|
||||
# Enter the project directory
|
||||
$ cd httpie
|
||||
|
||||
# Create a branch for your changes
|
||||
$ git checkout -b my_topical_branch
|
||||
```
|
||||
|
||||
#### Setup
|
||||
|
||||
The [Makefile](https://github.com/httpie/httpie/blob/master/Makefile) contains a bunch of tasks to get you started. Just run
|
||||
the following command, which:
|
||||
|
||||
- Creates an isolated Python virtual environment inside `./venv`
|
||||
(via the standard library [venv](https://docs.python.org/3/library/venv.html) tool);
|
||||
- installs all dependencies and also installs HTTPie
|
||||
(in editable mode so that the `http` command will point to your
|
||||
working copy).
|
||||
- and runs tests (It is the same as running `make install test`).
|
||||
|
||||
```bash
|
||||
$ make
|
||||
```
|
||||
|
||||
#### Python virtual environment
|
||||
|
||||
Activate the Python virtual environment—created via the `make install`
|
||||
task during [setup](#setup) for your active shell session using the following command:
|
||||
|
||||
```bash
|
||||
$ source venv/bin/activate
|
||||
```
|
||||
|
||||
(If you use `virtualenvwrapper`, you can also use `workon httpie` to
|
||||
activate the environment — we have created a symlink for you. It’s a bit of
|
||||
a hack but it works™.)
|
||||
|
||||
You should now see `(httpie)` next to your shell prompt, and
|
||||
the `http` command should point to your development copy:
|
||||
|
||||
```
|
||||
(httpie) ~/Code/httpie $ which http
|
||||
/Users/<user>/Code/httpie/venv/bin/http
|
||||
(httpie) ~/Code/httpie $ http --version
|
||||
2.0.0-dev
|
||||
```
|
||||
|
||||
(Btw, you don’t need to activate the virtual environment if you just want
|
||||
run some of the `make` tasks. You can also invoke the development
|
||||
version of HTTPie directly with `./venv/bin/http` without having to activate
|
||||
the environment first. The same goes for `./venv/bin/pytest`, etc.).
|
||||
|
||||
### Making Changes
|
||||
|
||||
Please make sure your changes conform to [Style Guide for Python Code](https://python.org/dev/peps/pep-0008/) (PEP8)
|
||||
and that `make pycodestyle` passes.
|
||||
|
||||
### Testing & CI
|
||||
|
||||
Please add tests for any new features and bug fixes.
|
||||
|
||||
When you open a Pull Request, [GitHub Actions](https://github.com/httpie/httpie/actions) will automatically run HTTPie’s [test suite](https://github.com/httpie/httpie/tree/master/tests) against your code, so please make sure all checks pass.
|
||||
|
||||
#### Running tests locally
|
||||
|
||||
HTTPie uses the [pytest](https://pytest.org/) runner.
|
||||
|
||||
```bash
|
||||
# Run tests on the current Python interpreter with coverage.
|
||||
$ make test
|
||||
|
||||
# Run tests with coverage
|
||||
$ make test-cover
|
||||
|
||||
# Test PEP8 compliance
|
||||
$ make codestyle
|
||||
|
||||
# Run extended tests — for code as well as .md files syntax, packaging, etc.
|
||||
$ make test-all
|
||||
```
|
||||
|
||||
#### Running specific tests
|
||||
|
||||
After you have activated your virtual environment (see [setup](#setup)), you
|
||||
can run specific tests from the terminal:
|
||||
|
||||
```bash
|
||||
# Run specific tests on the current Python
|
||||
$ python -m pytest tests/test_uploads.py
|
||||
$ python -m pytest tests/test_uploads.py::TestMultipartFormDataFileUpload
|
||||
$ python -m pytest tests/test_uploads.py::TestMultipartFormDataFileUpload::test_upload_ok
|
||||
```
|
||||
|
||||
See [Makefile](https://github.com/httpie/httpie/blob/master/Makefile) for additional development utilities.
|
||||
|
||||
#### Windows
|
||||
|
||||
If you are on a Windows machine and not able to run `make`,
|
||||
follow the next steps for a basic setup. As a prerequisite, you need to have
|
||||
Python 3.6+ installed.
|
||||
|
||||
Create a virtual environment and activate it:
|
||||
|
||||
```powershell
|
||||
C:\> python -m venv --prompt httpie venv
|
||||
C:\> venv\Scripts\activate
|
||||
```
|
||||
|
||||
Install HTTPie in editable mode with all the dependencies:
|
||||
|
||||
```powershell
|
||||
C:\> python -m pip install --upgrade -e . -r requirements-dev.txt
|
||||
```
|
||||
|
||||
You should now see `(httpie)` next to your shell prompt, and
|
||||
the `http` command should point to your development copy:
|
||||
|
||||
```powershell
|
||||
# In PowerShell:
|
||||
(httpie) PS C:\Users\ovezovs\httpie> Get-Command http
|
||||
CommandType Name Version Source
|
||||
----------- ---- ------- ------
|
||||
Application http.exe 0.0.0.0 C:\Users\ovezovs\httpie\venv\Scripts\http.exe
|
||||
```
|
||||
|
||||
```bash
|
||||
# In CMD:
|
||||
(httpie) C:\Users\ovezovs\httpie> where http
|
||||
C:\Users\ovezovs\httpie\venv\Scripts\http.exe
|
||||
C:\Users\ovezovs\AppData\Local\Programs\Python\Python38-32\Scripts\http.exe
|
||||
|
||||
(httpie) C:\Users\ovezovs\httpie> http --version
|
||||
2.3.0-dev
|
||||
```
|
||||
|
||||
Use `pytest` to run tests locally with an active virtual environment:
|
||||
|
||||
```bash
|
||||
# Run all tests
|
||||
$ python -m pytest
|
||||
```
|
||||
|
||||
______________________________________________________________________
|
||||
|
||||
Finally, feel free to add yourself to [AUTHORS](https://github.com/httpie/httpie/blob/master/AUTHORS.md)!
|
239
CONTRIBUTING.rst
239
CONTRIBUTING.rst
@ -1,239 +0,0 @@
|
||||
######################
|
||||
Contributing to HTTPie
|
||||
######################
|
||||
|
||||
Bug reports and code and documentation patches are welcome. You can
|
||||
help this project also by using the development version of HTTPie
|
||||
and by reporting any bugs you might encounter.
|
||||
|
||||
1. Reporting bugs
|
||||
=================
|
||||
|
||||
**It's important that you provide the full command argument list
|
||||
as well as the output of the failing command.**
|
||||
Use the ``--debug`` flag and copy&paste both the command and its output
|
||||
to your bug report, e.g.:
|
||||
|
||||
.. code-block:: bash
|
||||
|
||||
$ http --debug <COMPLETE ARGUMENT LIST THAT TRIGGERS THE ERROR>
|
||||
|
||||
<COMPLETE OUTPUT>
|
||||
|
||||
|
||||
2. Contributing Code and Docs
|
||||
=============================
|
||||
|
||||
Before working on a new feature or a bug, please browse `existing issues`_
|
||||
to see whether it has previously been discussed.
|
||||
|
||||
If your change alters HTTPie’s behaviour or interface, it's a good idea to
|
||||
discuss it before you start working on it.
|
||||
|
||||
If you are fixing an issue, the first step should be to create a test case that
|
||||
reproduces the incorrect behaviour. That will also help you to build an
|
||||
understanding of the issue at hand.
|
||||
|
||||
**Pull requests introducing code changes without tests
|
||||
will generally not get merged. The same goes for PRs changing HTTPie’s
|
||||
behaviour and not providing documentation.**
|
||||
|
||||
Conversely, PRs consisting of documentation improvements or tests
|
||||
for existing-yet-previously-untested behavior will very likely be merged.
|
||||
Therefore, docs and tests improvements are a great candidate for your first
|
||||
contribution.
|
||||
|
||||
Consider also adding a ``CHANGELOG`` entry for your changes.
|
||||
|
||||
|
||||
Development Environment
|
||||
--------------------------------
|
||||
|
||||
|
||||
Getting the code
|
||||
****************
|
||||
|
||||
Go to https://github.com/httpie/httpie and fork the project repository.
|
||||
|
||||
|
||||
.. code-block:: bash
|
||||
|
||||
# Clone your fork
|
||||
git clone git@github.com:<YOU>/httpie.git
|
||||
|
||||
# Enter the project directory
|
||||
cd httpie
|
||||
|
||||
# Create a branch for your changes
|
||||
git checkout -b my_topical_branch
|
||||
|
||||
|
||||
Setup
|
||||
*****
|
||||
|
||||
The `Makefile`_ contains a bunch of tasks to get you started. Just run
|
||||
the following command, which:
|
||||
|
||||
|
||||
* Creates an isolated Python virtual environment inside ``./venv``
|
||||
(via the standard library `venv`_ tool);
|
||||
* installs all dependencies and also installs HTTPie
|
||||
(in editable mode so that the ``http`` command will point to your
|
||||
working copy).
|
||||
* and runs tests (It is the same as running ``make install test``).
|
||||
|
||||
|
||||
.. code-block:: bash
|
||||
|
||||
make
|
||||
|
||||
|
||||
|
||||
Python virtual environment
|
||||
**************************
|
||||
|
||||
Activate the Python virtual environment—created via the ``make install``
|
||||
task during `setup`_—for your active shell session using the following command:
|
||||
|
||||
.. code-block:: bash
|
||||
|
||||
source venv/bin/activate
|
||||
|
||||
(If you use ``virtualenvwrapper``, you can also use ``workon httpie`` to
|
||||
activate the environment — we have created a symlink for you. It’s a bit of
|
||||
a hack but it works™.)
|
||||
|
||||
You should now see ``(httpie)`` next to your shell prompt, and
|
||||
the ``http`` command should point to your development copy:
|
||||
|
||||
.. code-block::
|
||||
|
||||
(httpie) ~/Code/httpie $ which http
|
||||
/Users/jakub/Code/httpie/venv/bin/http
|
||||
(httpie) ~/Code/httpie $ http --version
|
||||
2.0.0-dev
|
||||
|
||||
(Btw, you don’t need to activate the virtual environment if you just want
|
||||
run some of the ``make`` tasks. You can also invoke the development
|
||||
version of HTTPie directly with ``./venv/bin/http`` without having to activate
|
||||
the environment first. The same goes for ``./venv/bin/py.test``, etc.).
|
||||
|
||||
|
||||
Making Changes
|
||||
--------------
|
||||
|
||||
Please make sure your changes conform to `Style Guide for Python Code`_ (PEP8)
|
||||
and that ``make pycodestyle`` passes.
|
||||
|
||||
|
||||
Testing & CI
|
||||
------------
|
||||
|
||||
Please add tests for any new features and bug fixes.
|
||||
|
||||
When you open a pull request,
|
||||
`GitHub Actions <https://github.com/httpie/httpie/actions>`_
|
||||
will automatically run HTTPie’s `test suite`_ against your code
|
||||
so please make sure all checks pass.
|
||||
|
||||
|
||||
Running tests locally
|
||||
*********************
|
||||
|
||||
HTTPie uses the `pytest`_ runner.
|
||||
|
||||
|
||||
.. code-block:: bash
|
||||
|
||||
# Run tests on the current Python interpreter with coverage.
|
||||
make test
|
||||
|
||||
# Run tests with coverage
|
||||
make test-cover
|
||||
|
||||
# Test PEP8 compliance
|
||||
make pycodestyle
|
||||
|
||||
# Run extended tests — for code as well as .rst files syntax, packaging, etc.
|
||||
make test-all
|
||||
|
||||
|
||||
Running specific tests
|
||||
**********************
|
||||
|
||||
After you have activated your virtual environment (see `setup`_), you
|
||||
can run specific tests from the terminal:
|
||||
|
||||
.. code-block:: bash
|
||||
|
||||
# Run specific tests on the current Python
|
||||
py.test tests/test_uploads.py
|
||||
py.test tests/test_uploads.py::TestMultipartFormDataFileUpload
|
||||
py.test tests/test_uploads.py::TestMultipartFormDataFileUpload::test_upload_ok
|
||||
|
||||
-----
|
||||
|
||||
See `Makefile`_ for additional development utilities.
|
||||
|
||||
Windows
|
||||
*******
|
||||
|
||||
If you are on a Windows machine and not able to run ``make``,
|
||||
follow the next steps for a basic setup. As a prerequisite, you need to have
|
||||
Python 3.6+ installed.
|
||||
|
||||
Create a virtual environment and activate it:
|
||||
|
||||
.. code-block:: powershell
|
||||
|
||||
python -m venv --prompt httpie venv
|
||||
venv\Scripts\activate
|
||||
|
||||
Install HTTPie in editable mode with all the dependencies:
|
||||
|
||||
.. code-block:: powershell
|
||||
|
||||
pip install --upgrade -e . -r requirements-dev.txt
|
||||
|
||||
You should now see ``(httpie)`` next to your shell prompt, and
|
||||
the ``http`` command should point to your development copy:
|
||||
|
||||
.. code-block:: powershell
|
||||
|
||||
# In PowerShell:
|
||||
(httpie) PS C:\Users\ovezovs\httpie> Get-Command http
|
||||
CommandType Name Version Source
|
||||
----------- ---- ------- ------
|
||||
Application http.exe 0.0.0.0 C:\Users\ovezovs\httpie\venv\Scripts\http.exe
|
||||
|
||||
.. code-block:: bash
|
||||
|
||||
# In CMD:
|
||||
(httpie) C:\Users\ovezovs\httpie> where http
|
||||
C:\Users\ovezovs\httpie\venv\Scripts\http.exe
|
||||
C:\Users\ovezovs\AppData\Local\Programs\Python\Python38-32\Scripts\http.exe
|
||||
|
||||
(httpie) C:\Users\ovezovs\httpie> http --version
|
||||
2.3.0-dev
|
||||
|
||||
Use ``pytest`` to run tests locally with an active virtual environment:
|
||||
|
||||
.. code-block:: bash
|
||||
|
||||
# Run all tests
|
||||
py.test
|
||||
|
||||
|
||||
-----
|
||||
|
||||
|
||||
Finally, feel free to add yourself to `AUTHORS`_!
|
||||
|
||||
|
||||
.. _existing issues: https://github.com/httpie/httpie/issues?state=open
|
||||
.. _AUTHORS: https://github.com/httpie/httpie/blob/master/AUTHORS.rst
|
||||
.. _Makefile: https://github.com/httpie/httpie/blob/master/Makefile
|
||||
.. _venv: https://docs.python.org/3/library/venv.html
|
||||
.. _pytest: https://pytest.org/
|
||||
.. _Style Guide for Python Code: https://python.org/dev/peps/pep-0008/
|
||||
.. _test suite: https://github.com/httpie/httpie/tree/master/tests
|
2
LICENSE
2
LICENSE
@ -1,4 +1,4 @@
|
||||
Copyright © 2012-2020 Jakub Roztocil <jakub@roztocil.co>
|
||||
Copyright © 2012-2021 Jakub Roztocil <jakub@roztocil.co>
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
|
@ -1,7 +1,8 @@
|
||||
include LICENSE
|
||||
include README.rst
|
||||
include CHANGELOG.rst
|
||||
include AUTHORS.rst
|
||||
include README.md
|
||||
include CHANGELOG.md
|
||||
include AUTHORS.md
|
||||
include docs/README.md
|
||||
|
||||
# <https://github.com/httpie/httpie/issues/182>
|
||||
recursive-include tests/ *
|
||||
|
36
Makefile
36
Makefile
@ -1,12 +1,11 @@
|
||||
###############################################################################
|
||||
# See ./CONTRIBUTING.rst
|
||||
# See ./CONTRIBUTING.md
|
||||
###############################################################################
|
||||
|
||||
.PHONY: build
|
||||
|
||||
ROOT_DIR:=$(shell dirname $(realpath $(firstword $(MAKEFILE_LIST))))
|
||||
VERSION=$(shell grep __version__ httpie/__init__.py)
|
||||
REQUIREMENTS=requirements-dev.txt
|
||||
H1="\n\n\033[0;32m\#\#\# "
|
||||
H1END=" \#\#\# \033[0m\n"
|
||||
|
||||
@ -28,7 +27,7 @@ all: uninstall-httpie install test
|
||||
|
||||
install: venv
|
||||
@echo $(H1)Installing dev requirements$(H1END)
|
||||
$(VENV_PIP) install --upgrade -r $(REQUIREMENTS)
|
||||
$(VENV_PIP) install --upgrade --editable '.[dev]'
|
||||
|
||||
@echo $(H1)Installing HTTPie$(H1END)
|
||||
$(VENV_PIP) install --upgrade --editable .
|
||||
@ -78,7 +77,7 @@ venv:
|
||||
|
||||
test:
|
||||
@echo $(H1)Running tests$(HEADER_EXTRA)$(H1END)
|
||||
$(VENV_BIN)/py.test $(COV) ./httpie $(COV) ./tests --doctest-modules --verbose ./httpie ./tests
|
||||
$(VENV_BIN)/python -m pytest $(COV) ./httpie $(COV) ./tests --doctest-modules --verbose ./httpie ./tests
|
||||
@echo
|
||||
|
||||
|
||||
@ -88,7 +87,7 @@ test-cover: test
|
||||
|
||||
|
||||
# test-all is meant to test everything — even this Makefile
|
||||
test-all: clean install test test-dist pycodestyle
|
||||
test-all: clean install test test-dist codestyle
|
||||
@echo
|
||||
|
||||
|
||||
@ -116,10 +115,15 @@ test-bdist-wheel: clean venv
|
||||
twine-check:
|
||||
twine check dist/*
|
||||
|
||||
pycodestyle:
|
||||
@echo $(H1)Running pycodestyle$(H1END)
|
||||
@[ -f $(VENV_BIN)/pycodestyle ] || $(VENV_PIP) install pycodestyle
|
||||
$(VENV_BIN)/pycodestyle httpie/ tests/ extras/ *.py
|
||||
|
||||
# Kept for convenience, "make codestyle" is preferred though
|
||||
pycodestyle: codestyle
|
||||
|
||||
|
||||
codestyle:
|
||||
@echo $(H1)Running flake8$(H1END)
|
||||
@[ -f $(VENV_BIN)/flake8 ] || $(VENV_PIP) install --upgrade --editable '.[dev]'
|
||||
$(VENV_BIN)/flake8 httpie/ tests/ extras/ *.py
|
||||
@echo
|
||||
|
||||
|
||||
@ -170,20 +174,6 @@ uninstall-httpie:
|
||||
@echo
|
||||
|
||||
|
||||
###############################################################################
|
||||
# Docs
|
||||
###############################################################################
|
||||
|
||||
pdf:
|
||||
@echo "Converting README.rst to PDF…"
|
||||
rst2pdf \
|
||||
--strip-elements-with-class=no-pdf \
|
||||
README.rst \
|
||||
-o README.pdf
|
||||
@echo "Done"
|
||||
@echo
|
||||
|
||||
|
||||
###############################################################################
|
||||
# Homebrew
|
||||
###############################################################################
|
||||
|
84
README.md
Normal file
84
README.md
Normal file
@ -0,0 +1,84 @@
|
||||
<br/>
|
||||
<a href="https://httpie.io" target="blank_">
|
||||
<img height="100" alt="HTTPie" src="https://raw.githubusercontent.com/httpie/httpie/master/docs/httpie-logo.svg" />
|
||||
</a>
|
||||
<br/>
|
||||
|
||||
# HTTPie: human-friendly CLI HTTP client for the API era
|
||||
|
||||
HTTPie (pronounced _aitch-tee-tee-pie_) is a command-line HTTP client.
|
||||
Its goal is to make CLI interaction with web services as human-friendly as possible.
|
||||
HTTPie is designed for testing, debugging, and generally interacting with APIs & HTTP servers.
|
||||
The `http` & `https` commands allow for creating and sending arbitrary HTTP requests.
|
||||
They use simple and natural syntax and provide formatted and colorized output.
|
||||
|
||||
[](https://httpie.org/docs)
|
||||
[](https://pypi.python.org/pypi/httpie)
|
||||
[](https://github.com/httpie/httpie/actions)
|
||||
[](https://codecov.io/gh/httpie/httpie)
|
||||
[](https://twitter.com/httpie)
|
||||
[](https://httpie.io/chat)
|
||||
|
||||
<img src="https://raw.githubusercontent.com/httpie/httpie/master/docs/httpie-animation.gif" alt="HTTPie in action" width="100%"/>
|
||||
|
||||
## Getting started
|
||||
|
||||
- [Installation instructions →](https://httpie.io/docs#installation)
|
||||
- [Full documentation →](https://httpie.io/docs)
|
||||
|
||||
## Features
|
||||
|
||||
- Expressive and intuitive syntax
|
||||
- Formatted and colorized terminal output
|
||||
- Built-in JSON support
|
||||
- Forms and file uploads
|
||||
- HTTPS, proxies, and authentication
|
||||
- Arbitrary request data
|
||||
- Custom headers
|
||||
- Persistent sessions
|
||||
- `wget`-like downloads
|
||||
|
||||
[See for all features →](https://httpie.io/docs)
|
||||
|
||||
## Examples
|
||||
|
||||
Hello World:
|
||||
|
||||
```
|
||||
$ https httpie.io/hello
|
||||
```
|
||||
|
||||
Custom [HTTP method](https://httpie.io/docs#http-method), [HTTP headers](https://httpie.io/docs#http-headers) and [JSON](https://httpie.io/docs#json) data:
|
||||
|
||||
```
|
||||
$ http PUT pie.dev/put X-API-Token:123 name=John
|
||||
```
|
||||
|
||||
Build and print a request without sending it using [offline mode](https://httpie.io/docs#offline-mode):
|
||||
|
||||
```
|
||||
$ http --offline pie.dev/post hello=offline
|
||||
```
|
||||
|
||||
Use [GitHub API](https://developer.github.com/v3/issues/comments/#create-a-comment) to post a comment on an [Issue](https://github.com/httpie/httpie/issues/83) with [authentication](https://httpie.io/docs#authentication):
|
||||
|
||||
```
|
||||
$ http -a USERNAME POST https://api.github.com/repos/httpie/httpie/issues/83/comments body='HTTPie is awesome! :heart:'
|
||||
```
|
||||
|
||||
[See more examples →](https://httpie.io/docs#examples)
|
||||
|
||||
## Community & support
|
||||
|
||||
- Visit the [HTTPie website](https://httpie.io) for full documentation and useful links.
|
||||
- Join our [Discord server](https://httpie.io/chat) is to ask questions, discuss features, and for general API chat.
|
||||
- Tweet at [@httpie](https://twitter.com/httpie) on Twitter.
|
||||
- Use [StackOverflow](https://stackoverflow.com/questions/tagged/httpie) to ask questions and include a `httpie` tag.
|
||||
- Create [GitHub Issues](https://github.com/httpie/httpie/issues) for bug reports and feature requests.
|
||||
- Subscribe to the [HTTPie newsletter](https://httpie.io) for occasional updates.
|
||||
|
||||
## Contributing
|
||||
|
||||
Have a look through existing [Issues](https://github.com/httpie/httpie/issues) and [Pull Requests](https://github.com/httpie/httpie/pulls) that you could help with. If you'd like to request a feature or report a bug, please [create a GitHub Issue](https://github.com/httpie/httpie/issues) using one of the templates provided.
|
||||
|
||||
[See contribution guide →](https://github.com/httpie/httpie/blob/master/CONTRIBUTING.md)
|
2211
README.rst
2211
README.rst
File diff suppressed because it is too large
Load Diff
1683
docs/README.md
Normal file
1683
docs/README.md
Normal file
File diff suppressed because it is too large
Load Diff
Before Width: | Height: | Size: 1019 KiB After Width: | Height: | Size: 1019 KiB |
1
docs/httpie-logo.svg
Normal file
1
docs/httpie-logo.svg
Normal file
@ -0,0 +1 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 1635.31 470"><defs><style>.cls-1{fill:#4b78e6;}</style></defs><g id="Layer_2" data-name="Layer 2"><g id="Layer_1-2" data-name="Layer 1"><path class="cls-1" d="M1322.19,73.91h0a36.56,36.56,0,0,1,36.56-36.29h3.41a36.56,36.56,0,0,1,36.56,36.83h0a36.56,36.56,0,0,1-36.56,36.29h-3.41A36.56,36.56,0,0,1,1322.19,73.91Zm6.16,276.93V142.35a7.94,7.94,0,0,1,8-7.94h48.32a7.93,7.93,0,0,1,7.94,7.94V350.84a7.94,7.94,0,0,1-7.94,7.94H1336.3A8,8,0,0,1,1328.35,350.84Z"/><path class="cls-1" d="M1635.31,233.34c0-61.06-33.28-105.09-101.71-105.09-72.17,0-114.82,45.45-114.82,123.08,0,74.79,46.86,113.6,113.89,113.6,56.83,0,85.93-27.17,98.33-63.86a8,8,0,0,0-5.34-10.28l-40.32-11.39a8,8,0,0,0-9.54,4.73c-5.77,14.37-16.57,25.42-42.2,25.42-29.32,0-46.06-13.62-50.74-44.29a7.17,7.17,0,0,0,.81.08h143.7a8,8,0,0,0,7.94-7.94V242.23c0-.09,0-.18,0-.28C1635.31,239.17,1635.31,236.36,1635.31,233.34Zm-103.58-51.6c28.59,0,43.12,15.15,45,45H1483C1487.21,195,1503.61,181.74,1531.73,181.74Z"/><path class="cls-1" d="M581.91,358.75H533.56a7.93,7.93,0,0,1-7.94-7.94V76.39a7.93,7.93,0,0,1,7.94-7.94h48.35a7.93,7.93,0,0,1,7.94,7.94v84.66a6,6,0,0,0,11.22,2.77c13.45-25.56,34.68-35.33,60.42-35.69,38.66-.55,70,31.45,70,70.12V350.81a7.94,7.94,0,0,1-7.94,7.94H675.63a7.94,7.94,0,0,1-7.94-7.94V227.1c0-23.21-10.32-40.73-37-40.73-25.79,0-40.8,15.15-40.8,40.73V350.81A7.93,7.93,0,0,1,581.91,358.75Z"/><path class="cls-1" d="M1052.84,306.12a7.94,7.94,0,0,0-9.77-6.78c-6.47,1.55-13.73,3.05-20.35,3.05-19.23,0-25.79-8.52-25.79-26.52V188.26h50.67a7.94,7.94,0,0,0,7.94-7.94v-38.1a8,8,0,0,0-7.94-7.95H996.93V85.86A7.94,7.94,0,0,0,989,77.92H941.1a7.93,7.93,0,0,0-7.94,7.94v48.41H842.67V85.86a7.94,7.94,0,0,0-7.94-7.94H786.84a7.93,7.93,0,0,0-7.94,7.94v48.41H761.05a7.94,7.94,0,0,0-7.94,7.95v38.1a7.93,7.93,0,0,0,7.94,7.94H778.9v99.93c0,42.62,21.57,77.19,73.15,77.19,21.16,0,32.43-2.5,46.08-6.56a8,8,0,0,0,5.65-8.56l-5.2-44.14a7.94,7.94,0,0,0-9.77-6.78c-6.47,1.55-13.73,3.05-20.35,3.05-19.23,0-25.79-8.52-25.79-26.52V188.26h90.49v99.93c0,42.62,21.57,77.19,73.14,77.19,21.17,0,32.44-2.5,46.09-6.56a8,8,0,0,0,5.65-8.56Z"/><path class="cls-1" d="M1219.14,365.27c-28.49,0-49.51-10.92-62.87-35.86a6,6,0,0,0-11.19,2.84v82.83a7.93,7.93,0,0,1-7.94,7.94h-48.32a7.94,7.94,0,0,1-8-7.94V142.21a8,8,0,0,1,8-7.94h48.32a7.94,7.94,0,0,1,7.94,7.94v18.95c0,6.13,8.21,8.3,11.15,2.92,13.74-25.16,35.63-36,64.31-36,53.43,0,81.08,44,81.08,116.92C1301.62,320.78,1273,365.27,1219.14,365.27Zm19.21-119.76c0-37.39-14.06-59.17-46.4-59.17-29.53,0-46.87,20.35-46.87,57.28v4.26c0,36.45,17.34,59.17,46.87,59.17C1223.82,307.05,1238.35,284.33,1238.35,245.51Z"/><path class="cls-1" d="M394.41,102.12C394,45.31,346.61,0,289.8,0H104.69C48.31,0,1.09,44.6,0,101A103.07,103.07,0,0,0,103,205.92h82.7a6,6,0,0,1,2.39,11.42L61.31,272.91A103.09,103.09,0,0,0,0,367.83C.43,424.65,47.79,470,104.62,470H148c57.23,0,104.88-45.9,104.79-103.13a103.1,103.1,0,0,0-64.49-95.31,5.94,5.94,0,0,1-.1-10.94l145-63.58A103.08,103.08,0,0,0,394.41,102.12Z"/></g></g></svg>
|
After Width: | Height: | Size: 2.9 KiB |
@ -12,6 +12,13 @@ import hashlib
|
||||
import requests
|
||||
|
||||
|
||||
VERSIONS = {
|
||||
# By default, we use the latest packages. But sometimes Requests has a maximum supported versions.
|
||||
# Take a look here before making a release: <https://github.com/psf/requests/blob/master/setup.py>
|
||||
'idna': '2.10',
|
||||
}
|
||||
|
||||
|
||||
PACKAGES = [
|
||||
'httpie',
|
||||
'Pygments',
|
||||
@ -22,14 +29,22 @@ PACKAGES = [
|
||||
'idna',
|
||||
'chardet',
|
||||
'PySocks',
|
||||
'defusedxml',
|
||||
]
|
||||
|
||||
|
||||
def get_package_meta(package_name):
|
||||
api_url = f'https://pypi.python.org/pypi/{package_name}/json'
|
||||
api_url = f'https://pypi.org/pypi/{package_name}/json'
|
||||
resp = requests.get(api_url).json()
|
||||
hasher = hashlib.sha256()
|
||||
for release in resp['urls']:
|
||||
version = VERSIONS.get(package_name)
|
||||
if package_name not in VERSIONS:
|
||||
# Latest version
|
||||
release_bundle = resp['urls']
|
||||
else:
|
||||
release_bundle = resp['releases'][version]
|
||||
|
||||
for release in release_bundle:
|
||||
download_url = release['url']
|
||||
if download_url.endswith('.tar.gz'):
|
||||
hasher.update(requests.get(download_url).content)
|
||||
|
@ -1,11 +1,8 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
|
||||
_http_complete() {
|
||||
local cur_word=${COMP_WORDS[COMP_CWORD]}
|
||||
local prev_word=${COMP_WORDS[COMP_CWORD - 1]}
|
||||
|
||||
if [[ "$cur_word" == -* ]]; then
|
||||
if [[ "$cur_word" == -* ]]; then
|
||||
_http_complete_options "$cur_word"
|
||||
fi
|
||||
}
|
||||
@ -18,6 +15,6 @@ _http_complete_options() {
|
||||
-v --verbose -h --headers -b --body -S --stream -o --output -d --download
|
||||
-c --continue --session --session-read-only -a --auth --auth-type --proxy
|
||||
--follow --verify --cert --cert-key --timeout --check-status --ignore-stdin
|
||||
--help --version --traceback --debug"
|
||||
--help --version --traceback --debug --raw"
|
||||
COMPREPLY=( $( compgen -W "$options" -- "$cur_word" ) )
|
||||
}
|
||||
|
@ -1,59 +1,137 @@
|
||||
function __fish_httpie_auth_types
|
||||
echo "basic"\t"Basic HTTP auth"
|
||||
echo "digest"\t"Digest HTTP auth"
|
||||
end
|
||||
|
||||
function __fish_httpie_styles
|
||||
echo "autumn"
|
||||
echo "borland"
|
||||
echo "bw"
|
||||
echo "colorful"
|
||||
echo "default"
|
||||
echo "emacs"
|
||||
echo "friendly"
|
||||
echo "fruity"
|
||||
echo "igor"
|
||||
echo "manni"
|
||||
echo "monokai"
|
||||
echo "murphy"
|
||||
echo "native"
|
||||
echo "paraiso-dark"
|
||||
echo "paraiso-light"
|
||||
echo "pastie"
|
||||
echo "perldoc"
|
||||
echo "rrt"
|
||||
echo "solarized"
|
||||
echo "tango"
|
||||
echo "trac"
|
||||
echo "vim"
|
||||
echo "vs"
|
||||
echo "xcode"
|
||||
echo "
|
||||
abap
|
||||
algol
|
||||
algol_nu
|
||||
arduino
|
||||
auto
|
||||
autumn
|
||||
borland
|
||||
bw
|
||||
colorful
|
||||
default
|
||||
emacs
|
||||
friendly
|
||||
fruity
|
||||
gruvbox-dark
|
||||
gruvbox-light
|
||||
igor
|
||||
inkpot
|
||||
lovelace
|
||||
manni
|
||||
material
|
||||
monokai
|
||||
murphy
|
||||
native
|
||||
paraiso-dark
|
||||
paraiso-light
|
||||
pastie
|
||||
perldoc
|
||||
rainbow_dash
|
||||
rrt
|
||||
sas
|
||||
solarized
|
||||
solarized-dark
|
||||
solarized-light
|
||||
stata
|
||||
stata-dark
|
||||
stata-light
|
||||
tango
|
||||
trac
|
||||
vim
|
||||
vs
|
||||
xcode
|
||||
zenburn"
|
||||
end
|
||||
|
||||
complete -x -c http -s s -l style -d 'Output coloring style (default is "monokai")' -A -a '(__fish_httpie_styles)'
|
||||
complete -c http -s f -l form -d 'Data items from the command line are serialized as form fields'
|
||||
complete -c http -s j -l json -d '(default) Data items from the command line are serialized as a JSON object'
|
||||
complete -x -c http -l pretty -d 'Controls output processing' -a "all colors format none" -A
|
||||
complete -x -c http -s p -l print -d 'String specifying what the output should contain'
|
||||
complete -c http -s v -l verbose -d 'Print the whole request as well as the response'
|
||||
complete -c http -s h -l headers -d 'Print only the response headers'
|
||||
complete -c http -s b -l body -d 'Print only the response body'
|
||||
complete -c http -s S -l stream -d 'Always stream the output by line'
|
||||
complete -c http -s o -l output -d 'Save output to FILE'
|
||||
complete -c http -s d -l download -d 'Do not print the response body to stdout'
|
||||
complete -c http -s c -l continue -d 'Resume an interrupted download'
|
||||
complete -x -c http -l session -d 'Create, or reuse and update a session'
|
||||
complete -x -c http -s a -l auth -d 'If only the username is provided (-a username), HTTPie will prompt for the password'
|
||||
complete -x -c http -l auth-type -d 'The authentication mechanism to be used' -a '(__fish_httpie_auth_types)' -A
|
||||
complete -x -c http -l proxy -d 'String mapping protocol to the URL of the proxy'
|
||||
complete -c http -l follow -d 'Allow full redirects'
|
||||
complete -x -c http -l verify -d 'SSL cert verification'
|
||||
complete -c http -l cert -d 'SSL cert'
|
||||
complete -c http -l cert-key -d 'Private SSL cert key'
|
||||
complete -x -c http -l timeout -d 'Connection timeout in seconds'
|
||||
complete -c http -l check-status -d 'Error with non-200 HTTP status code'
|
||||
complete -c http -l ignore-stdin -d 'Do not attempt to read stdin'
|
||||
complete -c http -l help -d 'Show help'
|
||||
complete -c http -l version -d 'Show version'
|
||||
complete -c http -l traceback -d 'Prints exception traceback should one occur'
|
||||
complete -c http -l debug -d 'Show debugging information'
|
||||
function __fish_httpie_auth_types
|
||||
echo -e "basic\tBasic HTTP auth"
|
||||
echo -e "digest\tDigest HTTP auth"
|
||||
end
|
||||
|
||||
function __fish_http_verify_options
|
||||
echo -e "yes\tEnable cert verification"
|
||||
echo -e "no\tDisable cert verification"
|
||||
end
|
||||
|
||||
# Predefined Content Types
|
||||
|
||||
complete -c http -s j -l json -d 'Data items are serialized as a JSON object'
|
||||
complete -c http -s f -l form -d 'Data items are serialized as form fields'
|
||||
complete -c http -l multipart -d 'Always sends a multipart/form-data request'
|
||||
complete -c http -l boundary -x -d 'Custom boundary string for multipart/form-data requests'
|
||||
complete -c http -l raw -x -d 'Pass raw request data without extra processing'
|
||||
|
||||
|
||||
# Content Processing Options
|
||||
|
||||
complete -c http -s x -l compress -d 'Content compressed with Deflate algorithm'
|
||||
|
||||
|
||||
# Output Processing
|
||||
|
||||
complete -c http -l pretty -xa "all colors format none" -d 'Controls output processing'
|
||||
complete -c http -s s -l style -xa "(__fish_httpie_styles)" -d 'Output coloring style'
|
||||
complete -c http -l unsorted -d 'Disables all sorting while formatting output'
|
||||
complete -c http -l sorted -d 'Re-enables all sorting options while formatting output'
|
||||
complete -c http -l format-options -x -d 'Controls output formatting'
|
||||
|
||||
|
||||
# Output Options
|
||||
|
||||
complete -c http -s p -l print -x -d 'String specifying what the output should contain'
|
||||
complete -c http -s h -l headers -d 'Print only the response headers'
|
||||
complete -c http -s b -l body -d 'Print only the response body'
|
||||
complete -c http -s v -l verbose -d 'Print the whole request as well as the response'
|
||||
complete -c http -l all -d 'Show any intermediary requests/responses'
|
||||
complete -c http -s P -l history-print -x -d 'The same as --print but applies only to intermediary requests/responses'
|
||||
complete -c http -s S -l stream -d 'Always stream the response body by line'
|
||||
complete -c http -s o -l output -F -d 'Save output to FILE'
|
||||
complete -c http -s d -l download -d 'Download a file'
|
||||
complete -c http -s c -l continue -d 'Resume an interrupted download'
|
||||
complete -c http -s q -l quiet -d 'Do not print to stdout or stderr'
|
||||
|
||||
|
||||
# Sessions
|
||||
|
||||
complete -c http -l session -F -d 'Create, or reuse and update a session'
|
||||
complete -c http -l session-read-only -F -d 'Create or read a session without updating it'
|
||||
|
||||
|
||||
# Authentication
|
||||
|
||||
complete -c http -s a -l auth -x -d 'Username and password for authentication'
|
||||
complete -c http -s A -l auth-type -xa "(__fish_httpie_auth_types)" -d 'The authentication mechanism to be used'
|
||||
complete -c http -l ignore-netrc -d 'Ignore credentials from .netrc'
|
||||
|
||||
|
||||
# Network
|
||||
|
||||
complete -c http -l offline -d 'Build the request and print it but don\'t actually send it'
|
||||
complete -c http -l proxy -x -d 'String mapping protocol to the URL of the proxy'
|
||||
complete -c http -s F -l follow -d 'Follow 30x Location redirects'
|
||||
complete -c http -l max-redirects -x -d 'Set maximum number of redirects'
|
||||
complete -c http -l max-headers -x -d 'Maximum number of response headers to be read before giving up'
|
||||
complete -c http -l timeout -x -d 'Connection timeout in seconds'
|
||||
complete -c http -l check-status -d 'Error with non-200 HTTP status code'
|
||||
complete -c http -l path-as-is -d 'Bypass dot segment URL squashing'
|
||||
complete -c http -l chunked -d ''
|
||||
|
||||
|
||||
# SSL
|
||||
|
||||
complete -c http -l verify -xa "(__fish_http_verify_options)" -d 'Enable/disable cert verification'
|
||||
complete -c http -l ssl -x -d 'Desired protocol version to use'
|
||||
complete -c http -l ciphers -x -d 'String in the OpenSSL cipher list format'
|
||||
complete -c http -l cert -F -d 'Client side SSL certificate'
|
||||
complete -c http -l cert-key -F -d 'Private key to use with SSL'
|
||||
|
||||
|
||||
# Troubleshooting
|
||||
|
||||
complete -c http -s I -l ignore-stdin -d 'Do not attempt to read stdin'
|
||||
complete -c http -l help -d 'Show help'
|
||||
complete -c http -l version -d 'Show version'
|
||||
complete -c http -l traceback -d 'Prints exception traceback should one occur'
|
||||
complete -c http -l default-scheme -x -d 'The default scheme to use'
|
||||
complete -c http -l debug -d 'Show debugging output'
|
||||
|
@ -8,26 +8,31 @@ class Httpie < Formula
|
||||
include Language::Python::Virtualenv
|
||||
|
||||
desc "User-friendly cURL replacement (command-line HTTP client)"
|
||||
homepage "https://httpie.org/"
|
||||
url "https://files.pythonhosted.org/packages/b4/d4/712645808103f2d15c281b9eacd184c88754ef7e9a322d9a30ba343fd341/httpie-2.3.0.tar.gz"
|
||||
sha256 "d540571991d07329d217c31bf1ff95fd217957da2aa2def09bcfa0c0fca0cf96"
|
||||
homepage "https://httpie.io/"
|
||||
url "https://files.pythonhosted.org/packages/17/3a/90fb6702e600f5ba7d38d147bbc0b0a1e47159e3e244737319c98c140420/httpie-2.4.0.tar.gz"
|
||||
sha256 "4d1bf5779cf6c9007351cfcaa20bd19947267dc026af09246db6006a8927d8c6"
|
||||
license "BSD-3-Clause"
|
||||
head "https://github.com/httpie/httpie.git"
|
||||
|
||||
livecheck do
|
||||
url :stable
|
||||
bottle do
|
||||
rebuild 1
|
||||
sha256 cellar: :any_skip_relocation, arm64_big_sur: "a01ce8767f6ea88eb8e7894347ba64eb29294053a8ee91eed44dfaf0ab5e7ea2"
|
||||
sha256 cellar: :any_skip_relocation, big_sur: "bdffeff349595ed3c528ed791d568e308b0877246b49e05e867143ba3415a70f"
|
||||
sha256 cellar: :any_skip_relocation, catalina: "ba0627d70f0ee49c64677f5554881ebd56371f47d45196b6564680089ce69152"
|
||||
sha256 cellar: :any_skip_relocation, mojave: "0b87901e88bdcf53c55c5138677087b4621c5aaf1fca67b53b730d5a2fd5a40a"
|
||||
sha256 cellar: :any_skip_relocation, high_sierra: "87e7348b6fb40fd8e4f7597937952469601962189e62d321b8cb4fa421e035ef"
|
||||
end
|
||||
|
||||
depends_on "python@3.9"
|
||||
|
||||
resource "Pygments" do
|
||||
url "https://files.pythonhosted.org/packages/5d/0e/ff13c055b014d634ed17e9e9345a312c28ec6a06448ba6d6ccfa77c3b5e8/Pygments-2.7.2.tar.gz"
|
||||
sha256 "381985fcc551eb9d37c52088a32914e00517e57f4a21609f48141ba08e193fa0"
|
||||
url "https://files.pythonhosted.org/packages/e1/86/8059180e8217299079d8719c6e23d674aadaba0b1939e25e0cc15dcf075b/Pygments-2.7.4.tar.gz"
|
||||
sha256 "df49d09b498e83c1a73128295860250b0b7edd4c723a32e9bc0d295c7c2ec337"
|
||||
end
|
||||
|
||||
resource "requests" do
|
||||
url "https://files.pythonhosted.org/packages/da/67/672b422d9daf07365259958912ba533a0ecab839d4084c487a5fe9a5405f/requests-2.24.0.tar.gz"
|
||||
sha256 "b3559a131db72c33ee969480840fff4bb6dd111de7dd27c8ee1f820f4f00231b"
|
||||
url "https://files.pythonhosted.org/packages/6b/47/c14abc08432ab22dc18b9892252efaf005ab44066de871e72a38d6af464b/requests-2.25.1.tar.gz"
|
||||
sha256 "27973dd4a904a4f13b263a19c866c13b92a39ed1c964655f025f3f8d3d75b804"
|
||||
end
|
||||
|
||||
resource "requests-toolbelt" do
|
||||
@ -36,13 +41,13 @@ class Httpie < Formula
|
||||
end
|
||||
|
||||
resource "certifi" do
|
||||
url "https://files.pythonhosted.org/packages/40/a7/ded59fa294b85ca206082306bba75469a38ea1c7d44ea7e1d64f5443d67a/certifi-2020.6.20.tar.gz"
|
||||
sha256 "5930595817496dd21bb8dc35dad090f1c2cd0adfaf21204bf6732ca5d8ee34d3"
|
||||
url "https://files.pythonhosted.org/packages/06/a9/cd1fd8ee13f73a4d4f491ee219deeeae20afefa914dfb4c130cfc9dc397a/certifi-2020.12.5.tar.gz"
|
||||
sha256 "1a4995114262bffbc2413b159f2a1a480c969de6e6eb13ee966d470af86af59c"
|
||||
end
|
||||
|
||||
resource "urllib3" do
|
||||
url "https://files.pythonhosted.org/packages/76/d9/bbbafc76b18da706451fa91bc2ebe21c0daf8868ef3c30b869ac7cb7f01d/urllib3-1.25.11.tar.gz"
|
||||
sha256 "8d7eaa5a82a1cac232164990f04874c594c9453ec55eef02eab885aa02fc17a2"
|
||||
url "https://files.pythonhosted.org/packages/d7/8d/7ee68c6b48e1ec8d41198f694ecdc15f7596356f2ff8e6b1420300cf5db3/urllib3-1.26.3.tar.gz"
|
||||
sha256 "de3eedaad74a2683334e282005cd8d7f22f4d55fa690a2a1020a416cb0a47e73"
|
||||
end
|
||||
|
||||
resource "idna" do
|
||||
@ -51,8 +56,8 @@ class Httpie < Formula
|
||||
end
|
||||
|
||||
resource "chardet" do
|
||||
url "https://files.pythonhosted.org/packages/fc/bb/a5768c230f9ddb03acc9ef3f0d4a3cf93462473795d18e9535498c8f929d/chardet-3.0.4.tar.gz"
|
||||
sha256 "84ab92ed1c4d4f16916e05906b6b75a6c0fb5db821cc65e70cbd64a3e2a5eaae"
|
||||
url "https://files.pythonhosted.org/packages/ee/2d/9cdc2b527e127b4c9db64b86647d567985940ac3698eeabc7ffaccb4ea61/chardet-4.0.0.tar.gz"
|
||||
sha256 "0d6f53a15db4120f2b08c94f11e7d93d2c911ee118b6b30a04ec3ee8310179fa"
|
||||
end
|
||||
|
||||
resource "PySocks" do
|
||||
@ -65,7 +70,7 @@ class Httpie < Formula
|
||||
end
|
||||
|
||||
test do
|
||||
raw_url = "https://raw.githubusercontent.com/Homebrew/homebrew-core/master/Formula/httpie.rb"
|
||||
raw_url = "https://raw.githubusercontent.com/Homebrew/homebrew-core/HEAD/Formula/httpie.rb"
|
||||
assert_match "PYTHONPATH", shell_output("#{bin}/http --ignore-stdin #{raw_url}")
|
||||
end
|
||||
end
|
||||
|
BIN
httpie.png
BIN
httpie.png
Binary file not shown.
Before Width: | Height: | Size: 681 KiB |
@ -3,6 +3,6 @@ HTTPie: command-line HTTP client for the API era.
|
||||
|
||||
"""
|
||||
|
||||
__version__ = '2.4.0'
|
||||
__version__ = '2.5.0'
|
||||
__author__ = 'Jakub Roztocil'
|
||||
__licence__ = 'BSD'
|
||||
|
@ -1,20 +1,19 @@
|
||||
#!/usr/bin/env python
|
||||
"""The main entry point. Invoke as `http' or `python -m httpie'.
|
||||
|
||||
"""
|
||||
import sys
|
||||
|
||||
|
||||
def main():
|
||||
try:
|
||||
from .core import main
|
||||
from httpie.core import main
|
||||
exit_status = main()
|
||||
except KeyboardInterrupt:
|
||||
from httpie.status import ExitStatus
|
||||
exit_status = ExitStatus.ERROR_CTRL_C
|
||||
|
||||
sys.exit(exit_status.value)
|
||||
return exit_status.value
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
if __name__ == '__main__': # pragma: nocover
|
||||
import sys
|
||||
sys.exit(main())
|
||||
|
@ -9,23 +9,23 @@ from urllib.parse import urlsplit
|
||||
|
||||
from requests.utils import get_netrc_auth
|
||||
|
||||
from httpie.cli.argtypes import (
|
||||
from .argtypes import (
|
||||
AuthCredentials, KeyValueArgType, PARSED_DEFAULT_FORMAT_OPTIONS,
|
||||
parse_auth,
|
||||
parse_format_options,
|
||||
)
|
||||
from httpie.cli.constants import (
|
||||
from .constants import (
|
||||
HTTP_GET, HTTP_POST, OUTPUT_OPTIONS, OUTPUT_OPTIONS_DEFAULT,
|
||||
OUTPUT_OPTIONS_DEFAULT_OFFLINE, OUTPUT_OPTIONS_DEFAULT_STDOUT_REDIRECTED,
|
||||
OUT_RESP_BODY, PRETTY_MAP, PRETTY_STDOUT_TTY_ONLY, RequestType,
|
||||
SEPARATOR_CREDENTIALS,
|
||||
SEPARATOR_GROUP_ALL_ITEMS, SEPARATOR_GROUP_DATA_ITEMS, URL_SCHEME_RE,
|
||||
)
|
||||
from httpie.cli.exceptions import ParseError
|
||||
from httpie.cli.requestitems import RequestItems
|
||||
from httpie.context import Environment
|
||||
from httpie.plugins.registry import plugin_manager
|
||||
from httpie.utils import ExplicitNullAuth, get_content_type
|
||||
from .exceptions import ParseError
|
||||
from .requestitems import RequestItems
|
||||
from ..context import Environment
|
||||
from ..plugins.registry import plugin_manager
|
||||
from ..utils import ExplicitNullAuth, get_content_type
|
||||
|
||||
|
||||
class HTTPieHelpFormatter(RawDescriptionHelpFormatter):
|
||||
@ -64,6 +64,7 @@ class HTTPieArgumentParser(argparse.ArgumentParser):
|
||||
self.env = None
|
||||
self.args = None
|
||||
self.has_stdin_data = False
|
||||
self.has_input_data = False
|
||||
|
||||
# noinspection PyMethodOverriding
|
||||
def parse_args(
|
||||
@ -81,6 +82,7 @@ class HTTPieArgumentParser(argparse.ArgumentParser):
|
||||
and not self.args.ignore_stdin
|
||||
and not self.env.stdin_isatty
|
||||
)
|
||||
self.has_input_data = self.has_stdin_data or self.args.raw is not None
|
||||
# Arguments processing and environment setup.
|
||||
self._apply_no_options(no_options)
|
||||
self._process_request_type()
|
||||
@ -91,11 +93,14 @@ class HTTPieArgumentParser(argparse.ArgumentParser):
|
||||
self._process_format_options()
|
||||
self._guess_method()
|
||||
self._parse_items()
|
||||
if self.has_stdin_data:
|
||||
self._body_from_file(self.env.stdin)
|
||||
self._process_url()
|
||||
self._process_auth()
|
||||
|
||||
if self.args.raw is not None:
|
||||
self._body_from_input(self.args.raw)
|
||||
elif self.has_stdin_data:
|
||||
self._body_from_file(self.env.stdin)
|
||||
|
||||
if self.args.compress:
|
||||
# TODO: allow --compress with --chunked / --multipart
|
||||
if self.args.chunked:
|
||||
@ -171,7 +176,7 @@ class HTTPieArgumentParser(argparse.ArgumentParser):
|
||||
self.args.output_file.seek(0)
|
||||
try:
|
||||
self.args.output_file.truncate()
|
||||
except IOError as e:
|
||||
except OSError as e:
|
||||
if e.errno == errno.EINVAL:
|
||||
# E.g. /dev/null on Linux.
|
||||
pass
|
||||
@ -279,21 +284,34 @@ class HTTPieArgumentParser(argparse.ArgumentParser):
|
||||
invalid.append(option)
|
||||
|
||||
if invalid:
|
||||
msg = 'unrecognized arguments: %s'
|
||||
self.error(msg % ' '.join(invalid))
|
||||
self.error(f'unrecognized arguments: {" ".join(invalid)}')
|
||||
|
||||
def _body_from_file(self, fd):
|
||||
"""There can only be one source of request data.
|
||||
"""Read the data from a file-like object.
|
||||
|
||||
Bytes are always read.
|
||||
|
||||
"""
|
||||
if self.args.data or self.args.files:
|
||||
self.error('Request body (from stdin or a file) and request '
|
||||
self._ensure_one_data_source(self.args.data, self.args.files)
|
||||
self.args.data = getattr(fd, 'buffer', fd)
|
||||
|
||||
def _body_from_input(self, data):
|
||||
"""Read the data from the CLI.
|
||||
|
||||
"""
|
||||
self._ensure_one_data_source(self.has_stdin_data, self.args.data,
|
||||
self.args.files)
|
||||
self.args.data = data.encode()
|
||||
|
||||
def _ensure_one_data_source(self, *other_sources):
|
||||
"""There can only be one source of input request data.
|
||||
|
||||
"""
|
||||
if any(other_sources):
|
||||
self.error('Request body (from stdin, --raw or a file) and request '
|
||||
'data (key=value) cannot be mixed. Pass '
|
||||
'--ignore-stdin to let key/value take priority. '
|
||||
'See https://httpie.org/doc#scripting for details.')
|
||||
self.args.data = getattr(fd, 'buffer', fd)
|
||||
|
||||
def _guess_method(self):
|
||||
"""Set `args.method` if not specified to either POST or GET
|
||||
@ -303,7 +321,7 @@ class HTTPieArgumentParser(argparse.ArgumentParser):
|
||||
if self.args.method is None:
|
||||
# Invoked as `http URL'.
|
||||
assert not self.args.request_items
|
||||
if self.has_stdin_data:
|
||||
if self.has_input_data:
|
||||
self.args.method = HTTP_POST
|
||||
else:
|
||||
self.args.method = HTTP_GET
|
||||
@ -327,7 +345,7 @@ class HTTPieArgumentParser(argparse.ArgumentParser):
|
||||
self.args.url = self.args.method
|
||||
# Infer the method
|
||||
has_data = (
|
||||
self.has_stdin_data
|
||||
self.has_input_data
|
||||
or any(
|
||||
item.sep in SEPARATOR_GROUP_DATA_ITEMS
|
||||
for item in self.args.request_items)
|
||||
@ -358,13 +376,17 @@ class HTTPieArgumentParser(argparse.ArgumentParser):
|
||||
|
||||
if self.args.files and not self.args.form:
|
||||
# `http url @/path/to/file`
|
||||
file_fields = list(self.args.files.keys())
|
||||
if file_fields != ['']:
|
||||
self.error(
|
||||
'Invalid file fields (perhaps you meant --form?): %s'
|
||||
% ','.join(file_fields))
|
||||
request_file = None
|
||||
for key, file in self.args.files.items():
|
||||
if key != '':
|
||||
self.error(
|
||||
'Invalid file fields (perhaps you meant --form?):'
|
||||
f' {",".join(self.args.files.keys())}')
|
||||
if request_file is not None:
|
||||
self.error("Can't read request from multiple files")
|
||||
request_file = file
|
||||
|
||||
fn, fd, ct = self.args.files['']
|
||||
fn, fd, ct = request_file
|
||||
self.args.files = {}
|
||||
|
||||
self._body_from_file(fd)
|
||||
@ -384,10 +406,7 @@ class HTTPieArgumentParser(argparse.ArgumentParser):
|
||||
def check_options(value, option):
|
||||
unknown = set(value) - OUTPUT_OPTIONS
|
||||
if unknown:
|
||||
self.error('Unknown output options: {0}={1}'.format(
|
||||
option,
|
||||
','.join(unknown)
|
||||
))
|
||||
self.error(f'Unknown output options: {option}={",".join(unknown)}')
|
||||
|
||||
if self.args.verbose:
|
||||
self.args.all = True
|
||||
|
@ -5,8 +5,8 @@ import sys
|
||||
from copy import deepcopy
|
||||
from typing import List, Optional, Union
|
||||
|
||||
from httpie.cli.constants import DEFAULT_FORMAT_OPTIONS, SEPARATOR_CREDENTIALS
|
||||
from httpie.sessions import VALID_SESSION_NAME_PATTERN
|
||||
from .constants import DEFAULT_FORMAT_OPTIONS, SEPARATOR_CREDENTIALS
|
||||
from ..sessions import VALID_SESSION_NAME_PATTERN
|
||||
|
||||
|
||||
class KeyValueArg:
|
||||
@ -180,8 +180,8 @@ def readable_file_arg(filename):
|
||||
try:
|
||||
with open(filename, 'rb'):
|
||||
return filename
|
||||
except IOError as ex:
|
||||
raise argparse.ArgumentTypeError(f'{filename}: {ex.args[1]}')
|
||||
except OSError as ex:
|
||||
raise argparse.ArgumentTypeError(f'{ex.filename}: {ex.strerror}')
|
||||
|
||||
|
||||
def parse_format_options(s: str, defaults: Optional[dict]) -> dict:
|
||||
|
@ -90,6 +90,8 @@ DEFAULT_FORMAT_OPTIONS = [
|
||||
'json.format:true',
|
||||
'json.indent:4',
|
||||
'json.sort_keys:true',
|
||||
'xml.format:true',
|
||||
'xml.indent:2',
|
||||
]
|
||||
SORTED_FORMAT_OPTIONS = [
|
||||
'headers.sort:true',
|
||||
|
@ -5,13 +5,13 @@ CLI arguments definition.
|
||||
from argparse import (FileType, OPTIONAL, SUPPRESS, ZERO_OR_MORE)
|
||||
from textwrap import dedent, wrap
|
||||
|
||||
from httpie import __doc__, __version__
|
||||
from httpie.cli.argparser import HTTPieArgumentParser
|
||||
from httpie.cli.argtypes import (
|
||||
from .. import __doc__, __version__
|
||||
from .argparser import HTTPieArgumentParser
|
||||
from .argtypes import (
|
||||
KeyValueArgType, SessionNameValidator,
|
||||
readable_file_arg,
|
||||
)
|
||||
from httpie.cli.constants import (
|
||||
from .constants import (
|
||||
DEFAULT_FORMAT_OPTIONS, OUTPUT_OPTIONS,
|
||||
OUTPUT_OPTIONS_DEFAULT, OUT_REQ_BODY, OUT_REQ_HEAD,
|
||||
OUT_RESP_BODY, OUT_RESP_HEAD, PRETTY_MAP, PRETTY_STDOUT_TTY_ONLY,
|
||||
@ -19,18 +19,18 @@ from httpie.cli.constants import (
|
||||
SORTED_FORMAT_OPTIONS_STRING,
|
||||
UNSORTED_FORMAT_OPTIONS_STRING,
|
||||
)
|
||||
from httpie.output.formatters.colors import (
|
||||
from ..output.formatters.colors import (
|
||||
AUTO_STYLE, AVAILABLE_STYLES, DEFAULT_STYLE,
|
||||
)
|
||||
from httpie.plugins.builtin import BuiltinAuthPlugin
|
||||
from httpie.plugins.registry import plugin_manager
|
||||
from httpie.sessions import DEFAULT_SESSIONS_DIR
|
||||
from httpie.ssl import AVAILABLE_SSL_VERSION_ARG_MAPPING, DEFAULT_SSL_CIPHERS
|
||||
from ..plugins.builtin import BuiltinAuthPlugin
|
||||
from ..plugins.registry import plugin_manager
|
||||
from ..sessions import DEFAULT_SESSIONS_DIR
|
||||
from ..ssl import AVAILABLE_SSL_VERSION_ARG_MAPPING, DEFAULT_SSL_CIPHERS
|
||||
|
||||
|
||||
parser = HTTPieArgumentParser(
|
||||
prog='http',
|
||||
description='%s <https://httpie.org>' % __doc__.strip(),
|
||||
description=f'{__doc__.strip()} <https://httpie.org>',
|
||||
epilog=dedent('''
|
||||
For every --OPTION there is also a --no-OPTION that reverts OPTION
|
||||
to its default value.
|
||||
@ -185,6 +185,25 @@ content_type.add_argument(
|
||||
|
||||
'''
|
||||
)
|
||||
content_type.add_argument(
|
||||
'--raw',
|
||||
help='''
|
||||
This option allows you to pass raw request data without extra processing
|
||||
(as opposed to the structured request items syntax):
|
||||
|
||||
$ http --raw='data' pie.dev/post
|
||||
|
||||
You can achieve the same by piping the data via stdin:
|
||||
|
||||
$ echo data | http pie.dev/post
|
||||
|
||||
Or have HTTPie load the raw data from a file:
|
||||
|
||||
$ http pie.dev/post @data.txt
|
||||
|
||||
|
||||
'''
|
||||
)
|
||||
|
||||
|
||||
#######################################################################
|
||||
@ -237,7 +256,7 @@ output_processing.add_argument(
|
||||
help='''
|
||||
Output coloring style (default is "{default}"). It can be One of:
|
||||
|
||||
{available_styles}
|
||||
{available_styles}
|
||||
|
||||
The "{auto_style}" style follows your terminal's ANSI color styles.
|
||||
|
||||
@ -248,7 +267,7 @@ output_processing.add_argument(
|
||||
'''.format(
|
||||
default=DEFAULT_STYLE,
|
||||
available_styles='\n'.join(
|
||||
'{0}{1}'.format(8 * ' ', line.strip())
|
||||
f' {line.strip()}'
|
||||
for line in wrap(', '.join(sorted(AVAILABLE_STYLES)), 60)
|
||||
).strip(),
|
||||
auto_style=AUTO_STYLE,
|
||||
@ -311,7 +330,7 @@ output_processing.add_argument(
|
||||
|
||||
'''.format(
|
||||
option_list='\n'.join(
|
||||
(8 * ' ') + option for option in DEFAULT_FORMAT_OPTIONS).strip()
|
||||
f' {option}' for option in DEFAULT_FORMAT_OPTIONS).strip()
|
||||
)
|
||||
)
|
||||
|
||||
@ -364,12 +383,12 @@ output_options.add_argument(
|
||||
'--verbose', '-v',
|
||||
dest='verbose',
|
||||
action='store_true',
|
||||
help='''
|
||||
help=f'''
|
||||
Verbose output. Print the whole request as well as the response. Also print
|
||||
any intermediary requests/responses (such as redirects).
|
||||
It's a shortcut for: --all --print={0}
|
||||
It's a shortcut for: --all --print={''.join(OUTPUT_OPTIONS)}
|
||||
|
||||
'''.format(''.join(OUTPUT_OPTIONS))
|
||||
'''
|
||||
)
|
||||
output_options.add_argument(
|
||||
'--all',
|
||||
@ -543,7 +562,7 @@ auth.add_argument(
|
||||
name=plugin.name,
|
||||
package=(
|
||||
'' if issubclass(plugin, BuiltinAuthPlugin)
|
||||
else ' (provided by %s)' % plugin.package_name
|
||||
else f' (provided by {plugin.package_name})'
|
||||
),
|
||||
description=(
|
||||
'' if not plugin.description else
|
||||
@ -690,7 +709,7 @@ ssl.add_argument(
|
||||
ssl.add_argument(
|
||||
'--ssl',
|
||||
dest='ssl_version',
|
||||
choices=list(sorted(AVAILABLE_SSL_VERSION_ARG_MAPPING.keys())),
|
||||
choices=sorted(AVAILABLE_SSL_VERSION_ARG_MAPPING.keys()),
|
||||
help='''
|
||||
The desired protocol version to use. This will default to
|
||||
SSL v2.3 which will negotiate the highest protocol that both
|
||||
|
@ -1,21 +1,21 @@
|
||||
import os
|
||||
from typing import Callable, Dict, IO, List, Optional, Tuple, Union
|
||||
|
||||
from httpie.cli.argtypes import KeyValueArg
|
||||
from httpie.cli.constants import (
|
||||
from .argtypes import KeyValueArg
|
||||
from .constants import (
|
||||
SEPARATORS_GROUP_MULTIPART, SEPARATOR_DATA_EMBED_FILE_CONTENTS,
|
||||
SEPARATOR_DATA_EMBED_RAW_JSON_FILE,
|
||||
SEPARATOR_DATA_RAW_JSON, SEPARATOR_DATA_STRING, SEPARATOR_FILE_UPLOAD,
|
||||
SEPARATOR_FILE_UPLOAD_TYPE, SEPARATOR_HEADER, SEPARATOR_HEADER_EMPTY,
|
||||
SEPARATOR_QUERY_PARAM,
|
||||
)
|
||||
from httpie.cli.dicts import (
|
||||
from .dicts import (
|
||||
MultipartRequestDataDict, RequestDataDict, RequestFilesDict,
|
||||
RequestHeadersDict, RequestJSONDataDict,
|
||||
RequestQueryParamsDict,
|
||||
)
|
||||
from httpie.cli.exceptions import ParseError
|
||||
from httpie.utils import (get_content_type, load_json_preserve_order)
|
||||
from .exceptions import ParseError
|
||||
from ..utils import get_content_type, load_json_preserve_order
|
||||
|
||||
|
||||
class RequestItems:
|
||||
@ -89,13 +89,11 @@ def process_header_arg(arg: KeyValueArg) -> Optional[str]:
|
||||
|
||||
|
||||
def process_empty_header_arg(arg: KeyValueArg) -> str:
|
||||
if arg.value:
|
||||
raise ParseError(
|
||||
'Invalid item "%s" '
|
||||
'(to specify an empty header use `Header;`)'
|
||||
% arg.orig
|
||||
)
|
||||
return arg.value
|
||||
if not arg.value:
|
||||
return arg.value
|
||||
raise ParseError(
|
||||
f'Invalid item {arg.orig!r} (to specify an empty header use `Header;`)'
|
||||
)
|
||||
|
||||
|
||||
def process_query_param_arg(arg: KeyValueArg) -> str:
|
||||
@ -108,8 +106,8 @@ def process_file_upload_arg(arg: KeyValueArg) -> Tuple[str, IO, str]:
|
||||
mime_type = parts[1] if len(parts) > 1 else None
|
||||
try:
|
||||
f = open(os.path.expanduser(filename), 'rb')
|
||||
except IOError as e:
|
||||
raise ParseError('"%s": %s' % (arg.orig, e))
|
||||
except OSError as e:
|
||||
raise ParseError(f'{arg.orig!r}: {e}')
|
||||
return (
|
||||
os.path.basename(filename),
|
||||
f,
|
||||
@ -141,13 +139,12 @@ def load_text_file(item: KeyValueArg) -> str:
|
||||
try:
|
||||
with open(os.path.expanduser(path), 'rb') as f:
|
||||
return f.read().decode()
|
||||
except IOError as e:
|
||||
raise ParseError('"%s": %s' % (item.orig, e))
|
||||
except OSError as e:
|
||||
raise ParseError(f'{item.orig!r}: {e}')
|
||||
except UnicodeDecodeError:
|
||||
raise ParseError(
|
||||
'"%s": cannot embed the content of "%s",'
|
||||
' not a UTF8 or ASCII-encoded text file'
|
||||
% (item.orig, item.value)
|
||||
f'{item.orig!r}: cannot embed the content of {item.value!r},'
|
||||
' not a UTF-8 or ASCII-encoded text file'
|
||||
)
|
||||
|
||||
|
||||
@ -155,4 +152,4 @@ def load_json(arg: KeyValueArg, contents: str) -> JSONType:
|
||||
try:
|
||||
return load_json_preserve_order(contents)
|
||||
except ValueError as e:
|
||||
raise ParseError('"%s": %s' % (arg.orig, e))
|
||||
raise ParseError(f'{arg.orig!r}: {e}')
|
||||
|
@ -10,21 +10,22 @@ from urllib.parse import urlparse, urlunparse
|
||||
import requests
|
||||
# noinspection PyPackageRequirements
|
||||
import urllib3
|
||||
from httpie import __version__
|
||||
from httpie.cli.dicts import RequestHeadersDict
|
||||
from httpie.plugins.registry import plugin_manager
|
||||
from httpie.sessions import get_httpie_session
|
||||
from httpie.ssl import AVAILABLE_SSL_VERSION_ARG_MAPPING, HTTPieHTTPSAdapter
|
||||
from httpie.uploads import (
|
||||
from . import __version__
|
||||
from .cli.dicts import RequestHeadersDict
|
||||
from .constants import UTF8
|
||||
from .plugins.registry import plugin_manager
|
||||
from .sessions import get_httpie_session
|
||||
from .ssl import AVAILABLE_SSL_VERSION_ARG_MAPPING, HTTPieHTTPSAdapter
|
||||
from .uploads import (
|
||||
compress_request, prepare_request_body,
|
||||
get_multipart_data_and_content_type,
|
||||
)
|
||||
from httpie.utils import get_expired_cookies, repr_dict
|
||||
from .utils import get_expired_cookies, repr_dict
|
||||
|
||||
|
||||
urllib3.disable_warnings()
|
||||
|
||||
FORM_CONTENT_TYPE = 'application/x-www-form-urlencoded; charset=utf-8'
|
||||
FORM_CONTENT_TYPE = f'application/x-www-form-urlencoded; charset={UTF8}'
|
||||
JSON_CONTENT_TYPE = 'application/json'
|
||||
JSON_ACCEPT = f'{JSON_CONTENT_TYPE}, */*;q=0.5'
|
||||
DEFAULT_UA = f'HTTPie/{__version__}'
|
||||
@ -104,9 +105,8 @@ def collect_messages(
|
||||
**send_kwargs,
|
||||
)
|
||||
|
||||
# noinspection PyProtectedMember
|
||||
expired_cookies += get_expired_cookies(
|
||||
headers=response.raw._original_response.msg._headers
|
||||
response.headers.get('Set-Cookie', '')
|
||||
)
|
||||
|
||||
response_count += 1
|
||||
@ -189,7 +189,7 @@ def finalize_headers(headers: RequestHeadersDict) -> RequestHeadersDict:
|
||||
value = value.strip()
|
||||
if isinstance(value, str):
|
||||
# See <https://github.com/httpie/httpie/issues/212>
|
||||
value = value.encode('utf8')
|
||||
value = value.encode()
|
||||
final_headers[name] = value
|
||||
return final_headers
|
||||
|
||||
@ -213,11 +213,10 @@ def make_default_headers(args: argparse.Namespace) -> RequestHeadersDict:
|
||||
|
||||
|
||||
def make_send_kwargs(args: argparse.Namespace) -> dict:
|
||||
kwargs = {
|
||||
return {
|
||||
'timeout': args.timeout or None,
|
||||
'allow_redirects': False,
|
||||
}
|
||||
return kwargs
|
||||
|
||||
|
||||
def make_send_kwargs_mergeable_from_env(args: argparse.Namespace) -> dict:
|
||||
@ -226,7 +225,7 @@ def make_send_kwargs_mergeable_from_env(args: argparse.Namespace) -> dict:
|
||||
cert = args.cert
|
||||
if args.cert_key:
|
||||
cert = cert, args.cert_key
|
||||
kwargs = {
|
||||
return {
|
||||
'proxies': {p.key: p.value for p in args.proxy},
|
||||
'stream': True,
|
||||
'verify': {
|
||||
@ -237,7 +236,6 @@ def make_send_kwargs_mergeable_from_env(args: argparse.Namespace) -> dict:
|
||||
}.get(args.verify.lower(), args.verify),
|
||||
'cert': cert,
|
||||
}
|
||||
return kwargs
|
||||
|
||||
|
||||
def make_request_kwargs(
|
||||
@ -279,7 +277,7 @@ def make_request_kwargs(
|
||||
content_type=args.headers.get('Content-Type'),
|
||||
)
|
||||
|
||||
kwargs = {
|
||||
return {
|
||||
'method': args.method.lower(),
|
||||
'url': args.url,
|
||||
'headers': headers,
|
||||
@ -294,8 +292,6 @@ def make_request_kwargs(
|
||||
'params': args.params.items(),
|
||||
}
|
||||
|
||||
return kwargs
|
||||
|
||||
|
||||
def ensure_path_as_is(orig_url: str, prepped_url: str) -> str:
|
||||
"""
|
||||
@ -320,5 +316,4 @@ def ensure_path_as_is(orig_url: str, prepped_url: str) -> str:
|
||||
**parsed_prepped._asdict(),
|
||||
'path': parsed_orig.path,
|
||||
}
|
||||
final_url = urlunparse(tuple(final_dict.values()))
|
||||
return final_url
|
||||
return urlunparse(tuple(final_dict.values()))
|
||||
|
@ -1,11 +1,11 @@
|
||||
import errno
|
||||
import json
|
||||
import os
|
||||
from pathlib import Path
|
||||
from typing import Union
|
||||
|
||||
from httpie import __version__
|
||||
from httpie.compat import is_windows
|
||||
from . import __version__
|
||||
from .compat import is_windows
|
||||
from .constants import UTF8
|
||||
|
||||
|
||||
ENV_XDG_CONFIG_HOME = 'XDG_CONFIG_HOME'
|
||||
@ -72,11 +72,7 @@ class BaseConfigDict(dict):
|
||||
self.path = path
|
||||
|
||||
def ensure_directory(self):
|
||||
try:
|
||||
self.path.parent.mkdir(mode=0o700, parents=True)
|
||||
except OSError as e:
|
||||
if e.errno != errno.EEXIST:
|
||||
raise
|
||||
self.path.parent.mkdir(mode=0o700, parents=True, exist_ok=True)
|
||||
|
||||
def is_new(self) -> bool:
|
||||
return not self.path.exists()
|
||||
@ -84,7 +80,7 @@ class BaseConfigDict(dict):
|
||||
def load(self):
|
||||
config_type = type(self).__name__.lower()
|
||||
try:
|
||||
with self.path.open('rt') as f:
|
||||
with self.path.open(encoding=UTF8) as f:
|
||||
try:
|
||||
data = json.load(f)
|
||||
except ValueError as e:
|
||||
@ -92,11 +88,12 @@ class BaseConfigDict(dict):
|
||||
f'invalid {config_type} file: {e} [{self.path}]'
|
||||
)
|
||||
self.update(data)
|
||||
except IOError as e:
|
||||
if e.errno != errno.ENOENT:
|
||||
raise ConfigFileError(f'cannot read {config_type} file: {e}')
|
||||
except FileNotFoundError:
|
||||
pass
|
||||
except OSError as e:
|
||||
raise ConfigFileError(f'cannot read {config_type} file: {e}')
|
||||
|
||||
def save(self, fail_silently=False):
|
||||
def save(self):
|
||||
self['__meta__'] = {
|
||||
'httpie': __version__
|
||||
}
|
||||
@ -114,18 +111,7 @@ class BaseConfigDict(dict):
|
||||
sort_keys=True,
|
||||
ensure_ascii=True,
|
||||
)
|
||||
try:
|
||||
self.path.write_text(json_string + '\n')
|
||||
except IOError:
|
||||
if not fail_silently:
|
||||
raise
|
||||
|
||||
def delete(self):
|
||||
try:
|
||||
self.path.unlink()
|
||||
except OSError as e:
|
||||
if e.errno != errno.ENOENT:
|
||||
raise
|
||||
self.path.write_text(json_string + '\n', encoding=UTF8)
|
||||
|
||||
|
||||
class Config(BaseConfigDict):
|
||||
|
2
httpie/constants.py
Normal file
2
httpie/constants.py
Normal file
@ -0,0 +1,2 @@
|
||||
# UTF-8 encoding name
|
||||
UTF8 = 'utf-8'
|
@ -9,10 +9,11 @@ try:
|
||||
except ImportError:
|
||||
curses = None # Compiled w/o curses
|
||||
|
||||
from httpie.compat import is_windows
|
||||
from httpie.config import DEFAULT_CONFIG_DIR, Config, ConfigFileError
|
||||
from .compat import is_windows
|
||||
from .config import DEFAULT_CONFIG_DIR, Config, ConfigFileError
|
||||
from .constants import UTF8
|
||||
|
||||
from httpie.utils import repr_dict
|
||||
from .utils import repr_dict
|
||||
|
||||
|
||||
class Environment:
|
||||
@ -70,10 +71,10 @@ class Environment:
|
||||
self._orig_stderr = self.stderr
|
||||
self._devnull = devnull
|
||||
|
||||
# Keyword arguments > stream.encoding > default utf8
|
||||
# Keyword arguments > stream.encoding > default UTF-8
|
||||
if self.stdin and self.stdin_encoding is None:
|
||||
self.stdin_encoding = getattr(
|
||||
self.stdin, 'encoding', None) or 'utf8'
|
||||
self.stdin, 'encoding', None) or UTF8
|
||||
if self.stdout_encoding is None:
|
||||
actual_stdout = self.stdout
|
||||
if is_windows:
|
||||
@ -83,7 +84,7 @@ class Environment:
|
||||
# noinspection PyUnresolvedReferences
|
||||
actual_stdout = self.stdout.wrapped
|
||||
self.stdout_encoding = getattr(
|
||||
actual_stdout, 'encoding', None) or 'utf8'
|
||||
actual_stdout, 'encoding', None) or UTF8
|
||||
|
||||
def __str__(self):
|
||||
defaults = dict(type(self).__dict__)
|
||||
@ -119,10 +120,6 @@ class Environment:
|
||||
self._devnull = open(os.devnull, 'w+')
|
||||
return self._devnull
|
||||
|
||||
@devnull.setter
|
||||
def devnull(self, value):
|
||||
self._devnull = value
|
||||
|
||||
def log_error(self, msg, level='error'):
|
||||
assert level in ['error', 'warning']
|
||||
self._orig_stderr.write(f'\n{self.program_name}: {level}: {msg}\n\n')
|
||||
|
@ -8,14 +8,14 @@ import requests
|
||||
from pygments import __version__ as pygments_version
|
||||
from requests import __version__ as requests_version
|
||||
|
||||
from httpie import __version__ as httpie_version
|
||||
from httpie.cli.constants import OUT_REQ_BODY, OUT_REQ_HEAD, OUT_RESP_BODY, OUT_RESP_HEAD
|
||||
from httpie.client import collect_messages
|
||||
from httpie.context import Environment
|
||||
from httpie.downloads import Downloader
|
||||
from httpie.output.writer import write_message, write_stream, MESSAGE_SEPARATOR_BYTES
|
||||
from httpie.plugins.registry import plugin_manager
|
||||
from httpie.status import ExitStatus, http_status_to_exit_status
|
||||
from . import __version__ as httpie_version
|
||||
from .cli.constants import OUT_REQ_BODY, OUT_REQ_HEAD, OUT_RESP_BODY, OUT_RESP_HEAD
|
||||
from .client import collect_messages
|
||||
from .context import Environment
|
||||
from .downloads import Downloader
|
||||
from .output.writer import write_message, write_stream, MESSAGE_SEPARATOR_BYTES
|
||||
from .plugins.registry import plugin_manager
|
||||
from .status import ExitStatus, http_status_to_exit_status
|
||||
|
||||
|
||||
# noinspection PyDefaultArgument
|
||||
@ -34,7 +34,7 @@ def main(args: List[Union[str, bytes]] = sys.argv, env=Environment()) -> ExitSta
|
||||
args = decode_raw_args(args, env.stdin_encoding)
|
||||
plugin_manager.load_installed_plugins()
|
||||
|
||||
from httpie.cli.definition import parser
|
||||
from .cli.definition import parser
|
||||
|
||||
if env.config.default_options:
|
||||
args = env.config.default_options + args
|
||||
@ -177,10 +177,10 @@ def program(args: argparse.Namespace, env: Environment) -> ExitStatus:
|
||||
if is_request:
|
||||
if not initial_request:
|
||||
initial_request = message
|
||||
if with_body:
|
||||
is_streamed_upload = not isinstance(message.body, (str, bytes))
|
||||
if with_body:
|
||||
do_write_body = not is_streamed_upload
|
||||
force_separator = is_streamed_upload and env.stdout_isatty
|
||||
do_write_body = not is_streamed_upload
|
||||
force_separator = is_streamed_upload and env.stdout_isatty
|
||||
else:
|
||||
final_response = message
|
||||
if args.check_status or downloader:
|
||||
@ -205,16 +205,15 @@ def program(args: argparse.Namespace, env: Environment) -> ExitStatus:
|
||||
if downloader.interrupted:
|
||||
exit_status = ExitStatus.ERROR
|
||||
env.log_error(
|
||||
'Incomplete download: size=%d; downloaded=%d' % (
|
||||
downloader.status.total_size,
|
||||
downloader.status.downloaded
|
||||
))
|
||||
f'Incomplete download: size={downloader.status.total_size};'
|
||||
f' downloaded={downloader.status.downloaded}'
|
||||
)
|
||||
return exit_status
|
||||
|
||||
finally:
|
||||
if downloader and not downloader.finished:
|
||||
downloader.failed()
|
||||
if not isinstance(args, list) and args.output_file and args.output_file_specified:
|
||||
if args.output_file and args.output_file_specified:
|
||||
args.output_file.close()
|
||||
|
||||
|
||||
|
@ -1,26 +1,22 @@
|
||||
# coding=utf-8
|
||||
"""
|
||||
Download mode implementation.
|
||||
|
||||
"""
|
||||
from __future__ import division
|
||||
|
||||
import errno
|
||||
import mimetypes
|
||||
import os
|
||||
import re
|
||||
import sys
|
||||
import threading
|
||||
from mailbox import Message
|
||||
from time import sleep, time
|
||||
from time import sleep, monotonic
|
||||
from typing import IO, Optional, Tuple
|
||||
from urllib.parse import urlsplit
|
||||
|
||||
import requests
|
||||
|
||||
from httpie.models import HTTPResponse
|
||||
from httpie.output.streams import RawStream
|
||||
from httpie.utils import humanize_bytes
|
||||
from .models import HTTPResponse
|
||||
from .output.streams import RawStream
|
||||
from .utils import humanize_bytes
|
||||
|
||||
|
||||
PARTIAL_CONTENT = 206
|
||||
@ -64,7 +60,7 @@ def parse_content_range(content_range: str, resumed_from: int) -> int:
|
||||
|
||||
if not match:
|
||||
raise ContentRangeError(
|
||||
'Invalid Content-Range format %r' % content_range)
|
||||
f'Invalid Content-Range format {content_range!r}')
|
||||
|
||||
content_range_dict = match.groupdict()
|
||||
first_byte_pos = int(content_range_dict['first_byte_pos'])
|
||||
@ -81,20 +77,19 @@ def parse_content_range(content_range: str, resumed_from: int) -> int:
|
||||
# last-byte-pos value, is invalid. The recipient of an invalid
|
||||
# byte-content-range- spec MUST ignore it and any content
|
||||
# transferred along with it."
|
||||
if (first_byte_pos >= last_byte_pos
|
||||
if (first_byte_pos > last_byte_pos
|
||||
or (instance_length is not None
|
||||
and instance_length <= last_byte_pos)):
|
||||
raise ContentRangeError(
|
||||
'Invalid Content-Range returned: %r' % content_range)
|
||||
f'Invalid Content-Range returned: {content_range!r}')
|
||||
|
||||
if (first_byte_pos != resumed_from
|
||||
or (instance_length is not None
|
||||
and last_byte_pos + 1 != instance_length)):
|
||||
# Not what we asked for.
|
||||
raise ContentRangeError(
|
||||
'Unexpected Content-Range returned (%r)'
|
||||
' for the requested Range ("bytes=%d-")'
|
||||
% (content_range, resumed_from)
|
||||
f'Unexpected Content-Range returned ({content_range!r})'
|
||||
f' for the requested Range ("bytes={resumed_from}-")'
|
||||
)
|
||||
|
||||
return last_byte_pos + 1
|
||||
@ -112,7 +107,7 @@ def filename_from_content_disposition(
|
||||
"""
|
||||
# attachment; filename=jakubroztocil-httpie-0.4.1-20-g40bd8f6.tar.gz
|
||||
|
||||
msg = Message('Content-Disposition: %s' % content_disposition)
|
||||
msg = Message(f'Content-Disposition: {content_disposition}')
|
||||
filename = msg.get_filename()
|
||||
if filename:
|
||||
# Basic sanitation.
|
||||
@ -132,7 +127,7 @@ def filename_from_url(url: str, content_type: Optional[str]) -> str:
|
||||
else:
|
||||
ext = mimetypes.guess_extension(content_type)
|
||||
|
||||
if ext == '.htm': # Python 3
|
||||
if ext == '.htm':
|
||||
ext = '.html'
|
||||
|
||||
if ext:
|
||||
@ -154,16 +149,8 @@ def trim_filename(filename: str, max_len: int) -> str:
|
||||
|
||||
def get_filename_max_length(directory: str) -> int:
|
||||
max_len = 255
|
||||
try:
|
||||
pathconf = os.pathconf
|
||||
except AttributeError:
|
||||
pass # non-posix
|
||||
else:
|
||||
try:
|
||||
max_len = pathconf(directory, 'PC_NAME_MAX')
|
||||
except OSError as e:
|
||||
if e.errno != errno.EINVAL:
|
||||
raise
|
||||
if hasattr(os, 'pathconf') and 'PC_NAME_MAX' in os.pathconf_names:
|
||||
max_len = os.pathconf(directory, 'PC_NAME_MAX')
|
||||
return max_len
|
||||
|
||||
|
||||
@ -177,7 +164,7 @@ def trim_filename_if_needed(filename: str, directory='.', extra=0) -> str:
|
||||
def get_unique_filename(filename: str, exists=os.path.exists) -> str:
|
||||
attempt = 0
|
||||
while True:
|
||||
suffix = '-' + str(attempt) if attempt > 0 else ''
|
||||
suffix = f'-{attempt}' if attempt > 0 else ''
|
||||
try_filename = trim_filename_if_needed(filename, extra=len(suffix))
|
||||
try_filename += suffix
|
||||
if not exists(try_filename):
|
||||
@ -226,7 +213,7 @@ class Downloader:
|
||||
if bytes_have:
|
||||
# Set ``Range`` header to resume the download
|
||||
# TODO: Use "If-Range: mtime" to make sure it's fresh?
|
||||
request_headers['Range'] = 'bytes=%d-' % bytes_have
|
||||
request_headers['Range'] = f'bytes={bytes_have}-'
|
||||
self._resumed_from = bytes_have
|
||||
|
||||
def start(
|
||||
@ -271,7 +258,7 @@ class Downloader:
|
||||
try:
|
||||
self._output_file.seek(0)
|
||||
self._output_file.truncate()
|
||||
except IOError:
|
||||
except OSError:
|
||||
pass # stdout
|
||||
|
||||
self.status.started(
|
||||
@ -288,12 +275,8 @@ class Downloader:
|
||||
)
|
||||
|
||||
self._progress_reporter.output.write(
|
||||
'Downloading %sto "%s"\n' % (
|
||||
(humanize_bytes(total_size) + ' '
|
||||
if total_size is not None
|
||||
else ''),
|
||||
self._output_file.name
|
||||
)
|
||||
f'Downloading {humanize_bytes(total_size) + " " if total_size is not None else ""}'
|
||||
f'to "{self._output_file.name}"\n'
|
||||
)
|
||||
self._progress_reporter.start()
|
||||
|
||||
@ -358,7 +341,7 @@ class DownloadStatus:
|
||||
assert self.time_started is None
|
||||
self.total_size = total_size
|
||||
self.downloaded = self.resumed_from = resumed_from
|
||||
self.time_started = time()
|
||||
self.time_started = monotonic()
|
||||
|
||||
def chunk_downloaded(self, size):
|
||||
assert self.time_finished is None
|
||||
@ -371,7 +354,7 @@ class DownloadStatus:
|
||||
def finished(self):
|
||||
assert self.time_started is not None
|
||||
assert self.time_finished is None
|
||||
self.time_finished = time()
|
||||
self.time_finished = monotonic()
|
||||
|
||||
|
||||
class ProgressReporterThread(threading.Thread):
|
||||
@ -397,7 +380,7 @@ class ProgressReporterThread(threading.Thread):
|
||||
self._spinner_pos = 0
|
||||
self._status_line = ''
|
||||
self._prev_bytes = 0
|
||||
self._prev_time = time()
|
||||
self._prev_time = monotonic()
|
||||
self._should_stop = threading.Event()
|
||||
|
||||
def stop(self):
|
||||
@ -414,16 +397,11 @@ class ProgressReporterThread(threading.Thread):
|
||||
sleep(self._tick)
|
||||
|
||||
def report_speed(self):
|
||||
|
||||
now = time()
|
||||
|
||||
now = monotonic()
|
||||
if now - self._prev_time >= self._update_interval:
|
||||
downloaded = self.status.downloaded
|
||||
try:
|
||||
speed = ((downloaded - self._prev_bytes)
|
||||
/ (now - self._prev_time))
|
||||
except ZeroDivisionError:
|
||||
speed = 0
|
||||
speed = ((downloaded - self._prev_bytes)
|
||||
/ (now - self._prev_time))
|
||||
|
||||
if not self.status.total_size:
|
||||
self._status_line = PROGRESS_NO_CONTENT_LENGTH.format(
|
||||
@ -431,10 +409,9 @@ class ProgressReporterThread(threading.Thread):
|
||||
speed=humanize_bytes(speed),
|
||||
)
|
||||
else:
|
||||
try:
|
||||
percentage = downloaded / self.status.total_size * 100
|
||||
except ZeroDivisionError:
|
||||
percentage = 0
|
||||
percentage = (downloaded / self.status.total_size * 100
|
||||
if self.status.total_size
|
||||
else 0)
|
||||
|
||||
if not speed:
|
||||
eta = '-:--:--'
|
||||
@ -442,7 +419,7 @@ class ProgressReporterThread(threading.Thread):
|
||||
s = int((self.status.total_size - downloaded) / speed)
|
||||
h, s = divmod(s, 60 * 60)
|
||||
m, s = divmod(s, 60)
|
||||
eta = '{0}:{1:0>2}:{2:0>2}'.format(h, m, s)
|
||||
eta = f'{h}:{m:0>2}:{s:0>2}'
|
||||
|
||||
self._status_line = PROGRESS.format(
|
||||
percentage=percentage,
|
||||
@ -455,33 +432,20 @@ class ProgressReporterThread(threading.Thread):
|
||||
self._prev_bytes = downloaded
|
||||
|
||||
self.output.write(
|
||||
CLEAR_LINE
|
||||
+ ' '
|
||||
+ SPINNER[self._spinner_pos]
|
||||
+ ' '
|
||||
+ self._status_line
|
||||
f'{CLEAR_LINE} {SPINNER[self._spinner_pos]} {self._status_line}'
|
||||
)
|
||||
self.output.flush()
|
||||
|
||||
self._spinner_pos = (self._spinner_pos + 1
|
||||
if self._spinner_pos + 1 != len(SPINNER)
|
||||
else 0)
|
||||
self._spinner_pos = (self._spinner_pos + 1) % len(SPINNER)
|
||||
|
||||
def sum_up(self):
|
||||
actually_downloaded = (
|
||||
self.status.downloaded - self.status.resumed_from)
|
||||
time_taken = self.status.time_finished - self.status.time_started
|
||||
speed = actually_downloaded / time_taken if time_taken else actually_downloaded
|
||||
|
||||
self.output.write(CLEAR_LINE)
|
||||
|
||||
try:
|
||||
speed = actually_downloaded / time_taken
|
||||
except ZeroDivisionError:
|
||||
# Either time is 0 (not all systems provide `time.time`
|
||||
# with a better precision than 1 second), and/or nothing
|
||||
# has been downloaded.
|
||||
speed = actually_downloaded
|
||||
|
||||
self.output.write(SUMMARY.format(
|
||||
downloaded=humanize_bytes(actually_downloaded),
|
||||
total=(self.status.total_size
|
||||
|
@ -1,30 +1,34 @@
|
||||
from abc import ABCMeta, abstractmethod
|
||||
from typing import Iterable, Optional
|
||||
from urllib.parse import urlsplit
|
||||
|
||||
from .constants import UTF8
|
||||
from .utils import split_cookies
|
||||
|
||||
class HTTPMessage:
|
||||
|
||||
class HTTPMessage(metaclass=ABCMeta):
|
||||
"""Abstract class for HTTP messages."""
|
||||
|
||||
def __init__(self, orig):
|
||||
self._orig = orig
|
||||
|
||||
@abstractmethod
|
||||
def iter_body(self, chunk_size: int) -> Iterable[bytes]:
|
||||
"""Return an iterator over the body."""
|
||||
raise NotImplementedError()
|
||||
|
||||
@abstractmethod
|
||||
def iter_lines(self, chunk_size: int) -> Iterable[bytes]:
|
||||
"""Return an iterator over the body yielding (`line`, `line_feed`)."""
|
||||
raise NotImplementedError()
|
||||
|
||||
@property
|
||||
@abstractmethod
|
||||
def headers(self) -> str:
|
||||
"""Return a `str` with the message's headers."""
|
||||
raise NotImplementedError()
|
||||
|
||||
@property
|
||||
@abstractmethod
|
||||
def encoding(self) -> Optional[str]:
|
||||
"""Return a `str` with the message's encoding, if known."""
|
||||
raise NotImplementedError()
|
||||
|
||||
@property
|
||||
def body(self) -> bytes:
|
||||
@ -36,7 +40,7 @@ class HTTPMessage:
|
||||
"""Return the message content type."""
|
||||
ct = self._orig.headers.get('Content-Type', '')
|
||||
if not isinstance(ct, str):
|
||||
ct = ct.decode('utf8')
|
||||
ct = ct.decode()
|
||||
return ct
|
||||
|
||||
|
||||
@ -52,32 +56,35 @@ class HTTPResponse(HTTPMessage):
|
||||
# noinspection PyProtectedMember
|
||||
@property
|
||||
def headers(self):
|
||||
original = self._orig.raw._original_response
|
||||
|
||||
try:
|
||||
raw_version = self._orig.raw._original_response.version
|
||||
except AttributeError:
|
||||
# Assume HTTP/1.1
|
||||
raw_version = 11
|
||||
version = {
|
||||
9: '0.9',
|
||||
10: '1.0',
|
||||
11: '1.1',
|
||||
20: '2',
|
||||
}[original.version]
|
||||
}[raw_version]
|
||||
|
||||
status_line = f'HTTP/{version} {original.status} {original.reason}'
|
||||
original = self._orig
|
||||
status_line = f'HTTP/{version} {original.status_code} {original.reason}'
|
||||
headers = [status_line]
|
||||
try:
|
||||
# `original.msg` is a `http.client.HTTPMessage` on Python 3
|
||||
# `_headers` is a 2-tuple
|
||||
headers.extend(
|
||||
'%s: %s' % header for header in original.msg._headers)
|
||||
except AttributeError:
|
||||
# and a `httplib.HTTPMessage` on Python 2.x
|
||||
# `headers` is a list of `name: val<CRLF>`.
|
||||
headers.extend(h.strip() for h in original.msg.headers)
|
||||
|
||||
headers.extend(
|
||||
': '.join(header)
|
||||
for header in original.headers.items()
|
||||
if header[0] != 'Set-Cookie'
|
||||
)
|
||||
headers.extend(
|
||||
f'Set-Cookie: {cookie}'
|
||||
for cookie in split_cookies(original.headers.get('Set-Cookie'))
|
||||
)
|
||||
return '\r\n'.join(headers)
|
||||
|
||||
@property
|
||||
def encoding(self):
|
||||
return self._orig.encoding or 'utf8'
|
||||
return self._orig.encoding or UTF8
|
||||
|
||||
@property
|
||||
def body(self):
|
||||
@ -102,7 +109,7 @@ class HTTPRequest(HTTPMessage):
|
||||
request_line = '{method} {path}{query} HTTP/1.1'.format(
|
||||
method=self._orig.method,
|
||||
path=url.path or '/',
|
||||
query='?' + url.query if url.query else ''
|
||||
query=f'?{url.query}' if url.query else ''
|
||||
)
|
||||
|
||||
headers = dict(self._orig.headers)
|
||||
@ -110,29 +117,22 @@ class HTTPRequest(HTTPMessage):
|
||||
headers['Host'] = url.netloc.split('@')[-1]
|
||||
|
||||
headers = [
|
||||
'%s: %s' % (
|
||||
name,
|
||||
value if isinstance(value, str) else value.decode('utf8')
|
||||
)
|
||||
f'{name}: {value if isinstance(value, str) else value.decode()}'
|
||||
for name, value in headers.items()
|
||||
]
|
||||
|
||||
headers.insert(0, request_line)
|
||||
headers = '\r\n'.join(headers).strip()
|
||||
|
||||
if isinstance(headers, bytes):
|
||||
# Python < 3
|
||||
headers = headers.decode('utf8')
|
||||
return headers
|
||||
|
||||
@property
|
||||
def encoding(self):
|
||||
return 'utf8'
|
||||
return UTF8
|
||||
|
||||
@property
|
||||
def body(self):
|
||||
body = self._orig.body
|
||||
if isinstance(body, str):
|
||||
# Happens with JSON/form request data parsed from the command line.
|
||||
body = body.encode('utf8')
|
||||
body = body.encode()
|
||||
return body or b''
|
||||
|
@ -1,5 +1,3 @@
|
||||
from __future__ import absolute_import
|
||||
|
||||
import json
|
||||
from typing import Optional, Type
|
||||
|
||||
@ -15,9 +13,9 @@ from pygments.lexers.special import TextLexer
|
||||
from pygments.lexers.text import HttpLexer as PygmentsHttpLexer
|
||||
from pygments.util import ClassNotFound
|
||||
|
||||
from httpie.compat import is_windows
|
||||
from httpie.context import Environment
|
||||
from httpie.plugins import FormatterPlugin
|
||||
from ...compat import is_windows
|
||||
from ...context import Environment
|
||||
from ...plugins import FormatterPlugin
|
||||
|
||||
|
||||
AUTO_STYLE = 'auto' # Follows terminal ANSI color styles
|
||||
@ -120,8 +118,8 @@ def get_lexer(
|
||||
subtype_name, subtype_suffix = subtype.split('+', 1)
|
||||
lexer_names.extend([subtype_name, subtype_suffix])
|
||||
mime_types.extend([
|
||||
'%s/%s' % (type_, subtype_name),
|
||||
'%s/%s' % (type_, subtype_suffix)
|
||||
f'{type_}/{subtype_name}',
|
||||
f'{type_}/{subtype_suffix}',
|
||||
])
|
||||
|
||||
# As a last resort, if no lexer feels responsible, and
|
||||
|
@ -1,4 +1,4 @@
|
||||
from httpie.plugins import FormatterPlugin
|
||||
from ...plugins import FormatterPlugin
|
||||
|
||||
|
||||
class HeadersFormatter(FormatterPlugin):
|
||||
|
@ -1,7 +1,6 @@
|
||||
from __future__ import absolute_import
|
||||
import json
|
||||
|
||||
from httpie.plugins import FormatterPlugin
|
||||
from ...plugins import FormatterPlugin
|
||||
|
||||
|
||||
class JSONFormatter(FormatterPlugin):
|
||||
|
59
httpie/output/formatters/xml.py
Normal file
59
httpie/output/formatters/xml.py
Normal file
@ -0,0 +1,59 @@
|
||||
import sys
|
||||
from typing import TYPE_CHECKING, Optional
|
||||
|
||||
from ...constants import UTF8
|
||||
from ...plugins import FormatterPlugin
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from xml.dom.minidom import Document
|
||||
|
||||
|
||||
def parse_xml(data: str) -> 'Document':
|
||||
"""Parse given XML `data` string into an appropriate :class:`~xml.dom.minidom.Document` object."""
|
||||
from defusedxml.minidom import parseString
|
||||
return parseString(data)
|
||||
|
||||
|
||||
def pretty_xml(document: 'Document',
|
||||
encoding: Optional[str] = UTF8,
|
||||
indent: int = 2,
|
||||
standalone: Optional[bool] = None) -> str:
|
||||
"""Render the given :class:`~xml.dom.minidom.Document` `document` into a prettified string."""
|
||||
kwargs = {
|
||||
'encoding': encoding or UTF8,
|
||||
'indent': ' ' * indent,
|
||||
}
|
||||
if standalone is not None and sys.version_info >= (3, 9):
|
||||
kwargs['standalone'] = standalone
|
||||
body = document.toprettyxml(**kwargs).decode()
|
||||
|
||||
# Remove blank lines automatically added by `toprettyxml()`.
|
||||
return '\n'.join(line for line in body.splitlines() if line.strip())
|
||||
|
||||
|
||||
class XMLFormatter(FormatterPlugin):
|
||||
|
||||
def __init__(self, **kwargs):
|
||||
super().__init__(**kwargs)
|
||||
self.enabled = self.format_options['xml']['format']
|
||||
|
||||
def format_body(self, body: str, mime: str):
|
||||
if 'xml' not in mime:
|
||||
return body
|
||||
|
||||
from xml.parsers.expat import ExpatError
|
||||
from defusedxml.common import DefusedXmlException
|
||||
|
||||
try:
|
||||
parsed_body = parse_xml(body)
|
||||
except ExpatError:
|
||||
pass # Invalid XML, ignore.
|
||||
except DefusedXmlException:
|
||||
pass # Unsafe XML, ignore.
|
||||
else:
|
||||
body = pretty_xml(parsed_body,
|
||||
encoding=parsed_body.encoding,
|
||||
indent=self.format_options['xml']['indent'],
|
||||
standalone=parsed_body.standalone)
|
||||
|
||||
return body
|
@ -1,9 +1,9 @@
|
||||
import re
|
||||
from typing import Optional, List
|
||||
|
||||
from httpie.plugins import ConverterPlugin
|
||||
from httpie.plugins.registry import plugin_manager
|
||||
from httpie.context import Environment
|
||||
from ..plugins import ConverterPlugin
|
||||
from ..plugins.registry import plugin_manager
|
||||
from ..context import Environment
|
||||
|
||||
|
||||
MIME_RE = re.compile(r'^[^/]+/[^/]+$')
|
||||
|
@ -1,9 +1,11 @@
|
||||
from abc import ABCMeta, abstractmethod
|
||||
from itertools import chain
|
||||
from typing import Callable, Iterable, Union
|
||||
|
||||
from httpie.context import Environment
|
||||
from httpie.models import HTTPMessage
|
||||
from httpie.output.processing import Conversion, Formatting
|
||||
from ..context import Environment
|
||||
from ..constants import UTF8
|
||||
from ..models import HTTPMessage
|
||||
from .processing import Conversion, Formatting
|
||||
|
||||
|
||||
BINARY_SUPPRESSED_NOTICE = (
|
||||
@ -24,7 +26,7 @@ class BinarySuppressedError(DataSuppressedError):
|
||||
message = BINARY_SUPPRESSED_NOTICE
|
||||
|
||||
|
||||
class BaseStream:
|
||||
class BaseStream(metaclass=ABCMeta):
|
||||
"""Base HTTP message output stream class."""
|
||||
|
||||
def __init__(
|
||||
@ -48,11 +50,11 @@ class BaseStream:
|
||||
|
||||
def get_headers(self) -> bytes:
|
||||
"""Return the headers' bytes."""
|
||||
return self.msg.headers.encode('utf8')
|
||||
return self.msg.headers.encode()
|
||||
|
||||
@abstractmethod
|
||||
def iter_body(self) -> Iterable[bytes]:
|
||||
"""Return an iterator over the message body."""
|
||||
raise NotImplementedError()
|
||||
|
||||
def __iter__(self) -> Iterable[bytes]:
|
||||
"""Return an iterator over `self.msg`."""
|
||||
@ -104,8 +106,8 @@ class EncodedStream(BaseStream):
|
||||
else:
|
||||
# Preserve the message encoding.
|
||||
output_encoding = self.msg.encoding
|
||||
# Default to utf8 when unsure.
|
||||
self.output_encoding = output_encoding or 'utf8'
|
||||
# Default to UTF-8 when unsure.
|
||||
self.output_encoding = output_encoding or UTF8
|
||||
|
||||
def iter_body(self) -> Iterable[bytes]:
|
||||
for line, lf in self.msg.iter_lines(self.CHUNK_SIZE):
|
||||
|
@ -4,10 +4,10 @@ from typing import IO, TextIO, Tuple, Type, Union
|
||||
|
||||
import requests
|
||||
|
||||
from httpie.context import Environment
|
||||
from httpie.models import HTTPRequest, HTTPResponse
|
||||
from httpie.output.processing import Conversion, Formatting
|
||||
from httpie.output.streams import (
|
||||
from ..context import Environment
|
||||
from ..models import HTTPRequest, HTTPResponse
|
||||
from .processing import Conversion, Formatting
|
||||
from .streams import (
|
||||
BaseStream, BufferedPrettyStream, EncodedStream, PrettyStream, RawStream,
|
||||
)
|
||||
|
||||
@ -39,10 +39,10 @@ def write_message(
|
||||
}
|
||||
try:
|
||||
if env.is_windows and 'colors' in args.prettify:
|
||||
write_stream_with_colors_win_py3(**write_stream_kwargs)
|
||||
write_stream_with_colors_win(**write_stream_kwargs)
|
||||
else:
|
||||
write_stream(**write_stream_kwargs)
|
||||
except IOError as e:
|
||||
except OSError as e:
|
||||
show_traceback = args.debug or args.traceback
|
||||
if not show_traceback and e.errno == errno.EPIPE:
|
||||
# Ignore broken pipes unless --traceback.
|
||||
@ -58,7 +58,7 @@ def write_stream(
|
||||
):
|
||||
"""Write the output stream."""
|
||||
try:
|
||||
# Writing bytes so we use the buffer interface (Python 3).
|
||||
# Writing bytes so we use the buffer interface.
|
||||
buf = outfile.buffer
|
||||
except AttributeError:
|
||||
buf = outfile
|
||||
@ -69,14 +69,14 @@ def write_stream(
|
||||
outfile.flush()
|
||||
|
||||
|
||||
def write_stream_with_colors_win_py3(
|
||||
def write_stream_with_colors_win(
|
||||
stream: 'BaseStream',
|
||||
outfile: TextIO,
|
||||
flush: bool
|
||||
):
|
||||
"""Like `write`, but colorized chunks are written as text
|
||||
directly to `outfile` to ensure it gets processed by colorama.
|
||||
Applies only to Windows with Python 3 and colorized terminal output.
|
||||
Applies only to Windows and colorized terminal output.
|
||||
|
||||
"""
|
||||
color = b'\x1b['
|
||||
|
@ -3,7 +3,9 @@ WARNING: The plugin API is still work in progress and will
|
||||
probably be completely reworked in the future.
|
||||
|
||||
"""
|
||||
from httpie.plugins.base import (
|
||||
from .base import (
|
||||
AuthPlugin, FormatterPlugin,
|
||||
ConverterPlugin, TransportPlugin
|
||||
)
|
||||
|
||||
__all__ = ('AuthPlugin', 'ConverterPlugin', 'FormatterPlugin', 'TransportPlugin')
|
||||
|
@ -2,7 +2,7 @@ from base64 import b64encode
|
||||
|
||||
import requests.auth
|
||||
|
||||
from httpie.plugins.base import AuthPlugin
|
||||
from .base import AuthPlugin
|
||||
|
||||
|
||||
# noinspection PyAbstractClass
|
||||
@ -29,9 +29,9 @@ class HTTPBasicAuth(requests.auth.HTTPBasicAuth):
|
||||
|
||||
@staticmethod
|
||||
def make_header(username: str, password: str) -> str:
|
||||
credentials = u'%s:%s' % (username, password)
|
||||
token = b64encode(credentials.encode('utf8')).strip().decode('latin1')
|
||||
return 'Basic %s' % token
|
||||
credentials = f'{username}:{password}'
|
||||
token = b64encode(credentials.encode()).strip().decode('latin1')
|
||||
return f'Basic {token}'
|
||||
|
||||
|
||||
class BasicAuthPlugin(BuiltinAuthPlugin):
|
||||
|
@ -4,8 +4,8 @@ from typing import Dict, List, Type
|
||||
|
||||
from pkg_resources import iter_entry_points
|
||||
|
||||
from httpie.plugins import AuthPlugin, ConverterPlugin, FormatterPlugin
|
||||
from httpie.plugins.base import BasePlugin, TransportPlugin
|
||||
from . import AuthPlugin, ConverterPlugin, FormatterPlugin
|
||||
from .base import BasePlugin, TransportPlugin
|
||||
|
||||
|
||||
ENTRY_POINT_NAMES = [
|
||||
|
@ -1,8 +1,9 @@
|
||||
from httpie.plugins.manager import PluginManager
|
||||
from httpie.plugins.builtin import BasicAuthPlugin, DigestAuthPlugin
|
||||
from httpie.output.formatters.headers import HeadersFormatter
|
||||
from httpie.output.formatters.json import JSONFormatter
|
||||
from httpie.output.formatters.colors import ColorFormatter
|
||||
from .manager import PluginManager
|
||||
from .builtin import BasicAuthPlugin, DigestAuthPlugin
|
||||
from ..output.formatters.headers import HeadersFormatter
|
||||
from ..output.formatters.json import JSONFormatter
|
||||
from ..output.formatters.xml import XMLFormatter
|
||||
from ..output.formatters.colors import ColorFormatter
|
||||
|
||||
|
||||
plugin_manager = PluginManager()
|
||||
@ -14,5 +15,6 @@ plugin_manager.register(
|
||||
DigestAuthPlugin,
|
||||
HeadersFormatter,
|
||||
JSONFormatter,
|
||||
XMLFormatter,
|
||||
ColorFormatter,
|
||||
)
|
||||
|
@ -13,9 +13,9 @@ from urllib.parse import urlsplit
|
||||
from requests.auth import AuthBase
|
||||
from requests.cookies import RequestsCookieJar, create_cookie
|
||||
|
||||
from httpie.cli.dicts import RequestHeadersDict
|
||||
from httpie.config import BaseConfigDict, DEFAULT_CONFIG_DIR
|
||||
from httpie.plugins.registry import plugin_manager
|
||||
from .cli.dicts import RequestHeadersDict
|
||||
from .config import BaseConfigDict, DEFAULT_CONFIG_DIR
|
||||
from .plugins.registry import plugin_manager
|
||||
|
||||
|
||||
SESSIONS_DIR_NAME = 'sessions'
|
||||
@ -72,13 +72,13 @@ class Session(BaseConfigDict):
|
||||
|
||||
"""
|
||||
headers = self.headers
|
||||
for name, value in request_headers.items():
|
||||
for name, value in request_headers.copy().items():
|
||||
|
||||
if value is None:
|
||||
continue # Ignore explicitly unset headers
|
||||
|
||||
if type(value) is not str:
|
||||
value = value.decode('utf8')
|
||||
value = value.decode()
|
||||
|
||||
if name.lower() == 'user-agent' and value.startswith('HTTPie/'):
|
||||
continue
|
||||
@ -141,7 +141,7 @@ class Session(BaseConfigDict):
|
||||
}
|
||||
else:
|
||||
if plugin.auth_parse:
|
||||
from httpie.cli.argtypes import parse_auth
|
||||
from .cli.argtypes import parse_auth
|
||||
parsed = parse_auth(plugin.raw_auth)
|
||||
credentials = {
|
||||
'username': parsed.key,
|
||||
|
@ -6,7 +6,7 @@ import requests
|
||||
from requests.utils import super_len
|
||||
from requests_toolbelt import MultipartEncoder
|
||||
|
||||
from httpie.cli.dicts import MultipartRequestDataDict, RequestDataDict
|
||||
from .cli.dicts import MultipartRequestDataDict, RequestDataDict
|
||||
|
||||
|
||||
class ChunkedUploadStream:
|
||||
|
@ -1,5 +1,3 @@
|
||||
from __future__ import division
|
||||
|
||||
import json
|
||||
import mimetypes
|
||||
import time
|
||||
@ -7,9 +5,12 @@ from collections import OrderedDict
|
||||
from http.cookiejar import parse_ns_headers
|
||||
from pprint import pformat
|
||||
from typing import List, Optional, Tuple
|
||||
import re
|
||||
|
||||
import requests.auth
|
||||
|
||||
RE_COOKIE_SPLIT = re.compile(r', (?=[^ ;]+=)')
|
||||
|
||||
|
||||
def load_json_preserve_order(s):
|
||||
return json.loads(s, object_pairs_hook=OrderedDict)
|
||||
@ -25,8 +26,6 @@ def humanize_bytes(n, precision=2):
|
||||
# URL: https://code.activestate.com/recipes/577081/
|
||||
"""Return a humanized string representation of a number of bytes.
|
||||
|
||||
Assumes `from __future__ import division`.
|
||||
|
||||
>>> humanize_bytes(1)
|
||||
'1 B'
|
||||
>>> humanize_bytes(1024, precision=1)
|
||||
@ -62,7 +61,7 @@ def humanize_bytes(n, precision=2):
|
||||
break
|
||||
|
||||
# noinspection PyUnboundLocalVariable
|
||||
return '%.*f %s' % (precision, n / factor, suffix)
|
||||
return f'{n / factor:.{precision}f} {suffix}'
|
||||
|
||||
|
||||
class ExplicitNullAuth(requests.auth.AuthBase):
|
||||
@ -81,16 +80,24 @@ def get_content_type(filename):
|
||||
to ``mimetypes``.
|
||||
|
||||
"""
|
||||
mime, encoding = mimetypes.guess_type(filename, strict=False)
|
||||
if mime:
|
||||
content_type = mime
|
||||
if encoding:
|
||||
content_type = '%s; charset=%s' % (mime, encoding)
|
||||
return content_type
|
||||
return mimetypes.guess_type(filename, strict=False)[0]
|
||||
|
||||
|
||||
def split_cookies(cookies):
|
||||
"""
|
||||
When ``requests`` stores cookies in ``response.headers['Set-Cookie']``
|
||||
it concatenates all of them through ``, ``.
|
||||
|
||||
This function splits cookies apart being careful to not to
|
||||
split on ``, `` which may be part of cookie value.
|
||||
"""
|
||||
if not cookies:
|
||||
return []
|
||||
return RE_COOKIE_SPLIT.split(cookies)
|
||||
|
||||
|
||||
def get_expired_cookies(
|
||||
headers: List[Tuple[str, str]],
|
||||
cookies: str,
|
||||
now: float = None
|
||||
) -> List[dict]:
|
||||
|
||||
@ -100,9 +107,9 @@ def get_expired_cookies(
|
||||
return expires is not None and expires <= now
|
||||
|
||||
attr_sets: List[Tuple[str, str]] = parse_ns_headers(
|
||||
value for name, value in headers
|
||||
if name.lower() == 'set-cookie'
|
||||
split_cookies(cookies)
|
||||
)
|
||||
|
||||
cookies = [
|
||||
# The first attr name is the cookie name.
|
||||
dict(attrs[1:], name=attrs[0][0])
|
||||
|
@ -1,8 +0,0 @@
|
||||
mock
|
||||
pytest
|
||||
pytest-cov
|
||||
pytest-httpbin>=0.0.6
|
||||
docutils
|
||||
wheel
|
||||
pycodestyle
|
||||
twine
|
17
setup.cfg
17
setup.cfg
@ -1,19 +1,18 @@
|
||||
# Please keep all characters in this file in ASCII
|
||||
# distutils uses system's locale to interpret it and not everybody
|
||||
# uses UTF-8. See https://github.com/httpie/httpie/issues/1039
|
||||
# for an example
|
||||
[wheel]
|
||||
|
||||
|
||||
[tool:pytest]
|
||||
# <https://docs.pytest.org/en/latest/customize.html>
|
||||
norecursedirs = tests/fixtures
|
||||
norecursedirs = tests/fixtures .*
|
||||
addopts = --tb=native --doctest-modules
|
||||
|
||||
|
||||
[pycodestyle]
|
||||
# <http://pycodestyle.pycqa.org/en/latest/intro.html#configuration>
|
||||
|
||||
exclude = .git,.idea,__pycache__,build,dist,.pytest_cache,*.egg-info
|
||||
|
||||
# <http://pycodestyle.pycqa.org/en/latest/intro.html#error-codes>
|
||||
# E241 - multiple spaces after ‘,’
|
||||
[flake8]
|
||||
# <https://flake8.pycqa.org/en/latest/user/error-codes.html>
|
||||
# E501 - line too long
|
||||
# W503 - line break before binary operator
|
||||
ignore = E241,E501,W503
|
||||
ignore = E501,W503
|
||||
|
56
setup.py
56
setup.py
@ -1,47 +1,35 @@
|
||||
# This is purely the result of trial and error.
|
||||
|
||||
import sys
|
||||
import codecs
|
||||
|
||||
from setuptools import setup, find_packages
|
||||
from setuptools.command.test import test as TestCommand
|
||||
|
||||
import httpie
|
||||
|
||||
|
||||
class PyTest(TestCommand):
|
||||
"""
|
||||
Running `$ python setup.py test' simply installs minimal requirements
|
||||
and runs the tests with no fancy stuff like parallel execution.
|
||||
|
||||
"""
|
||||
|
||||
def finalize_options(self):
|
||||
TestCommand.finalize_options(self)
|
||||
self.test_args = [
|
||||
'--doctest-modules',
|
||||
'--verbose',
|
||||
'./httpie',
|
||||
'./tests',
|
||||
]
|
||||
self.test_suite = True
|
||||
|
||||
def run_tests(self):
|
||||
import pytest
|
||||
sys.exit(pytest.main(self.test_args))
|
||||
|
||||
|
||||
# Note: keep requirements here to ease distributions packaging
|
||||
tests_require = [
|
||||
'pytest-httpbin',
|
||||
'pytest',
|
||||
'mock',
|
||||
'pytest-httpbin>=0.0.6',
|
||||
'responses',
|
||||
]
|
||||
dev_require = [
|
||||
*tests_require,
|
||||
'flake8',
|
||||
'flake8-comprehensions',
|
||||
'flake8-deprecated',
|
||||
'flake8-mutable',
|
||||
'flake8-tuple',
|
||||
'mdformat',
|
||||
'pytest-cov',
|
||||
'twine',
|
||||
'wheel',
|
||||
]
|
||||
|
||||
|
||||
install_requires = [
|
||||
'defusedxml>=0.6.0',
|
||||
'requests[socks]>=2.22.0',
|
||||
'Pygments>=2.5.2',
|
||||
'requests-toolbelt>=0.9.1',
|
||||
'setuptools',
|
||||
]
|
||||
install_requires_win_only = [
|
||||
'colorama>=0.2.4',
|
||||
@ -59,13 +47,15 @@ if 'bdist_wheel' not in sys.argv:
|
||||
|
||||
# bdist_wheel
|
||||
extras_require = {
|
||||
'dev': dev_require,
|
||||
'test': tests_require,
|
||||
# https://wheel.readthedocs.io/en/latest/#defining-conditional-dependencies
|
||||
':sys_platform == "win32"': install_requires_win_only,
|
||||
}
|
||||
|
||||
|
||||
def long_description():
|
||||
with codecs.open('README.rst', encoding='utf8') as f:
|
||||
with open('README.md', encoding='utf-8') as f:
|
||||
return f.read()
|
||||
|
||||
|
||||
@ -74,13 +64,13 @@ setup(
|
||||
version=httpie.__version__,
|
||||
description=httpie.__doc__.strip(),
|
||||
long_description=long_description(),
|
||||
long_description_content_type='text/x-rst',
|
||||
long_description_content_type='text/markdown',
|
||||
url='https://httpie.org/',
|
||||
download_url=f'https://github.com/httpie/httpie/archive/{httpie.__version__}.tar.gz',
|
||||
author=httpie.__author__,
|
||||
author_email='jakub@roztocil.co',
|
||||
license=httpie.__licence__,
|
||||
packages=find_packages(),
|
||||
packages=find_packages(include=['httpie', 'httpie.*']),
|
||||
entry_points={
|
||||
'console_scripts': [
|
||||
'http = httpie.__main__:main',
|
||||
@ -90,8 +80,6 @@ setup(
|
||||
python_requires='>=3.6',
|
||||
extras_require=extras_require,
|
||||
install_requires=install_requires,
|
||||
tests_require=tests_require,
|
||||
cmdclass={'test': PyTest},
|
||||
classifiers=[
|
||||
'Development Status :: 5 - Production/Stable',
|
||||
'Programming Language :: Python',
|
||||
|
3
tests/README.md
Normal file
3
tests/README.md
Normal file
@ -0,0 +1,3 @@
|
||||
# HTTPie Test Suite
|
||||
|
||||
Please see [CONTRIBUTING](https://github.com/httpie/httpie/blob/master/CONTRIBUTING.md) for contribution and testing guidelines.
|
@ -1,8 +0,0 @@
|
||||
HTTPie Test Suite
|
||||
=================
|
||||
|
||||
|
||||
Please see `CONTRIBUTING`_.
|
||||
|
||||
|
||||
.. _CONTRIBUTING: https://github.com/httpie/httpie/blob/master/CONTRIBUTING.rst
|
0
tests/__init__.py
Normal file
0
tests/__init__.py
Normal file
@ -1,6 +1,9 @@
|
||||
import socket
|
||||
import pytest
|
||||
from pytest_httpbin import certs
|
||||
|
||||
from .utils import HTTPBIN_WITH_CHUNKED_SUPPORT_DOMAIN, HTTPBIN_WITH_CHUNKED_SUPPORT
|
||||
|
||||
|
||||
@pytest.fixture(scope='function', autouse=True)
|
||||
def httpbin_add_ca_bundle(monkeypatch):
|
||||
@ -22,3 +25,19 @@ def httpbin_secure_untrusted(monkeypatch, httpbin_secure):
|
||||
"""
|
||||
monkeypatch.delenv('REQUESTS_CA_BUNDLE')
|
||||
return httpbin_secure
|
||||
|
||||
|
||||
@pytest.fixture(scope='session')
|
||||
def _httpbin_with_chunked_support_available():
|
||||
try:
|
||||
socket.gethostbyname(HTTPBIN_WITH_CHUNKED_SUPPORT_DOMAIN)
|
||||
return True
|
||||
except OSError:
|
||||
return False
|
||||
|
||||
|
||||
@pytest.fixture(scope='function')
|
||||
def httpbin_with_chunked_support(_httpbin_with_chunked_support_available):
|
||||
if _httpbin_with_chunked_support_available:
|
||||
return HTTPBIN_WITH_CHUNKED_SUPPORT
|
||||
pytest.skip(f'{HTTPBIN_WITH_CHUNKED_SUPPORT_DOMAIN} not resolvable')
|
||||
|
6
tests/fixtures/.editorconfig
vendored
Normal file
6
tests/fixtures/.editorconfig
vendored
Normal file
@ -0,0 +1,6 @@
|
||||
# https://editorconfig.org
|
||||
|
||||
[{*.txt, *.json}]
|
||||
trim_trailing_whitespace = false
|
||||
insert_final_newline = false
|
||||
|
9
tests/fixtures/__init__.py
vendored
9
tests/fixtures/__init__.py
vendored
@ -1,6 +1,8 @@
|
||||
"""Test data"""
|
||||
from pathlib import Path
|
||||
|
||||
from httpie.constants import UTF8
|
||||
|
||||
|
||||
def patharg(path):
|
||||
"""
|
||||
@ -15,6 +17,9 @@ FIXTURES_ROOT = Path(__file__).parent
|
||||
FILE_PATH = FIXTURES_ROOT / 'test.txt'
|
||||
JSON_FILE_PATH = FIXTURES_ROOT / 'test.json'
|
||||
BIN_FILE_PATH = FIXTURES_ROOT / 'test.bin'
|
||||
XML_FILES_PATH = FIXTURES_ROOT / 'xmldata'
|
||||
XML_FILES_VALID = list((XML_FILES_PATH / 'valid').glob('*_raw.xml'))
|
||||
XML_FILES_INVALID = list((XML_FILES_PATH / 'invalid').glob('*.xml'))
|
||||
|
||||
FILE_PATH_ARG = patharg(FILE_PATH)
|
||||
BIN_FILE_PATH_ARG = patharg(BIN_FILE_PATH)
|
||||
@ -23,9 +28,9 @@ JSON_FILE_PATH_ARG = patharg(JSON_FILE_PATH)
|
||||
# Strip because we don't want new lines in the data so that we can
|
||||
# easily count occurrences also when embedded in JSON (where the new
|
||||
# line would be escaped).
|
||||
FILE_CONTENT = FILE_PATH.read_text('utf8').strip()
|
||||
FILE_CONTENT = FILE_PATH.read_text(encoding=UTF8).strip()
|
||||
|
||||
|
||||
JSON_FILE_CONTENT = JSON_FILE_PATH.read_text('utf8')
|
||||
JSON_FILE_CONTENT = JSON_FILE_PATH.read_text(encoding=UTF8)
|
||||
BIN_FILE_CONTENT = BIN_FILE_PATH.read_bytes()
|
||||
UNICODE = FILE_CONTENT
|
||||
|
2
tests/fixtures/test.json
vendored
2
tests/fixtures/test.json
vendored
@ -1,4 +1,4 @@
|
||||
{
|
||||
"name": "Jakub Roztočil",
|
||||
"unicode": "χρυσαφὶ 太陽 เลิศ ♜♞♝♛♚♝♞♜ оживлённым तान्यहानि 有朋"
|
||||
}
|
||||
}
|
2
tests/fixtures/test.txt
vendored
2
tests/fixtures/test.txt
vendored
@ -1 +1 @@
|
||||
[one line of UTF8-encoded unicode text] χρυσαφὶ 太陽 เลิศ ♜♞♝♛♚♝♞♜ оживлённым तान्यहानि 有朋 ஸ்றீனிவாஸ ٱلرَّحْمـَبنِ
|
||||
[one line of UTF8-encoded unicode text] χρυσαφὶ 太陽 เลิศ ♜♞♝♛♚♝♞♜ оживлённым तान्यहानि 有朋 ஸ்றீனிவாஸ ٱلرَّحْمـَبنِ
|
5
tests/fixtures/xmldata/invalid/cyclic.xml
vendored
Normal file
5
tests/fixtures/xmldata/invalid/cyclic.xml
vendored
Normal file
@ -0,0 +1,5 @@
|
||||
<!DOCTYPE xmlbomb [
|
||||
<!ENTITY a "123 &b;" >
|
||||
<!ENTITY b "&a;">
|
||||
]>
|
||||
<bomb>&a;</bomb>
|
4
tests/fixtures/xmldata/invalid/external.xml
vendored
Normal file
4
tests/fixtures/xmldata/invalid/external.xml
vendored
Normal file
@ -0,0 +1,4 @@
|
||||
<!DOCTYPE external [
|
||||
<!ENTITY ee SYSTEM "http://www.w3schools.com/xml/note.xml">
|
||||
]>
|
||||
<root>ⅇ</root>
|
5
tests/fixtures/xmldata/invalid/external_file.xml
vendored
Normal file
5
tests/fixtures/xmldata/invalid/external_file.xml
vendored
Normal file
@ -0,0 +1,5 @@
|
||||
<!DOCTYPE external [
|
||||
<!ENTITY ee SYSTEM "file:///PATH/TO/xmltestdata/simple.xml">
|
||||
]>
|
||||
<root>ⅇ</root>
|
||||
|
1
tests/fixtures/xmldata/invalid/not-xml.xml
vendored
Normal file
1
tests/fixtures/xmldata/invalid/not-xml.xml
vendored
Normal file
@ -0,0 +1 @@
|
||||
some string
|
4
tests/fixtures/xmldata/invalid/quadratic.xml
vendored
Normal file
4
tests/fixtures/xmldata/invalid/quadratic.xml
vendored
Normal file
File diff suppressed because one or more lines are too long
20
tests/fixtures/xmldata/invalid/xalan_exec.xsl
vendored
Normal file
20
tests/fixtures/xmldata/invalid/xalan_exec.xsl
vendored
Normal file
@ -0,0 +1,20 @@
|
||||
<!-- Tested with xalan-j_2_7_1-bin.zip, Xerces-J-bin.2.11.0.tar.gz on
|
||||
OpenJDK 1.7.0_15
|
||||
|
||||
$ LC_ALL=C java -cp xalan.jar:serializer.jar:xercesImpl.jar:xml-apis.jar \
|
||||
org.apache.xalan.xslt.Process -in simple.xml -xsl xalan_exec.xsl
|
||||
-->
|
||||
<xsl:stylesheet version="1.0"
|
||||
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
|
||||
xmlns:rt="http://xml.apache.org/xalan/java/java.lang.Runtime"
|
||||
xmlns:ob="http://xml.apache.org/xalan/java/java.lang.Object"
|
||||
exclude-result-prefixes="rt ob">
|
||||
<xsl:template match="/">
|
||||
<xsl:variable name="runtimeObject" select="rt:getRuntime()"/>
|
||||
<xsl:variable name="command"
|
||||
select="rt:exec($runtimeObject, '/usr/bin/notify-send SomethingBadHappensHere')"/>
|
||||
<xsl:variable name="commandAsString" select="ob:toString($command)"/>
|
||||
<xsl:value-of select="$commandAsString"/>
|
||||
</xsl:template>
|
||||
</xsl:stylesheet>
|
||||
|
18
tests/fixtures/xmldata/invalid/xalan_write.xsl
vendored
Normal file
18
tests/fixtures/xmldata/invalid/xalan_write.xsl
vendored
Normal file
@ -0,0 +1,18 @@
|
||||
<!-- Tested with xalan-j_2_7_1-bin.zip, Xerces-J-bin.2.11.0.tar.gz on
|
||||
OpenJDK 1.7.0_15
|
||||
|
||||
$ LC_ALL=C java -cp xalan.jar:serializer.jar:xercesImpl.jar:xml-apis.jar \
|
||||
org.apache.xalan.xslt.Process -in simple.xml -xsl xalan_write.xsl
|
||||
-->
|
||||
<xsl:stylesheet version="1.0"
|
||||
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
|
||||
xmlns:redirect="http://xml.apache.org/xalan/redirect"
|
||||
extension-element-prefixes="redirect">
|
||||
<xsl:output omit-xml-declaration="yes" indent="yes"/>
|
||||
<xsl:template match="/">
|
||||
<redirect:write file="xalan_redirect.txt" method="text">
|
||||
<xsl:text>Something bad happens here! </xsl:text>
|
||||
</redirect:write>
|
||||
</xsl:template>
|
||||
</xsl:stylesheet>
|
||||
|
7
tests/fixtures/xmldata/invalid/xmlbomb.xml
vendored
Normal file
7
tests/fixtures/xmldata/invalid/xmlbomb.xml
vendored
Normal file
@ -0,0 +1,7 @@
|
||||
<!DOCTYPE xmlbomb [
|
||||
<!ENTITY a "1234567890" >
|
||||
<!ENTITY b "&a;&a;&a;&a;&a;&a;&a;&a;">
|
||||
<!ENTITY c "&b;&b;&b;&b;&b;&b;&b;&b;">
|
||||
<!ENTITY d "&c;&c;&c;&c;&c;&c;&c;&c;">
|
||||
]>
|
||||
<bomb>&c;</bomb>
|
4
tests/fixtures/xmldata/invalid/xmlbomb2.xml
vendored
Normal file
4
tests/fixtures/xmldata/invalid/xmlbomb2.xml
vendored
Normal file
@ -0,0 +1,4 @@
|
||||
<!DOCTYPE xmlbomb [
|
||||
<!ENTITY a "1234567890">
|
||||
]>
|
||||
<root>text<bomb>&a;</bomb><tag/></root>
|
8
tests/fixtures/xmldata/valid/dtd_formatted.xml
vendored
Normal file
8
tests/fixtures/xmldata/valid/dtd_formatted.xml
vendored
Normal file
@ -0,0 +1,8 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!DOCTYPE html
|
||||
PUBLIC '-//W3C//DTD XHTML 1.0 Transitional//EN'
|
||||
'http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd'>
|
||||
<html>
|
||||
<head/>
|
||||
<body>text</body>
|
||||
</html>
|
2
tests/fixtures/xmldata/valid/dtd_raw.xml
vendored
Normal file
2
tests/fixtures/xmldata/valid/dtd_raw.xml
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
<?xml version="1.0" encoding="utf-8"?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
||||
<html><head/><body>text</body></html>
|
9
tests/fixtures/xmldata/valid/simple-ns_formatted.xml
vendored
Normal file
9
tests/fixtures/xmldata/valid/simple-ns_formatted.xml
vendored
Normal file
@ -0,0 +1,9 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<?pi data?>
|
||||
<!-- comment -->
|
||||
<root xmlns="namespace">
|
||||
<element key="value">text</element>
|
||||
<element>text</element>
|
||||
tail
|
||||
<empty-element/>
|
||||
</root>
|
1
tests/fixtures/xmldata/valid/simple-ns_raw.xml
vendored
Normal file
1
tests/fixtures/xmldata/valid/simple-ns_raw.xml
vendored
Normal file
@ -0,0 +1 @@
|
||||
<?pi data?><!-- comment --><root xmlns='namespace'><element key='value'>text</element><element>text</element>tail<empty-element/></root>
|
3
tests/fixtures/xmldata/valid/simple-standalone-no_formatted.xml
vendored
Normal file
3
tests/fixtures/xmldata/valid/simple-standalone-no_formatted.xml
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
<!DOCTYPE s1>
|
||||
<s1>........</s1>
|
2
tests/fixtures/xmldata/valid/simple-standalone-no_raw.xml
vendored
Normal file
2
tests/fixtures/xmldata/valid/simple-standalone-no_raw.xml
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="no"?><!DOCTYPE s1>
|
||||
<s1>........</s1>
|
3
tests/fixtures/xmldata/valid/simple-standalone-yes_formatted.xml
vendored
Normal file
3
tests/fixtures/xmldata/valid/simple-standalone-yes_formatted.xml
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
||||
<!DOCTYPE s1>
|
||||
<s1>........</s1>
|
2
tests/fixtures/xmldata/valid/simple-standalone-yes_raw.xml
vendored
Normal file
2
tests/fixtures/xmldata/valid/simple-standalone-yes_raw.xml
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="yes"?><!DOCTYPE s1>
|
||||
<s1>........</s1>
|
8
tests/fixtures/xmldata/valid/simple_formatted.xml
vendored
Normal file
8
tests/fixtures/xmldata/valid/simple_formatted.xml
vendored
Normal file
@ -0,0 +1,8 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!-- comment -->
|
||||
<root>
|
||||
<element key="value">text</element>
|
||||
<element>text</element>
|
||||
tail
|
||||
<empty-element/>
|
||||
</root>
|
1
tests/fixtures/xmldata/valid/simple_raw.xml
vendored
Normal file
1
tests/fixtures/xmldata/valid/simple_raw.xml
vendored
Normal file
@ -0,0 +1 @@
|
||||
<!-- comment --><root><element key='value'>text</element><element>text</element>tail<empty-element/></root>
|
29
tests/fixtures/xmldata/xhtml/xhtml_formatted.xml
vendored
Normal file
29
tests/fixtures/xmldata/xhtml/xhtml_formatted.xml
vendored
Normal file
@ -0,0 +1,29 @@
|
||||
<!DOCTYPE html
|
||||
PUBLIC '-//W3C//DTD XHTML 1.0 Strict//EN'
|
||||
'http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd'>
|
||||
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
|
||||
<title>XHTML 1.0 Strict Example</title>
|
||||
<script type="text/javascript">
|
||||
//
|
||||
<![CDATA[
|
||||
function loadpdf() {
|
||||
document.getElementById("pdf-object").src="http://www.w3.org/TR/xhtml1/xhtml1.pdf";
|
||||
}
|
||||
//]]>
|
||||
</script>
|
||||
</head>
|
||||
<body onload="loadpdf()">
|
||||
<p>
|
||||
This is an example of an
|
||||
<abbr title="Extensible HyperText Markup Language">XHTML</abbr>
|
||||
1.0 Strict document.
|
||||
<br/>
|
||||
<img id="validation-icon" src="http://www.w3.org/Icons/valid-xhtml10" alt="Valid XHTML 1.0 Strict"/>
|
||||
<br/>
|
||||
<object id="pdf-object" name="pdf-object" type="application/pdf" data="http://www.w3.org/TR/xhtml1/xhtml1.pdf" width="100%" height="500">
|
||||
</object>
|
||||
</p>
|
||||
</body>
|
||||
</html>
|
29
tests/fixtures/xmldata/xhtml/xhtml_formatted_python_less_than_3.8.xml
vendored
Normal file
29
tests/fixtures/xmldata/xhtml/xhtml_formatted_python_less_than_3.8.xml
vendored
Normal file
@ -0,0 +1,29 @@
|
||||
<!DOCTYPE html
|
||||
PUBLIC '-//W3C//DTD XHTML 1.0 Strict//EN'
|
||||
'http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd'>
|
||||
<html lang="en" xml:lang="en" xmlns="http://www.w3.org/1999/xhtml">
|
||||
<head>
|
||||
<meta content="text/html; charset=utf-8" http-equiv="Content-Type"/>
|
||||
<title>XHTML 1.0 Strict Example</title>
|
||||
<script type="text/javascript">
|
||||
//
|
||||
<![CDATA[
|
||||
function loadpdf() {
|
||||
document.getElementById("pdf-object").src="http://www.w3.org/TR/xhtml1/xhtml1.pdf";
|
||||
}
|
||||
//]]>
|
||||
</script>
|
||||
</head>
|
||||
<body onload="loadpdf()">
|
||||
<p>
|
||||
This is an example of an
|
||||
<abbr title="Extensible HyperText Markup Language">XHTML</abbr>
|
||||
1.0 Strict document.
|
||||
<br/>
|
||||
<img alt="Valid XHTML 1.0 Strict" id="validation-icon" src="http://www.w3.org/Icons/valid-xhtml10"/>
|
||||
<br/>
|
||||
<object data="http://www.w3.org/TR/xhtml1/xhtml1.pdf" height="500" id="pdf-object" name="pdf-object" type="application/pdf" width="100%">
|
||||
</object>
|
||||
</p>
|
||||
</body>
|
||||
</html>
|
30
tests/fixtures/xmldata/xhtml/xhtml_raw.xml
vendored
Normal file
30
tests/fixtures/xmldata/xhtml/xhtml_raw.xml
vendored
Normal file
@ -0,0 +1,30 @@
|
||||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
|
||||
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
|
||||
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
|
||||
<title>XHTML 1.0 Strict Example</title>
|
||||
<script type="text/javascript">
|
||||
//<![CDATA[
|
||||
function loadpdf() {
|
||||
document.getElementById("pdf-object").src="http://www.w3.org/TR/xhtml1/xhtml1.pdf";
|
||||
}
|
||||
//]]>
|
||||
</script>
|
||||
</head>
|
||||
<body onload="loadpdf()">
|
||||
<p>This is an example of an
|
||||
<abbr title="Extensible HyperText Markup Language">XHTML</abbr> 1.0 Strict document.<br />
|
||||
<img id="validation-icon"
|
||||
src="http://www.w3.org/Icons/valid-xhtml10"
|
||||
alt="Valid XHTML 1.0 Strict"/><br />
|
||||
<object id="pdf-object"
|
||||
name="pdf-object"
|
||||
type="application/pdf"
|
||||
data="http://www.w3.org/TR/xhtml1/xhtml1.pdf"
|
||||
width="100%"
|
||||
height="500">
|
||||
</object>
|
||||
</p>
|
||||
</body>
|
||||
</html>
|
@ -1,11 +1,11 @@
|
||||
"""HTTP authentication-related tests."""
|
||||
import mock
|
||||
from unittest import mock
|
||||
import pytest
|
||||
|
||||
from httpie.plugins.builtin import HTTPBasicAuth
|
||||
from httpie.status import ExitStatus
|
||||
from httpie.utils import ExplicitNullAuth
|
||||
from utils import http, add_auth, HTTP_OK, MockEnvironment
|
||||
from .utils import http, add_auth, HTTP_OK, MockEnvironment
|
||||
import httpie.cli.constants
|
||||
import httpie.cli.definition
|
||||
|
||||
|
@ -1,9 +1,9 @@
|
||||
from mock import mock
|
||||
from unittest import mock
|
||||
|
||||
from httpie.cli.constants import SEPARATOR_CREDENTIALS
|
||||
from httpie.plugins import AuthPlugin
|
||||
from httpie.plugins.registry import plugin_manager
|
||||
from utils import http, HTTP_OK
|
||||
from .utils import http, HTTP_OK
|
||||
|
||||
|
||||
# TODO: run all these tests in session mode as well
|
||||
@ -13,7 +13,7 @@ PASSWORD = 'password'
|
||||
# Basic auth encoded `USERNAME` and `PASSWORD`
|
||||
# noinspection SpellCheckingInspection
|
||||
BASIC_AUTH_HEADER_VALUE = 'Basic dXNlcjpwYXNzd29yZA=='
|
||||
BASIC_AUTH_URL = '/basic-auth/{0}/{1}'.format(USERNAME, PASSWORD)
|
||||
BASIC_AUTH_URL = f'/basic-auth/{USERNAME}/{PASSWORD}'
|
||||
AUTH_OK = {'authenticated': True, 'user': USERNAME}
|
||||
|
||||
|
||||
|
@ -1,9 +1,9 @@
|
||||
"""Tests for dealing with binary request and response data."""
|
||||
import requests
|
||||
|
||||
from fixtures import BIN_FILE_PATH, BIN_FILE_CONTENT, BIN_FILE_PATH_ARG
|
||||
from .fixtures import BIN_FILE_PATH, BIN_FILE_CONTENT, BIN_FILE_PATH_ARG
|
||||
from httpie.output.streams import BINARY_SUPPRESSED_NOTICE
|
||||
from utils import MockEnvironment, http
|
||||
from .utils import MockEnvironment, http
|
||||
|
||||
|
||||
class TestBinaryRequestData:
|
||||
|
@ -6,7 +6,7 @@ import pytest
|
||||
from requests.exceptions import InvalidSchema
|
||||
|
||||
import httpie.cli.argparser
|
||||
from fixtures import (
|
||||
from .fixtures import (
|
||||
FILE_CONTENT, FILE_PATH, FILE_PATH_ARG, JSON_FILE_CONTENT,
|
||||
JSON_FILE_PATH_ARG,
|
||||
)
|
||||
@ -15,7 +15,7 @@ from httpie.cli import constants
|
||||
from httpie.cli.definition import parser
|
||||
from httpie.cli.argtypes import KeyValueArg, KeyValueArgType
|
||||
from httpie.cli.requestitems import RequestItems
|
||||
from utils import HTTP_OK, MockEnvironment, StdinBytesIO, http
|
||||
from .utils import HTTP_OK, MockEnvironment, StdinBytesIO, http
|
||||
|
||||
|
||||
class TestItemParsing:
|
||||
@ -36,7 +36,7 @@ class TestItemParsing:
|
||||
self.key_value_arg(r'baz\=bar=foo'),
|
||||
|
||||
# files
|
||||
self.key_value_arg(r'bar\@baz@%s' % FILE_PATH_ARG),
|
||||
self.key_value_arg(fr'bar\@baz@{FILE_PATH_ARG}'),
|
||||
])
|
||||
# `requests.structures.CaseInsensitiveDict` => `dict`
|
||||
headers = dict(items.headers._store.values())
|
||||
@ -118,7 +118,7 @@ class TestItemParsing:
|
||||
# Parsed file fields
|
||||
assert 'file' in items.files
|
||||
assert (items.files['file'][1].read().strip().
|
||||
decode('utf8') == FILE_CONTENT)
|
||||
decode() == FILE_CONTENT)
|
||||
|
||||
def test_multiple_file_fields_with_same_field_name(self):
|
||||
items = RequestItems.from_args([
|
||||
@ -148,16 +148,16 @@ class TestQuerystring:
|
||||
path = '/get?a=1&b=2'
|
||||
url = httpbin.url + path
|
||||
assert HTTP_OK in r
|
||||
assert 'GET %s HTTP/1.1' % path in r
|
||||
assert '"url": "%s"' % url in r
|
||||
assert f'GET {path} HTTP/1.1' in r
|
||||
assert f'"url": "{url}"' in r
|
||||
|
||||
def test_query_string_params_items(self, httpbin):
|
||||
r = http('--print=Hhb', 'GET', httpbin.url + '/get', 'a==1')
|
||||
path = '/get?a=1'
|
||||
url = httpbin.url + path
|
||||
assert HTTP_OK in r
|
||||
assert 'GET %s HTTP/1.1' % path in r
|
||||
assert '"url": "%s"' % url in r
|
||||
assert f'GET {path} HTTP/1.1' in r
|
||||
assert f'"url": "{url}"' in r
|
||||
|
||||
def test_query_string_params_in_url_and_items_with_duplicates(self,
|
||||
httpbin):
|
||||
@ -166,8 +166,8 @@ class TestQuerystring:
|
||||
path = '/get?a=1&a=1&a=1&a=1'
|
||||
url = httpbin.url + path
|
||||
assert HTTP_OK in r
|
||||
assert 'GET %s HTTP/1.1' % path in r
|
||||
assert '"url": "%s"' % url in r
|
||||
assert f'GET {path} HTTP/1.1' in r
|
||||
assert f'"url": "{url}"' in r
|
||||
|
||||
|
||||
class TestLocalhostShorthand:
|
||||
@ -347,9 +347,9 @@ class TestSchemes:
|
||||
http('bah', '--default=scheme=foo+bar-BAZ.123')
|
||||
|
||||
def test_default_scheme_option(self, httpbin_secure):
|
||||
url = '{0}:{1}'.format(httpbin_secure.host, httpbin_secure.port)
|
||||
url = f'{httpbin_secure.host}:{httpbin_secure.port}'
|
||||
assert HTTP_OK in http(url, '--default-scheme=https')
|
||||
|
||||
def test_scheme_when_invoked_as_https(self, httpbin_secure):
|
||||
url = '{0}:{1}'.format(httpbin_secure.host, httpbin_secure.port)
|
||||
url = f'{httpbin_secure.host}:{httpbin_secure.port}'
|
||||
assert HTTP_OK in http(url, program_name='https')
|
||||
|
@ -11,9 +11,9 @@ our zlib-encoded request data.
|
||||
import base64
|
||||
import zlib
|
||||
|
||||
from fixtures import FILE_PATH, FILE_CONTENT
|
||||
from .fixtures import FILE_PATH, FILE_CONTENT
|
||||
from httpie.status import ExitStatus
|
||||
from utils import StdinBytesIO, http, HTTP_OK, MockEnvironment
|
||||
from .utils import StdinBytesIO, http, HTTP_OK, MockEnvironment
|
||||
|
||||
|
||||
def assert_decompressed_equal(base64_compressed_data, expected_str):
|
||||
@ -92,6 +92,19 @@ def test_compress_form(httpbin_both):
|
||||
assert '"foo": "bar"' not in r
|
||||
|
||||
|
||||
def test_compress_raw(httpbin_both):
|
||||
r = http(
|
||||
'--raw',
|
||||
FILE_CONTENT,
|
||||
'--compress',
|
||||
'--compress',
|
||||
httpbin_both + '/post',
|
||||
)
|
||||
assert HTTP_OK in r
|
||||
assert r.json['headers']['Content-Encoding'] == 'deflate'
|
||||
assert_decompressed_equal(r.json['data'], FILE_CONTENT.strip())
|
||||
|
||||
|
||||
def test_compress_stdin(httpbin_both):
|
||||
env = MockEnvironment(
|
||||
stdin=StdinBytesIO(FILE_PATH.read_bytes()),
|
||||
|
@ -4,12 +4,13 @@ import pytest
|
||||
from _pytest.monkeypatch import MonkeyPatch
|
||||
|
||||
from httpie.compat import is_windows
|
||||
from httpie.constants import UTF8
|
||||
from httpie.config import (
|
||||
Config, DEFAULT_CONFIG_DIRNAME, DEFAULT_RELATIVE_LEGACY_CONFIG_DIR,
|
||||
DEFAULT_RELATIVE_XDG_CONFIG_HOME, DEFAULT_WINDOWS_CONFIG_DIR,
|
||||
ENV_HTTPIE_CONFIG_DIR, ENV_XDG_CONFIG_HOME, get_default_config_dir,
|
||||
)
|
||||
from utils import HTTP_OK, MockEnvironment, http
|
||||
from .utils import HTTP_OK, MockEnvironment, http
|
||||
|
||||
|
||||
def test_default_options(httpbin):
|
||||
@ -25,8 +26,7 @@ def test_default_options(httpbin):
|
||||
def test_config_file_not_valid(httpbin):
|
||||
env = MockEnvironment()
|
||||
env.create_temp_config_dir()
|
||||
with (env.config_dir / Config.FILENAME).open('w') as f:
|
||||
f.write('{invalid json}')
|
||||
(env.config_dir / Config.FILENAME).write_text('{invalid json}', encoding=UTF8)
|
||||
r = http(httpbin + '/get', env=env)
|
||||
assert HTTP_OK in r
|
||||
assert 'http: warning' in r.stderr
|
||||
|
47
tests/test_cookie.py
Normal file
47
tests/test_cookie.py
Normal file
@ -0,0 +1,47 @@
|
||||
from http.cookies import SimpleCookie
|
||||
from http.server import BaseHTTPRequestHandler, HTTPServer
|
||||
from threading import Thread
|
||||
|
||||
from .utils import http
|
||||
|
||||
|
||||
class TestIntegration:
|
||||
|
||||
def setup_mock_server(self, handler):
|
||||
"""Configure mock server."""
|
||||
# Passing 0 as the port will cause a random free port to be chosen.
|
||||
self.mock_server = HTTPServer(('localhost', 0), handler)
|
||||
_, self.mock_server_port = self.mock_server.server_address
|
||||
|
||||
# Start running mock server in a separate thread.
|
||||
# Daemon threads automatically shut down when the main process exits.
|
||||
self.mock_server_thread = Thread(target=self.mock_server.serve_forever)
|
||||
self.mock_server_thread.setDaemon(True)
|
||||
self.mock_server_thread.start()
|
||||
|
||||
def test_cookie_parser(self):
|
||||
"""Not directly testing HTTPie but `requests` to ensure their cookies handling
|
||||
is still as expected by `get_expired_cookies()`.
|
||||
"""
|
||||
|
||||
class MockServerRequestHandler(BaseHTTPRequestHandler):
|
||||
""""HTTP request handler."""
|
||||
|
||||
def do_GET(self):
|
||||
"""Handle GET requests."""
|
||||
# Craft multiple cookies
|
||||
cookie = SimpleCookie()
|
||||
cookie['hello'] = 'world'
|
||||
cookie['hello']['path'] = self.path
|
||||
cookie['oatmeal_raisin'] = 'is the best'
|
||||
cookie['oatmeal_raisin']['path'] = self.path
|
||||
|
||||
# Send HTTP headers
|
||||
self.send_response(200)
|
||||
self.send_header('Set-Cookie', cookie.output())
|
||||
self.end_headers()
|
||||
|
||||
self.setup_mock_server(MockServerRequestHandler)
|
||||
response = http(f'http://localhost:{self.mock_server_port}/')
|
||||
assert 'Set-Cookie: hello=world; Path=/' in response
|
||||
assert 'Set-Cookie: oatmeal_raisin="is the best"; Path=/' in response
|
@ -5,8 +5,8 @@ Tests for the provided defaults regarding HTTP method, and --json vs. --form.
|
||||
from io import BytesIO
|
||||
|
||||
from httpie.client import JSON_ACCEPT
|
||||
from utils import MockEnvironment, http, HTTP_OK
|
||||
from fixtures import FILE_PATH
|
||||
from .utils import MockEnvironment, http, HTTP_OK
|
||||
from .fixtures import FILE_PATH
|
||||
|
||||
|
||||
def test_default_headers_case_insensitive(httpbin):
|
||||
@ -45,6 +45,11 @@ class TestImplicitHTTPMethod:
|
||||
assert HTTP_OK in r
|
||||
assert r.json['form'] == {'foo': 'bar'}
|
||||
|
||||
def test_implicit_POST_raw(self, httpbin):
|
||||
r = http('--raw', 'foo bar', httpbin.url + '/post')
|
||||
assert HTTP_OK in r
|
||||
assert r.json['data'] == 'foo bar'
|
||||
|
||||
def test_implicit_POST_stdin(self, httpbin):
|
||||
env = MockEnvironment(
|
||||
stdin_isatty=False,
|
||||
|
@ -1,69 +1,35 @@
|
||||
import os
|
||||
import subprocess
|
||||
from glob import glob
|
||||
from pathlib import Path
|
||||
|
||||
import pytest
|
||||
from httpie.compat import is_windows
|
||||
|
||||
from utils import TESTS_ROOT
|
||||
from .utils import TESTS_ROOT
|
||||
|
||||
|
||||
ROOT = TESTS_ROOT.parent
|
||||
SOURCE_DIRECTORIES = [
|
||||
'docs',
|
||||
'extras',
|
||||
'httpie',
|
||||
'tests',
|
||||
]
|
||||
|
||||
|
||||
def has_docutils():
|
||||
try:
|
||||
# noinspection PyUnresolvedReferences,PyPackageRequirements
|
||||
import docutils
|
||||
return True
|
||||
except ImportError:
|
||||
return False
|
||||
def md_filenames():
|
||||
yield from ROOT.glob('*.md')
|
||||
for directory in SOURCE_DIRECTORIES:
|
||||
yield from (ROOT / directory).glob('**/*.md')
|
||||
|
||||
|
||||
def rst_filenames():
|
||||
cwd = os.getcwd()
|
||||
os.chdir(TESTS_ROOT.parent)
|
||||
try:
|
||||
yield from glob('*.rst')
|
||||
for directory in SOURCE_DIRECTORIES:
|
||||
yield from glob(f'{directory}/**/*.rst', recursive=True)
|
||||
finally:
|
||||
os.chdir(cwd)
|
||||
|
||||
|
||||
filenames = list(sorted(rst_filenames()))
|
||||
filenames = sorted(md_filenames())
|
||||
assert filenames
|
||||
|
||||
|
||||
# HACK: hardcoded paths, venv should be irrelevant, etc.
|
||||
# TODO: simplify by using the Python API instead of a subprocess
|
||||
# then we wont’t need the paths.
|
||||
VENV_BIN = Path(__file__).parent.parent / 'venv/bin'
|
||||
VENV_PYTHON = VENV_BIN / 'python'
|
||||
VENV_RST2PSEUDOXML = VENV_BIN / 'rst2pseudoxml.py'
|
||||
|
||||
|
||||
@pytest.mark.skipif(
|
||||
not VENV_RST2PSEUDOXML.exists(),
|
||||
reason='docutils not installed',
|
||||
)
|
||||
@pytest.mark.skipif(is_windows and 'CI' in os.environ,
|
||||
reason='Does not pass on GitHub.')
|
||||
@pytest.mark.parametrize('filename', filenames)
|
||||
def test_rst_file_syntax(filename):
|
||||
p = subprocess.Popen(
|
||||
[
|
||||
VENV_PYTHON,
|
||||
VENV_RST2PSEUDOXML,
|
||||
'--report=1',
|
||||
'--exit-status=1',
|
||||
filename,
|
||||
],
|
||||
stderr=subprocess.PIPE,
|
||||
stdout=subprocess.PIPE,
|
||||
shell=True,
|
||||
)
|
||||
err = p.communicate()[1]
|
||||
assert p.returncode == 0, err.decode('utf8')
|
||||
def test_md_file_syntax(filename):
|
||||
mdformat = pytest.importorskip('mdformat._cli')
|
||||
args = ['--end-of-line', 'lf', '--number']
|
||||
err = f'Running "python -m mdformat {" ".join(args)} {filename}; git diff" should help.'
|
||||
assert mdformat.run(args + ['--check', str(filename)]) == 0, err
|
||||
|
@ -1,17 +1,17 @@
|
||||
import os
|
||||
import tempfile
|
||||
import time
|
||||
from unittest import mock
|
||||
from urllib.request import urlopen
|
||||
|
||||
import pytest
|
||||
import mock
|
||||
from requests.structures import CaseInsensitiveDict
|
||||
|
||||
from httpie.downloads import (
|
||||
parse_content_range, filename_from_content_disposition, filename_from_url,
|
||||
get_unique_filename, ContentRangeError, Downloader,
|
||||
get_unique_filename, ContentRangeError, Downloader, PARTIAL_CONTENT
|
||||
)
|
||||
from utils import http, MockEnvironment
|
||||
from .utils import http, MockEnvironment
|
||||
|
||||
|
||||
class Response:
|
||||
@ -30,6 +30,9 @@ class TestDownloadUtils:
|
||||
assert parse('bytes 100-199/200', 100) == 200
|
||||
assert parse('bytes 100-199/*', 100) == 200
|
||||
|
||||
# single byte
|
||||
assert parse('bytes 100-100/*', 100) == 101
|
||||
|
||||
# missing
|
||||
pytest.raises(ContentRangeError, parse, None, 100)
|
||||
|
||||
@ -45,9 +48,6 @@ class TestDownloadUtils:
|
||||
# invalid byte-range-resp-spec
|
||||
pytest.raises(ContentRangeError, parse, 'bytes 100-99/199', 100)
|
||||
|
||||
# invalid byte-range-resp-spec
|
||||
pytest.raises(ContentRangeError, parse, 'bytes 100-100/*', 100)
|
||||
|
||||
@pytest.mark.parametrize('header, expected_filename', [
|
||||
('attachment; filename=hello-WORLD_123.txt', 'hello-WORLD_123.txt'),
|
||||
('attachment; filename=".hello-WORLD_123.txt"', 'hello-WORLD_123.txt'),
|
||||
@ -66,7 +66,7 @@ class TestDownloadUtils:
|
||||
)
|
||||
assert 'foo.html' == filename_from_url(
|
||||
url='http://example.org/foo',
|
||||
content_type='text/html; charset=utf8'
|
||||
content_type='text/html; charset=UTF-8'
|
||||
)
|
||||
assert 'foo' == filename_from_url(
|
||||
url='http://example.org/foo',
|
||||
@ -120,7 +120,6 @@ class TestDownloadUtils:
|
||||
|
||||
|
||||
class TestDownloads:
|
||||
# TODO: more tests
|
||||
|
||||
def test_actual_download(self, httpbin_both, httpbin):
|
||||
robots_txt = '/robots.txt'
|
||||
@ -163,6 +162,35 @@ class TestDownloads:
|
||||
assert not downloader.interrupted
|
||||
downloader._progress_reporter.join()
|
||||
|
||||
def test_download_output_from_content_disposition(self, httpbin_both):
|
||||
with tempfile.TemporaryDirectory() as tmp_dirname, open(os.devnull, 'w') as devnull:
|
||||
orig_cwd = os.getcwd()
|
||||
os.chdir(tmp_dirname)
|
||||
try:
|
||||
assert not os.path.isfile('filename.bin')
|
||||
downloader = Downloader(progress_file=devnull)
|
||||
downloader.start(
|
||||
final_response=Response(
|
||||
url=httpbin_both.url + '/',
|
||||
headers={
|
||||
'Content-Length': 5,
|
||||
'Content-Disposition': 'attachment; filename="filename.bin"',
|
||||
}
|
||||
),
|
||||
initial_url='/'
|
||||
)
|
||||
downloader.chunk_downloaded(b'12345')
|
||||
downloader.finish()
|
||||
downloader.failed() # Stop the reporter
|
||||
assert not downloader.interrupted
|
||||
downloader._progress_reporter.join()
|
||||
|
||||
# TODO: Auto-close the file in that case?
|
||||
downloader._output_file.close()
|
||||
assert os.path.isfile('filename.bin')
|
||||
finally:
|
||||
os.chdir(orig_cwd)
|
||||
|
||||
def test_download_interrupted(self, httpbin_both):
|
||||
with open(os.devnull, 'w') as devnull:
|
||||
downloader = Downloader(output_file=devnull, progress_file=devnull)
|
||||
@ -178,6 +206,54 @@ class TestDownloads:
|
||||
assert downloader.interrupted
|
||||
downloader._progress_reporter.join()
|
||||
|
||||
def test_download_resumed(self, httpbin_both):
|
||||
with tempfile.TemporaryDirectory() as tmp_dirname:
|
||||
file = os.path.join(tmp_dirname, 'file.bin')
|
||||
with open(file, 'a'):
|
||||
pass
|
||||
|
||||
with open(os.devnull, 'w') as devnull, open(file, 'a+b') as output_file:
|
||||
# Start and interrupt the transfer after 3 bytes written
|
||||
downloader = Downloader(output_file=output_file, progress_file=devnull)
|
||||
downloader.start(
|
||||
final_response=Response(
|
||||
url=httpbin_both.url + '/',
|
||||
headers={'Content-Length': 5}
|
||||
),
|
||||
initial_url='/'
|
||||
)
|
||||
downloader.chunk_downloaded(b'123')
|
||||
downloader.finish()
|
||||
downloader.failed()
|
||||
assert downloader.interrupted
|
||||
downloader._progress_reporter.join()
|
||||
|
||||
# Write bytes
|
||||
with open(file, 'wb') as fh:
|
||||
fh.write(b'123')
|
||||
|
||||
with open(os.devnull, 'w') as devnull, open(file, 'a+b') as output_file:
|
||||
# Resume the transfer
|
||||
downloader = Downloader(output_file=output_file, progress_file=devnull, resume=True)
|
||||
|
||||
# Ensure `pre_request()` is working as expected too
|
||||
headers = {}
|
||||
downloader.pre_request(headers)
|
||||
assert headers['Accept-Encoding'] == 'identity'
|
||||
assert headers['Range'] == 'bytes=3-'
|
||||
|
||||
downloader.start(
|
||||
final_response=Response(
|
||||
url=httpbin_both.url + '/',
|
||||
headers={'Content-Length': 5, 'Content-Range': 'bytes 3-4/5'},
|
||||
status_code=PARTIAL_CONTENT
|
||||
),
|
||||
initial_url='/'
|
||||
)
|
||||
downloader.chunk_downloaded(b'45')
|
||||
downloader.finish()
|
||||
downloader._progress_reporter.join()
|
||||
|
||||
def test_download_with_redirect_original_url_used_for_filename(self, httpbin):
|
||||
# Redirect from `/redirect/1` to `/get`.
|
||||
expected_filename = '1.json'
|
||||
|
@ -1,10 +1,10 @@
|
||||
import mock
|
||||
from unittest import mock
|
||||
from pytest import raises
|
||||
from requests import Request
|
||||
from requests.exceptions import ConnectionError
|
||||
|
||||
from httpie.status import ExitStatus
|
||||
from utils import HTTP_OK, http
|
||||
from .utils import HTTP_OK, http
|
||||
|
||||
|
||||
@mock.patch('httpie.core.program')
|
||||
|
@ -1,7 +1,7 @@
|
||||
import mock
|
||||
from unittest import mock
|
||||
|
||||
from httpie.status import ExitStatus
|
||||
from utils import MockEnvironment, http, HTTP_OK
|
||||
from .utils import MockEnvironment, http, HTTP_OK
|
||||
|
||||
|
||||
def test_keyboard_interrupt_during_arg_parsing_exit_status(httpbin):
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user