mirror of
https://github.com/httpie/cli.git
synced 2025-08-13 16:27:10 +02:00
Compare commits
241 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 | |||
bb36897054 | |||
173e622567 | |||
3426030370 | |||
d014498713 | |||
5414d1853e | |||
1ac8f69651 | |||
3c07a25326 | |||
cf78a12e46 | |||
0f1e098cc4 | |||
0401d7b31c | |||
795627f965 | |||
21cc008cb2 | |||
77b8c37cb0 | |||
db685d58b5 | |||
44ae67685d | |||
6922a0c912 | |||
2afdc958c6 | |||
57b1baf1d1 | |||
1828da6a50 | |||
0629f2ff42 | |||
d71b7eee81 | |||
9883a46575 | |||
2409077a6d | |||
02971b938d | |||
f7e77efe4b | |||
5d8bd0da7c | |||
3c6e7c73fe | |||
d64c0ee415 | |||
311a5ede70 | |||
f64c90010f | |||
8456ddb27c | |||
cf254680b7 | |||
42c4a7596b | |||
1573058811 | |||
51bc8fb2c6 | |||
a69d6f44fd | |||
507cd6e255 | |||
759e4400d0 | |||
8cb1af7376 | |||
2f8d330b57 | |||
32d8b481e9 | |||
75f1e02215 | |||
70ba84dc48 | |||
5a5b42340f | |||
299250b3c3 | |||
6925d930da | |||
c1948f8340 | |||
b80ba040ac | |||
b7754f92ce | |||
e4e40e5b06 | |||
d12af4a569 | |||
c431ed7728 | |||
16ef08a159 | |||
100872b5cf | |||
664cebfbcc | |||
743f9738a3 | |||
69445c106c | |||
1813cf6156 | |||
a23b0e39e5 | |||
06dec4e6c6 | |||
ce185bd0fa | |||
1e1dbfeba0 | |||
5a908aa411 | |||
6cd934d1b8 | |||
d32c8cab12 | |||
5ce7c190e9 | |||
1aa1366f99 | |||
2c7f24e3e5 | |||
c90d039a0b | |||
ae22d4e754 | |||
69e1067a2c | |||
7e38f9ccf0 | |||
d546081340 | |||
6421c145d9 | |||
61e7cd786e | |||
4bd2e622a5 | |||
a4a1e8d43b | |||
ebf2139fd5 | |||
6c84cebed4 | |||
10246366da | |||
a448b0d928 | |||
0541490dda | |||
3704db9b6d | |||
d1665b08d2 | |||
1a4e0c2646 | |||
0d480139e4 | |||
9931747901 | |||
8891afa3b7 | |||
4f493d51f8 | |||
cf937b6b79 | |||
14677bd25d | |||
49e71d252f | |||
d6f25b1017 | |||
a434cddd42 | |||
55d7af86fd | |||
978aace86c | |||
ecdeffe7c8 | |||
9500ce136a | |||
93d07cfe57 | |||
5945845420 | |||
3ee5b49256 | |||
bb024757b6 | |||
d35864e79d | |||
8a106781be | |||
23dd80563f | |||
2bab69d9fb | |||
826489950d | |||
b86598886e | |||
c240162cab | |||
26e29612f2 | |||
37200eb055 | |||
9c68d7dd87 | |||
7ee519ef46 | |||
c4627cc882 | |||
492687b0da | |||
caeef2fb7c | |||
aae596d472 | |||
cb51faec51 | |||
c2a0cef76e | |||
493e98c833 | |||
ca02e51420 | |||
cd085cbc0d | |||
27d57ce773 | |||
4c4efff56a | |||
a53505f26e | |||
165dc36f8d | |||
5df3a91619 | |||
7dbceafc01 | |||
d62d6a77d1 | |||
0a81facccf | |||
3e20ade645 | |||
0c47094109 | |||
defe4bc76d | |||
afee6a7970 | |||
7b676dd583 | |||
5af0874ed3 | |||
e11a2d1346 | |||
b2044fc18d | |||
d9a2d665ad | |||
e83e275dff | |||
4a99495466 | |||
495f67229a | |||
45b9bae3dc | |||
774ff148cd |
12
.github/FUNDING.yml
vendored
12
.github/FUNDING.yml
vendored
@ -1,12 +0,0 @@
|
|||||||
# These are supported funding model platforms
|
|
||||||
|
|
||||||
github: # Replace with up to 4 GitHub Sponsors-enabled usernames e.g., [user1, user2]
|
|
||||||
patreon: # Replace with a single Patreon username
|
|
||||||
open_collective: # Replace with a single Open Collective username
|
|
||||||
ko_fi: # Replace with a single Ko-fi username
|
|
||||||
tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel
|
|
||||||
community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry
|
|
||||||
liberapay: # Replace with a single Liberapay username
|
|
||||||
issuehunt: # Replace with a single IssueHunt username
|
|
||||||
otechie: # Replace with a single Otechie username
|
|
||||||
custom: https://paypal.me/roztocil
|
|
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
|
26
.github/workflows/build.yml
vendored
26
.github/workflows/build.yml
vendored
@ -5,13 +5,13 @@ jobs:
|
|||||||
# Run coverage and extra tests only once
|
# Run coverage and extra tests only once
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v1
|
- uses: actions/checkout@v2
|
||||||
- uses: actions/setup-python@v1
|
- uses: actions/setup-python@v2
|
||||||
with:
|
with:
|
||||||
python-version: 3.8
|
python-version: 3.9
|
||||||
- run: pip install --upgrade pip
|
- run: python -m pip install --upgrade pip setuptools wheel
|
||||||
- run: make install
|
- run: make install
|
||||||
- run: make pycodestyle
|
- run: make codestyle
|
||||||
- run: make test-cover
|
- run: make test-cover
|
||||||
- run: make codecov-upload
|
- run: make codecov-upload
|
||||||
env:
|
env:
|
||||||
@ -21,17 +21,15 @@ jobs:
|
|||||||
# Run core HTTPie tests everywhere
|
# Run core HTTPie tests everywhere
|
||||||
runs-on: ${{ matrix.os }}
|
runs-on: ${{ matrix.os }}
|
||||||
strategy:
|
strategy:
|
||||||
|
fail-fast: false
|
||||||
matrix:
|
matrix:
|
||||||
os: [ubuntu-latest, macOS-latest, windows-latest]
|
os: [ubuntu-latest, macOS-latest, windows-latest]
|
||||||
python-version: [3.6, 3.7, 3.8]
|
python-version: [3.6, 3.7, 3.8, 3.9, "3.10.0-rc.1"]
|
||||||
exclude:
|
|
||||||
- os: windows-latest
|
|
||||||
python-version: 3.8
|
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v1
|
- uses: actions/checkout@v2
|
||||||
- uses: actions/setup-python@v1
|
- uses: actions/setup-python@v2
|
||||||
with:
|
with:
|
||||||
python-version: ${{ matrix.python-version }}
|
python-version: ${{ matrix.python-version }}
|
||||||
- run: python -m pip install --upgrade pip
|
- run: python -m pip install --upgrade pip setuptools wheel
|
||||||
- run: pip install --upgrade --editable .
|
- run: python -m pip install --upgrade '.[dev]'
|
||||||
- run: python setup.py test
|
- run: python -m pytest --verbose ./httpie ./tests
|
||||||
|
8
.gitignore
vendored
8
.gitignore
vendored
@ -7,7 +7,7 @@ htmlcov
|
|||||||
|
|
||||||
|
|
||||||
##############################################################################
|
##############################################################################
|
||||||
# The bellow is GitHub template for Python project. gitignore.
|
# The below is GitHub template for Python project. gitignore.
|
||||||
# <https://github.com/github/gitignore/blob/master/Python.gitignore>
|
# <https://github.com/github/gitignore/blob/master/Python.gitignore>
|
||||||
##############################################################################
|
##############################################################################
|
||||||
|
|
||||||
@ -52,7 +52,6 @@ pip-delete-this-directory.txt
|
|||||||
|
|
||||||
# Unit test / coverage reports
|
# Unit test / coverage reports
|
||||||
htmlcov/
|
htmlcov/
|
||||||
.tox/
|
|
||||||
.nox/
|
.nox/
|
||||||
.coverage
|
.coverage
|
||||||
.coverage.*
|
.coverage.*
|
||||||
@ -140,3 +139,8 @@ dmypy.json
|
|||||||
|
|
||||||
# Pyre type checker
|
# Pyre type checker
|
||||||
.pyre/
|
.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)
|
42
AUTHORS.rst
42
AUTHORS.rst
@ -1,42 +0,0 @@
|
|||||||
==============
|
|
||||||
HTTPie authors
|
|
||||||
==============
|
|
||||||
|
|
||||||
* `Jakub Roztocil <https://github.com/jakubroztocil>`_
|
|
||||||
|
|
||||||
|
|
||||||
Patches and ideas
|
|
||||||
-----------------
|
|
||||||
|
|
||||||
`Complete list of contributors on GitHub <https://github.com/jakubroztocil/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>`_
|
|
||||||
|
|
||||||
|
|
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
|
429
CHANGELOG.rst
429
CHANGELOG.rst
@ -1,429 +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.1.0`_ (2020-04-18)
|
|
||||||
---------------------
|
|
||||||
|
|
||||||
* Added ``--path-as-is`` to bypass dot segment (``/../`` or ``/./``)
|
|
||||||
URL squashing (#895).
|
|
||||||
* Changed the default value ``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/jakubroztocil/httpie/commit/b966efa
|
|
||||||
.. _0.1.4: https://github.com/jakubroztocil/httpie/compare/b966efa...0.1.4
|
|
||||||
.. _0.1.5: https://github.com/jakubroztocil/httpie/compare/0.1.4...0.1.5
|
|
||||||
.. _0.1.6: https://github.com/jakubroztocil/httpie/compare/0.1.5...0.1.6
|
|
||||||
.. _0.2.0: https://github.com/jakubroztocil/httpie/compare/0.1.6...0.2.0
|
|
||||||
.. _0.2.1: https://github.com/jakubroztocil/httpie/compare/0.2.0...0.2.1
|
|
||||||
.. _0.2.2: https://github.com/jakubroztocil/httpie/compare/0.2.1...0.2.2
|
|
||||||
.. _0.2.5: https://github.com/jakubroztocil/httpie/compare/0.2.2...0.2.5
|
|
||||||
.. _0.2.6: https://github.com/jakubroztocil/httpie/compare/0.2.5...0.2.6
|
|
||||||
.. _0.2.7: https://github.com/jakubroztocil/httpie/compare/0.2.5...0.2.7
|
|
||||||
.. _0.3.0: https://github.com/jakubroztocil/httpie/compare/0.2.7...0.3.0
|
|
||||||
.. _0.4.0: https://github.com/jakubroztocil/httpie/compare/0.3.0...0.4.0
|
|
||||||
.. _0.4.1: https://github.com/jakubroztocil/httpie/compare/0.4.0...0.4.1
|
|
||||||
.. _0.5.0: https://github.com/jakubroztocil/httpie/compare/0.4.1...0.5.0
|
|
||||||
.. _0.5.1: https://github.com/jakubroztocil/httpie/compare/0.5.0...0.5.1
|
|
||||||
.. _0.6.0: https://github.com/jakubroztocil/httpie/compare/0.5.1...0.6.0
|
|
||||||
.. _0.7.1: https://github.com/jakubroztocil/httpie/compare/0.6.0...0.7.1
|
|
||||||
.. _0.8.0: https://github.com/jakubroztocil/httpie/compare/0.7.1...0.8.0
|
|
||||||
.. _0.9.0: https://github.com/jakubroztocil/httpie/compare/0.8.0...0.9.0
|
|
||||||
.. _0.9.1: https://github.com/jakubroztocil/httpie/compare/0.9.0...0.9.1
|
|
||||||
.. _0.9.2: https://github.com/jakubroztocil/httpie/compare/0.9.1...0.9.2
|
|
||||||
.. _0.9.3: https://github.com/jakubroztocil/httpie/compare/0.9.2...0.9.3
|
|
||||||
.. _0.9.4: https://github.com/jakubroztocil/httpie/compare/0.9.3...0.9.4
|
|
||||||
.. _0.9.6: https://github.com/jakubroztocil/httpie/compare/0.9.4...0.9.6
|
|
||||||
.. _0.9.8: https://github.com/jakubroztocil/httpie/compare/0.9.6...0.9.8
|
|
||||||
.. _0.9.9: https://github.com/jakubroztocil/httpie/compare/0.9.8...0.9.9
|
|
||||||
.. _1.0.0: https://github.com/jakubroztocil/httpie/compare/0.9.9...1.0.0
|
|
||||||
.. _1.0.1: https://github.com/jakubroztocil/httpie/compare/1.0.0...1.0.1
|
|
||||||
.. _1.0.2: https://github.com/jakubroztocil/httpie/compare/1.0.1...1.0.2
|
|
||||||
.. _1.0.3: https://github.com/jakubroztocil/httpie/compare/1.0.2...1.0.3
|
|
||||||
.. _2.0.0: https://github.com/jakubroztocil/httpie/compare/1.0.3...2.0.0
|
|
||||||
.. _2.1.0: https://github.com/jakubroztocil/httpie/compare/2.0.0...2.1.0
|
|
||||||
|
|
||||||
|
|
||||||
.. _#488:https://github.com/jakubroztocil/httpie/issues/488
|
|
||||||
.. _#840:https://github.com/jakubroztocil/httpie/issues/840
|
|
||||||
.. _#895:https://github.com/jakubroztocil/httpie/issues/895
|
|
@ -14,22 +14,22 @@ appearance, race, religion, or sexual identity and orientation.
|
|||||||
Examples of behavior that contributes to creating a positive environment
|
Examples of behavior that contributes to creating a positive environment
|
||||||
include:
|
include:
|
||||||
|
|
||||||
* Using welcoming and inclusive language
|
- Using welcoming and inclusive language
|
||||||
* Being respectful of differing viewpoints and experiences
|
- Being respectful of differing viewpoints and experiences
|
||||||
* Gracefully accepting constructive criticism
|
- Gracefully accepting constructive criticism
|
||||||
* Focusing on what is best for the community
|
- Focusing on what is best for the community
|
||||||
* Showing empathy towards other community members
|
- Showing empathy towards other community members
|
||||||
|
|
||||||
Examples of unacceptable behavior by participants include:
|
Examples of unacceptable behavior by participants include:
|
||||||
|
|
||||||
* The use of sexualized language or imagery and unwelcome sexual attention or
|
- The use of sexualized language or imagery and unwelcome sexual attention or
|
||||||
advances
|
advances
|
||||||
* Trolling, insulting/derogatory comments, and personal or political attacks
|
- Trolling, insulting/derogatory comments, and personal or political attacks
|
||||||
* Public or private harassment
|
- Public or private harassment
|
||||||
* Publishing others' private information, such as a physical or electronic
|
- Publishing others' private information, such as a physical or electronic
|
||||||
address, without explicit permission
|
address, without explicit permission
|
||||||
* Other conduct which could reasonably be considered inappropriate in a
|
- Other conduct which could reasonably be considered inappropriate in a
|
||||||
professional setting
|
professional setting
|
||||||
|
|
||||||
## Our Responsibilities
|
## Our Responsibilities
|
||||||
|
|
||||||
@ -67,10 +67,8 @@ members of the project's leadership.
|
|||||||
|
|
||||||
## Attribution
|
## Attribution
|
||||||
|
|
||||||
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
|
This Code of Conduct is adapted from the [Contributor Covenant](https://www.contributor-covenant.org),
|
||||||
available at https://www.contributor-covenant.org/version/1/4/code-of-conduct.html
|
version 1.4, available at https://www.contributor-covenant.org/version/1/4/code-of-conduct.html
|
||||||
|
|
||||||
[homepage]: https://www.contributor-covenant.org
|
|
||||||
|
|
||||||
For answers to common questions about this code of conduct, see
|
For answers to common questions about this code of conduct, see
|
||||||
https://www.contributor-covenant.org/faq
|
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)!
|
183
CONTRIBUTING.rst
183
CONTRIBUTING.rst
@ -1,183 +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 been previously discussed. If the change in question
|
|
||||||
is a bigger one, it's always good to discuss before you start working on
|
|
||||||
it.
|
|
||||||
|
|
||||||
|
|
||||||
Development Environment
|
|
||||||
--------------------------------
|
|
||||||
|
|
||||||
|
|
||||||
Getting the code
|
|
||||||
****************
|
|
||||||
|
|
||||||
Go to https://github.com/jakubroztocil/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`` should point to you 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/jakubroztocil/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. It also uses `Tox`_ which allows you to run
|
|
||||||
tests on multiple Python versions even when testing locally.
|
|
||||||
|
|
||||||
|
|
||||||
.. code-block:: bash
|
|
||||||
|
|
||||||
# Run tests on the current Python interpreter with coverage.
|
|
||||||
make test
|
|
||||||
|
|
||||||
# Run tests with coverage
|
|
||||||
make test-cover
|
|
||||||
|
|
||||||
# Run all tests in all of the supported and available Pythons via Tox
|
|
||||||
make test-tox
|
|
||||||
|
|
||||||
# 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
|
|
||||||
|
|
||||||
# Run specific tests on the on all Pythons via Tox
|
|
||||||
# (change to `tox -e py37' to limit Python version)
|
|
||||||
tox -- tests/test_uploads.py --verbose
|
|
||||||
tox -- tests/test_uploads.py::TestMultipartFormDataFileUpload --verbose
|
|
||||||
tox -- tests/test_uploads.py::TestMultipartFormDataFileUpload::test_upload_ok --verbose
|
|
||||||
|
|
||||||
-----
|
|
||||||
|
|
||||||
See `Makefile`_ for additional development utilities.
|
|
||||||
|
|
||||||
|
|
||||||
Finally, don't forget to add yourself to `AUTHORS`_!
|
|
||||||
|
|
||||||
|
|
||||||
.. _Tox: http://tox.testrun.org
|
|
||||||
.. _supported Python environments: https://github.com/jakubroztocil/httpie/blob/master/tox.ini
|
|
||||||
.. _existing issues: https://github.com/jakubroztocil/httpie/issues?state=open
|
|
||||||
.. _AUTHORS: https://github.com/jakubroztocil/httpie/blob/master/AUTHORS.rst
|
|
||||||
.. _Makefile: https://github.com/jakubroztocil/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/jakubroztocil/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
|
Redistribution and use in source and binary forms, with or without
|
||||||
modification, are permitted provided that the following conditions are met:
|
modification, are permitted provided that the following conditions are met:
|
||||||
|
@ -1,7 +1,8 @@
|
|||||||
include LICENSE
|
include LICENSE
|
||||||
include README.rst
|
include README.md
|
||||||
include CHANGELOG.rst
|
include CHANGELOG.md
|
||||||
include AUTHORS.rst
|
include AUTHORS.md
|
||||||
|
include docs/README.md
|
||||||
|
|
||||||
# <https://github.com/jakubroztocil/httpie/issues/182>
|
# <https://github.com/httpie/httpie/issues/182>
|
||||||
recursive-include tests/ *
|
recursive-include tests/ *
|
||||||
|
60
Makefile
60
Makefile
@ -1,10 +1,11 @@
|
|||||||
###############################################################################
|
###############################################################################
|
||||||
# See ./CONTRIBUTING.rst
|
# See ./CONTRIBUTING.md
|
||||||
###############################################################################
|
###############################################################################
|
||||||
|
|
||||||
|
.PHONY: build
|
||||||
|
|
||||||
ROOT_DIR:=$(shell dirname $(realpath $(firstword $(MAKEFILE_LIST))))
|
ROOT_DIR:=$(shell dirname $(realpath $(firstword $(MAKEFILE_LIST))))
|
||||||
VERSION=$(shell grep __version__ httpie/__init__.py)
|
VERSION=$(shell grep __version__ httpie/__init__.py)
|
||||||
REQUIREMENTS=requirements-dev.txt
|
|
||||||
H1="\n\n\033[0;32m\#\#\# "
|
H1="\n\n\033[0;32m\#\#\# "
|
||||||
H1END=" \#\#\# \033[0m\n"
|
H1END=" \#\#\# \033[0m\n"
|
||||||
|
|
||||||
@ -26,7 +27,7 @@ all: uninstall-httpie install test
|
|||||||
|
|
||||||
install: venv
|
install: venv
|
||||||
@echo $(H1)Installing dev requirements$(H1END)
|
@echo $(H1)Installing dev requirements$(H1END)
|
||||||
$(VENV_PIP) install --upgrade -r $(REQUIREMENTS)
|
$(VENV_PIP) install --upgrade --editable '.[dev]'
|
||||||
|
|
||||||
@echo $(H1)Installing HTTPie$(H1END)
|
@echo $(H1)Installing HTTPie$(H1END)
|
||||||
$(VENV_PIP) install --upgrade --editable .
|
$(VENV_PIP) install --upgrade --editable .
|
||||||
@ -38,7 +39,7 @@ clean:
|
|||||||
rm -rf $(VENV_ROOT)
|
rm -rf $(VENV_ROOT)
|
||||||
# Remove symlink for virtualenvwrapper, if we’ve created one.
|
# Remove symlink for virtualenvwrapper, if we’ve created one.
|
||||||
[ -n "$(WORKON_HOME)" -a -L "$(WORKON_HOME)/httpie" -a -f "$(WORKON_HOME)/httpie" ] && rm $(WORKON_HOME)/httpie || true
|
[ -n "$(WORKON_HOME)" -a -L "$(WORKON_HOME)/httpie" -a -f "$(WORKON_HOME)/httpie" ] && rm $(WORKON_HOME)/httpie || true
|
||||||
rm -rf .tox *.egg dist build .coverage .cache .pytest_cache httpie.egg-info
|
rm -rf *.egg dist build .coverage .cache .pytest_cache httpie.egg-info
|
||||||
find . -name '__pycache__' -delete -o -name '*.pyc' -delete
|
find . -name '__pycache__' -delete -o -name '*.pyc' -delete
|
||||||
@echo
|
@echo
|
||||||
|
|
||||||
@ -76,7 +77,7 @@ venv:
|
|||||||
|
|
||||||
test:
|
test:
|
||||||
@echo $(H1)Running tests$(HEADER_EXTRA)$(H1END)
|
@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
|
@echo
|
||||||
|
|
||||||
|
|
||||||
@ -86,7 +87,7 @@ test-cover: test
|
|||||||
|
|
||||||
|
|
||||||
# test-all is meant to test everything — even this Makefile
|
# test-all is meant to test everything — even this Makefile
|
||||||
test-all: clean install test test-tox test-dist pycodestyle
|
test-all: clean install test test-dist codestyle
|
||||||
@echo
|
@echo
|
||||||
|
|
||||||
|
|
||||||
@ -94,12 +95,6 @@ test-dist: test-sdist test-bdist-wheel
|
|||||||
@echo
|
@echo
|
||||||
|
|
||||||
|
|
||||||
test-tox: uninstall-httpie install
|
|
||||||
@echo $(H1)Running tests on all Pythons via Tox$(H1END)
|
|
||||||
$(VENV_BIN)/tox
|
|
||||||
@echo
|
|
||||||
|
|
||||||
|
|
||||||
test-sdist: clean venv
|
test-sdist: clean venv
|
||||||
@echo $(H1)Testing sdist build an installation$(H1END)
|
@echo $(H1)Testing sdist build an installation$(H1END)
|
||||||
$(VENV_PYTHON) setup.py sdist
|
$(VENV_PYTHON) setup.py sdist
|
||||||
@ -117,10 +112,18 @@ test-bdist-wheel: clean venv
|
|||||||
@echo
|
@echo
|
||||||
|
|
||||||
|
|
||||||
pycodestyle:
|
twine-check:
|
||||||
@echo $(H1)Running pycodestyle$(H1END)
|
twine check dist/*
|
||||||
@[ -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
|
@echo
|
||||||
|
|
||||||
|
|
||||||
@ -137,6 +140,11 @@ codecov-upload:
|
|||||||
###############################################################################
|
###############################################################################
|
||||||
|
|
||||||
|
|
||||||
|
build:
|
||||||
|
rm -rf build/
|
||||||
|
$(VENV_PYTHON) setup.py sdist bdist_wheel
|
||||||
|
|
||||||
|
|
||||||
publish: test-all publish-no-test
|
publish: test-all publish-no-test
|
||||||
|
|
||||||
|
|
||||||
@ -144,8 +152,9 @@ publish-no-test:
|
|||||||
@echo $(H1)Testing wheel build an installation$(H1END)
|
@echo $(H1)Testing wheel build an installation$(H1END)
|
||||||
@echo "$(VERSION)"
|
@echo "$(VERSION)"
|
||||||
@echo "$(VERSION)" | grep -q "dev" && echo '!!!Not publishing dev version!!!' && exit 1 || echo ok
|
@echo "$(VERSION)" | grep -q "dev" && echo '!!!Not publishing dev version!!!' && exit 1 || echo ok
|
||||||
$(VENV_PYTHON) setup.py sdist bdist_wheel
|
make build
|
||||||
$(VENV_BIN)/twine upload dist/*
|
make twine-check
|
||||||
|
$(VENV_BIN)/twine upload --repository=httpie dist/*
|
||||||
@echo
|
@echo
|
||||||
|
|
||||||
|
|
||||||
@ -165,21 +174,6 @@ uninstall-httpie:
|
|||||||
@echo
|
@echo
|
||||||
|
|
||||||
|
|
||||||
###############################################################################
|
|
||||||
# Docs
|
|
||||||
###############################################################################
|
|
||||||
|
|
||||||
pdf:
|
|
||||||
# NOTE: rst2pdf needs to be installed manually and against a Python 2
|
|
||||||
@echo "Converting README.rst to PDF…"
|
|
||||||
rst2pdf \
|
|
||||||
--strip-elements-with-class=no-pdf \
|
|
||||||
README.rst \
|
|
||||||
-o README.pdf
|
|
||||||
@echo "Done"
|
|
||||||
@echo
|
|
||||||
|
|
||||||
|
|
||||||
###############################################################################
|
###############################################################################
|
||||||
# Homebrew
|
# 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)
|
1960
README.rst
1960
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,23 +12,39 @@ import hashlib
|
|||||||
import requests
|
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 = [
|
PACKAGES = [
|
||||||
'httpie',
|
'httpie',
|
||||||
'Pygments',
|
'Pygments',
|
||||||
'requests',
|
'requests',
|
||||||
|
'requests-toolbelt',
|
||||||
'certifi',
|
'certifi',
|
||||||
'urllib3',
|
'urllib3',
|
||||||
'idna',
|
'idna',
|
||||||
'chardet',
|
'chardet',
|
||||||
'PySocks',
|
'PySocks',
|
||||||
|
'defusedxml',
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
def get_package_meta(package_name):
|
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()
|
resp = requests.get(api_url).json()
|
||||||
hasher = hashlib.sha256()
|
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']
|
download_url = release['url']
|
||||||
if download_url.endswith('.tar.gz'):
|
if download_url.endswith('.tar.gz'):
|
||||||
hasher.update(requests.get(download_url).content)
|
hasher.update(requests.get(download_url).content)
|
||||||
|
@ -1,11 +1,8 @@
|
|||||||
#!/usr/bin/env bash
|
|
||||||
|
|
||||||
|
|
||||||
_http_complete() {
|
_http_complete() {
|
||||||
local cur_word=${COMP_WORDS[COMP_CWORD]}
|
local cur_word=${COMP_WORDS[COMP_CWORD]}
|
||||||
local prev_word=${COMP_WORDS[COMP_CWORD - 1]}
|
local prev_word=${COMP_WORDS[COMP_CWORD - 1]}
|
||||||
|
|
||||||
if [[ "$cur_word" == -* ]]; then
|
if [[ "$cur_word" == -* ]]; then
|
||||||
_http_complete_options "$cur_word"
|
_http_complete_options "$cur_word"
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
@ -18,6 +15,6 @@ _http_complete_options() {
|
|||||||
-v --verbose -h --headers -b --body -S --stream -o --output -d --download
|
-v --verbose -h --headers -b --body -S --stream -o --output -d --download
|
||||||
-c --continue --session --session-read-only -a --auth --auth-type --proxy
|
-c --continue --session --session-read-only -a --auth --auth-type --proxy
|
||||||
--follow --verify --cert --cert-key --timeout --check-status --ignore-stdin
|
--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" ) )
|
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
|
function __fish_httpie_styles
|
||||||
echo "autumn"
|
echo "
|
||||||
echo "borland"
|
abap
|
||||||
echo "bw"
|
algol
|
||||||
echo "colorful"
|
algol_nu
|
||||||
echo "default"
|
arduino
|
||||||
echo "emacs"
|
auto
|
||||||
echo "friendly"
|
autumn
|
||||||
echo "fruity"
|
borland
|
||||||
echo "igor"
|
bw
|
||||||
echo "manni"
|
colorful
|
||||||
echo "monokai"
|
default
|
||||||
echo "murphy"
|
emacs
|
||||||
echo "native"
|
friendly
|
||||||
echo "paraiso-dark"
|
fruity
|
||||||
echo "paraiso-light"
|
gruvbox-dark
|
||||||
echo "pastie"
|
gruvbox-light
|
||||||
echo "perldoc"
|
igor
|
||||||
echo "rrt"
|
inkpot
|
||||||
echo "solarized"
|
lovelace
|
||||||
echo "tango"
|
manni
|
||||||
echo "trac"
|
material
|
||||||
echo "vim"
|
monokai
|
||||||
echo "vs"
|
murphy
|
||||||
echo "xcode"
|
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
|
end
|
||||||
|
|
||||||
complete -x -c http -s s -l style -d 'Output coloring style (default is "monokai")' -A -a '(__fish_httpie_styles)'
|
function __fish_httpie_auth_types
|
||||||
complete -c http -s f -l form -d 'Data items from the command line are serialized as form fields'
|
echo -e "basic\tBasic HTTP auth"
|
||||||
complete -c http -s j -l json -d '(default) Data items from the command line are serialized as a JSON object'
|
echo -e "digest\tDigest HTTP auth"
|
||||||
complete -x -c http -l pretty -d 'Controls output processing' -a "all colors format none" -A
|
end
|
||||||
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'
|
function __fish_http_verify_options
|
||||||
complete -c http -s h -l headers -d 'Print only the response headers'
|
echo -e "yes\tEnable cert verification"
|
||||||
complete -c http -s b -l body -d 'Print only the response body'
|
echo -e "no\tDisable cert verification"
|
||||||
complete -c http -s S -l stream -d 'Always stream the output by line'
|
end
|
||||||
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'
|
# Predefined Content Types
|
||||||
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 -c http -s j -l json -d 'Data items are serialized as a JSON object'
|
||||||
complete -x -c http -s a -l auth -d 'If only the username is provided (-a username), HTTPie will prompt for the password'
|
complete -c http -s f -l form -d 'Data items are serialized as form fields'
|
||||||
complete -x -c http -l auth-type -d 'The authentication mechanism to be used' -a '(__fish_httpie_auth_types)' -A
|
complete -c http -l multipart -d 'Always sends a multipart/form-data request'
|
||||||
complete -x -c http -l proxy -d 'String mapping protocol to the URL of the proxy'
|
complete -c http -l boundary -x -d 'Custom boundary string for multipart/form-data requests'
|
||||||
complete -c http -l follow -d 'Allow full redirects'
|
complete -c http -l raw -x -d 'Pass raw request data without extra processing'
|
||||||
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'
|
# Content Processing Options
|
||||||
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 -s x -l compress -d 'Content compressed with Deflate algorithm'
|
||||||
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'
|
# Output Processing
|
||||||
complete -c http -l traceback -d 'Prints exception traceback should one occur'
|
|
||||||
complete -c http -l debug -d 'Show debugging information'
|
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,49 +8,56 @@ class Httpie < Formula
|
|||||||
include Language::Python::Virtualenv
|
include Language::Python::Virtualenv
|
||||||
|
|
||||||
desc "User-friendly cURL replacement (command-line HTTP client)"
|
desc "User-friendly cURL replacement (command-line HTTP client)"
|
||||||
homepage "https://httpie.org/"
|
homepage "https://httpie.io/"
|
||||||
url "https://files.pythonhosted.org/packages/35/6c/93da2ebd4eb768c3733437ce01b5fae297522434fdeabeeabdc4f42aabd3/httpie-2.0.0.tar.gz"
|
url "https://files.pythonhosted.org/packages/17/3a/90fb6702e600f5ba7d38d147bbc0b0a1e47159e3e244737319c98c140420/httpie-2.4.0.tar.gz"
|
||||||
sha256 "8c04f9756f1a7eac71a6dfa0834d0f6813dc8a982d8564f3a7418dcd19107c09"
|
sha256 "4d1bf5779cf6c9007351cfcaa20bd19947267dc026af09246db6006a8927d8c6"
|
||||||
revision 1
|
license "BSD-3-Clause"
|
||||||
head "https://github.com/jakubroztocil/httpie.git"
|
head "https://github.com/httpie/httpie.git"
|
||||||
|
|
||||||
bottle do
|
bottle do
|
||||||
cellar :any_skip_relocation
|
rebuild 1
|
||||||
sha256 "19694b5ec311939a8b73cc329ca49386155ed3a17e4eca691779c725d36286b5" => :catalina
|
sha256 cellar: :any_skip_relocation, arm64_big_sur: "a01ce8767f6ea88eb8e7894347ba64eb29294053a8ee91eed44dfaf0ab5e7ea2"
|
||||||
sha256 "8c7d93d55ea3351e25fadfdd3748ca0a3ff7dd62ab9dbf31b7243fba76890c4d" => :mojave
|
sha256 cellar: :any_skip_relocation, big_sur: "bdffeff349595ed3c528ed791d568e308b0877246b49e05e867143ba3415a70f"
|
||||||
sha256 "e0d5269bb5d03a1797c8612005fa46d6a35f2b84eb76e9607ef1169464b566ea" => :high_sierra
|
sha256 cellar: :any_skip_relocation, catalina: "ba0627d70f0ee49c64677f5554881ebd56371f47d45196b6564680089ce69152"
|
||||||
|
sha256 cellar: :any_skip_relocation, mojave: "0b87901e88bdcf53c55c5138677087b4621c5aaf1fca67b53b730d5a2fd5a40a"
|
||||||
|
sha256 cellar: :any_skip_relocation, high_sierra: "87e7348b6fb40fd8e4f7597937952469601962189e62d321b8cb4fa421e035ef"
|
||||||
end
|
end
|
||||||
|
|
||||||
depends_on "python@3.8"
|
depends_on "python@3.9"
|
||||||
|
|
||||||
resource "Pygments" do
|
resource "Pygments" do
|
||||||
url "https://files.pythonhosted.org/packages/cb/9f/27d4844ac5bf158a33900dbad7985951e2910397998e85712da03ce125f0/Pygments-2.5.2.tar.gz"
|
url "https://files.pythonhosted.org/packages/e1/86/8059180e8217299079d8719c6e23d674aadaba0b1939e25e0cc15dcf075b/Pygments-2.7.4.tar.gz"
|
||||||
sha256 "98c8aa5a9f778fcd1026a17361ddaf7330d1b7c62ae97c3bb0ae73e0b9b6b0fe"
|
sha256 "df49d09b498e83c1a73128295860250b0b7edd4c723a32e9bc0d295c7c2ec337"
|
||||||
end
|
end
|
||||||
|
|
||||||
resource "requests" do
|
resource "requests" do
|
||||||
url "https://files.pythonhosted.org/packages/01/62/ddcf76d1d19885e8579acb1b1df26a852b03472c0e46d2b959a714c90608/requests-2.22.0.tar.gz"
|
url "https://files.pythonhosted.org/packages/6b/47/c14abc08432ab22dc18b9892252efaf005ab44066de871e72a38d6af464b/requests-2.25.1.tar.gz"
|
||||||
sha256 "11e007a8a2aa0323f5a921e9e6a2d7e4e67d9877e85773fba9ba6419025cbeb4"
|
sha256 "27973dd4a904a4f13b263a19c866c13b92a39ed1c964655f025f3f8d3d75b804"
|
||||||
|
end
|
||||||
|
|
||||||
|
resource "requests-toolbelt" do
|
||||||
|
url "https://files.pythonhosted.org/packages/28/30/7bf7e5071081f761766d46820e52f4b16c8a08fef02d2eb4682ca7534310/requests-toolbelt-0.9.1.tar.gz"
|
||||||
|
sha256 "968089d4584ad4ad7c171454f0a5c6dac23971e9472521ea3b6d49d610aa6fc0"
|
||||||
end
|
end
|
||||||
|
|
||||||
resource "certifi" do
|
resource "certifi" do
|
||||||
url "https://files.pythonhosted.org/packages/41/bf/9d214a5af07debc6acf7f3f257265618f1db242a3f8e49a9b516f24523a6/certifi-2019.11.28.tar.gz"
|
url "https://files.pythonhosted.org/packages/06/a9/cd1fd8ee13f73a4d4f491ee219deeeae20afefa914dfb4c130cfc9dc397a/certifi-2020.12.5.tar.gz"
|
||||||
sha256 "25b64c7da4cd7479594d035c08c2d809eb4aab3a26e5a990ea98cc450c320f1f"
|
sha256 "1a4995114262bffbc2413b159f2a1a480c969de6e6eb13ee966d470af86af59c"
|
||||||
end
|
end
|
||||||
|
|
||||||
resource "urllib3" do
|
resource "urllib3" do
|
||||||
url "https://files.pythonhosted.org/packages/ad/fc/54d62fa4fc6e675678f9519e677dfc29b8964278d75333cf142892caf015/urllib3-1.25.7.tar.gz"
|
url "https://files.pythonhosted.org/packages/d7/8d/7ee68c6b48e1ec8d41198f694ecdc15f7596356f2ff8e6b1420300cf5db3/urllib3-1.26.3.tar.gz"
|
||||||
sha256 "f3c5fd51747d450d4dcf6f923c81f78f811aab8205fda64b0aba34a4e48b0745"
|
sha256 "de3eedaad74a2683334e282005cd8d7f22f4d55fa690a2a1020a416cb0a47e73"
|
||||||
end
|
end
|
||||||
|
|
||||||
resource "idna" do
|
resource "idna" do
|
||||||
url "https://files.pythonhosted.org/packages/ad/13/eb56951b6f7950cadb579ca166e448ba77f9d24efc03edd7e55fa57d04b7/idna-2.8.tar.gz"
|
url "https://files.pythonhosted.org/packages/ea/b7/e0e3c1c467636186c39925827be42f16fee389dc404ac29e930e9136be70/idna-2.10.tar.gz"
|
||||||
sha256 "c357b3f628cf53ae2c4c05627ecc484553142ca23264e593d327bcde5e9c3407"
|
sha256 "b307872f855b18632ce0c21c5e45be78c0ea7ae4c15c828c20788b26921eb3f6"
|
||||||
end
|
end
|
||||||
|
|
||||||
resource "chardet" do
|
resource "chardet" do
|
||||||
url "https://files.pythonhosted.org/packages/fc/bb/a5768c230f9ddb03acc9ef3f0d4a3cf93462473795d18e9535498c8f929d/chardet-3.0.4.tar.gz"
|
url "https://files.pythonhosted.org/packages/ee/2d/9cdc2b527e127b4c9db64b86647d567985940ac3698eeabc7ffaccb4ea61/chardet-4.0.0.tar.gz"
|
||||||
sha256 "84ab92ed1c4d4f16916e05906b6b75a6c0fb5db821cc65e70cbd64a3e2a5eaae"
|
sha256 "0d6f53a15db4120f2b08c94f11e7d93d2c911ee118b6b30a04ec3ee8310179fa"
|
||||||
end
|
end
|
||||||
|
|
||||||
resource "PySocks" do
|
resource "PySocks" do
|
||||||
@ -63,7 +70,7 @@ class Httpie < Formula
|
|||||||
end
|
end
|
||||||
|
|
||||||
test do
|
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}")
|
assert_match "PYTHONPATH", shell_output("#{bin}/http --ignore-stdin #{raw_url}")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
BIN
httpie.png
BIN
httpie.png
Binary file not shown.
Before Width: | Height: | Size: 681 KiB |
@ -1,8 +1,8 @@
|
|||||||
"""
|
"""
|
||||||
HTTPie - a CLI, cURL-like tool for humans.
|
HTTPie: command-line HTTP client for the API era.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
__version__ = '2.1.0'
|
__version__ = '2.5.0'
|
||||||
__author__ = 'Jakub Roztocil'
|
__author__ = 'Jakub Roztocil'
|
||||||
__licence__ = 'BSD'
|
__licence__ = 'BSD'
|
||||||
|
@ -1,20 +1,19 @@
|
|||||||
#!/usr/bin/env python
|
|
||||||
"""The main entry point. Invoke as `http' or `python -m httpie'.
|
"""The main entry point. Invoke as `http' or `python -m httpie'.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
import sys
|
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
try:
|
try:
|
||||||
from .core import main
|
from httpie.core import main
|
||||||
exit_status = main()
|
exit_status = main()
|
||||||
except KeyboardInterrupt:
|
except KeyboardInterrupt:
|
||||||
from httpie.status import ExitStatus
|
from httpie.status import ExitStatus
|
||||||
exit_status = ExitStatus.ERROR_CTRL_C
|
exit_status = ExitStatus.ERROR_CTRL_C
|
||||||
|
|
||||||
sys.exit(exit_status.value)
|
return exit_status.value
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__': # pragma: nocover
|
||||||
main()
|
import sys
|
||||||
|
sys.exit(main())
|
||||||
|
@ -7,19 +7,25 @@ from argparse import RawDescriptionHelpFormatter
|
|||||||
from textwrap import dedent
|
from textwrap import dedent
|
||||||
from urllib.parse import urlsplit
|
from urllib.parse import urlsplit
|
||||||
|
|
||||||
from httpie.cli.argtypes import AuthCredentials, KeyValueArgType, parse_auth
|
from requests.utils import get_netrc_auth
|
||||||
from httpie.cli.constants import (
|
|
||||||
HTTP_GET, HTTP_POST, OUTPUT_OPTIONS, OUTPUT_OPTIONS_DEFAULT,
|
from .argtypes import (
|
||||||
OUTPUT_OPTIONS_DEFAULT_STDOUT_REDIRECTED, OUT_RESP_BODY, PRETTY_MAP,
|
AuthCredentials, KeyValueArgType, PARSED_DEFAULT_FORMAT_OPTIONS,
|
||||||
PRETTY_STDOUT_TTY_ONLY, SEPARATOR_CREDENTIALS, SEPARATOR_GROUP_ALL_ITEMS,
|
parse_auth,
|
||||||
SEPARATOR_GROUP_DATA_ITEMS, URL_SCHEME_RE,
|
parse_format_options,
|
||||||
OUTPUT_OPTIONS_DEFAULT_OFFLINE,
|
|
||||||
)
|
)
|
||||||
from httpie.cli.exceptions import ParseError
|
from .constants import (
|
||||||
from httpie.cli.requestitems import RequestItems
|
HTTP_GET, HTTP_POST, OUTPUT_OPTIONS, OUTPUT_OPTIONS_DEFAULT,
|
||||||
from httpie.context import Environment
|
OUTPUT_OPTIONS_DEFAULT_OFFLINE, OUTPUT_OPTIONS_DEFAULT_STDOUT_REDIRECTED,
|
||||||
from httpie.plugins import plugin_manager
|
OUT_RESP_BODY, PRETTY_MAP, PRETTY_STDOUT_TTY_ONLY, RequestType,
|
||||||
from httpie.utils import ExplicitNullAuth, get_content_type
|
SEPARATOR_CREDENTIALS,
|
||||||
|
SEPARATOR_GROUP_ALL_ITEMS, SEPARATOR_GROUP_DATA_ITEMS, URL_SCHEME_RE,
|
||||||
|
)
|
||||||
|
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):
|
class HTTPieHelpFormatter(RawDescriptionHelpFormatter):
|
||||||
@ -42,6 +48,8 @@ class HTTPieHelpFormatter(RawDescriptionHelpFormatter):
|
|||||||
return text.splitlines()
|
return text.splitlines()
|
||||||
|
|
||||||
|
|
||||||
|
# TODO: refactor and design type-annotated data structures
|
||||||
|
# for raw args + parsed args and keep things immutable.
|
||||||
class HTTPieArgumentParser(argparse.ArgumentParser):
|
class HTTPieArgumentParser(argparse.ArgumentParser):
|
||||||
"""Adds additional logic to `argparse.ArgumentParser`.
|
"""Adds additional logic to `argparse.ArgumentParser`.
|
||||||
|
|
||||||
@ -56,6 +64,7 @@ class HTTPieArgumentParser(argparse.ArgumentParser):
|
|||||||
self.env = None
|
self.env = None
|
||||||
self.args = None
|
self.args = None
|
||||||
self.has_stdin_data = False
|
self.has_stdin_data = False
|
||||||
|
self.has_input_data = False
|
||||||
|
|
||||||
# noinspection PyMethodOverriding
|
# noinspection PyMethodOverriding
|
||||||
def parse_args(
|
def parse_args(
|
||||||
@ -66,32 +75,56 @@ class HTTPieArgumentParser(argparse.ArgumentParser):
|
|||||||
) -> argparse.Namespace:
|
) -> argparse.Namespace:
|
||||||
self.env = env
|
self.env = env
|
||||||
self.args, no_options = super().parse_known_args(args, namespace)
|
self.args, no_options = super().parse_known_args(args, namespace)
|
||||||
|
|
||||||
if self.args.debug:
|
if self.args.debug:
|
||||||
self.args.traceback = True
|
self.args.traceback = True
|
||||||
|
|
||||||
self.has_stdin_data = (
|
self.has_stdin_data = (
|
||||||
self.env.stdin
|
self.env.stdin
|
||||||
and not self.args.ignore_stdin
|
and not self.args.ignore_stdin
|
||||||
and not self.env.stdin_isatty
|
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.
|
# Arguments processing and environment setup.
|
||||||
self._apply_no_options(no_options)
|
self._apply_no_options(no_options)
|
||||||
|
self._process_request_type()
|
||||||
self._process_download_options()
|
self._process_download_options()
|
||||||
self._setup_standard_streams()
|
self._setup_standard_streams()
|
||||||
self._process_output_options()
|
self._process_output_options()
|
||||||
self._process_pretty_options()
|
self._process_pretty_options()
|
||||||
|
self._process_format_options()
|
||||||
self._guess_method()
|
self._guess_method()
|
||||||
self._parse_items()
|
self._parse_items()
|
||||||
|
self._process_url()
|
||||||
|
self._process_auth()
|
||||||
|
|
||||||
if self.has_stdin_data:
|
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)
|
self._body_from_file(self.env.stdin)
|
||||||
|
|
||||||
|
if self.args.compress:
|
||||||
|
# TODO: allow --compress with --chunked / --multipart
|
||||||
|
if self.args.chunked:
|
||||||
|
self.error('cannot combine --compress and --chunked')
|
||||||
|
if self.args.multipart:
|
||||||
|
self.error('cannot combine --compress and --multipart')
|
||||||
|
|
||||||
|
return self.args
|
||||||
|
|
||||||
|
def _process_request_type(self):
|
||||||
|
request_type = self.args.request_type
|
||||||
|
self.args.json = request_type is RequestType.JSON
|
||||||
|
self.args.multipart = request_type is RequestType.MULTIPART
|
||||||
|
self.args.form = request_type in {
|
||||||
|
RequestType.FORM,
|
||||||
|
RequestType.MULTIPART,
|
||||||
|
}
|
||||||
|
|
||||||
|
def _process_url(self):
|
||||||
if not URL_SCHEME_RE.match(self.args.url):
|
if not URL_SCHEME_RE.match(self.args.url):
|
||||||
if os.path.basename(env.program_name) == 'https':
|
if os.path.basename(self.env.program_name) == 'https':
|
||||||
scheme = 'https://'
|
scheme = 'https://'
|
||||||
else:
|
else:
|
||||||
scheme = self.args.default_scheme + "://"
|
scheme = self.args.default_scheme + '://'
|
||||||
|
|
||||||
# See if we're using curl style shorthand for localhost (:3000/foo)
|
# See if we're using curl style shorthand for localhost (:3000/foo)
|
||||||
shorthand = re.match(r'^:(?!:)(\d*)(/?.*)$', self.args.url)
|
shorthand = re.match(r'^:(?!:)(\d*)(/?.*)$', self.args.url)
|
||||||
@ -104,9 +137,6 @@ class HTTPieArgumentParser(argparse.ArgumentParser):
|
|||||||
self.args.url += rest
|
self.args.url += rest
|
||||||
else:
|
else:
|
||||||
self.args.url = scheme + self.args.url
|
self.args.url = scheme + self.args.url
|
||||||
self._process_auth()
|
|
||||||
|
|
||||||
return self.args
|
|
||||||
|
|
||||||
# noinspection PyShadowingBuiltins
|
# noinspection PyShadowingBuiltins
|
||||||
def _print_message(self, message, file=None):
|
def _print_message(self, message, file=None):
|
||||||
@ -125,6 +155,7 @@ class HTTPieArgumentParser(argparse.ArgumentParser):
|
|||||||
Modify `env.stdout` and `env.stdout_isatty` based on args, if needed.
|
Modify `env.stdout` and `env.stdout_isatty` based on args, if needed.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
self.args.output_file_specified = bool(self.args.output_file)
|
self.args.output_file_specified = bool(self.args.output_file)
|
||||||
if self.args.download:
|
if self.args.download:
|
||||||
# FIXME: Come up with a cleaner solution.
|
# FIXME: Come up with a cleaner solution.
|
||||||
@ -137,6 +168,7 @@ class HTTPieArgumentParser(argparse.ArgumentParser):
|
|||||||
# The response body will be treated separately.
|
# The response body will be treated separately.
|
||||||
self.env.stdout = self.env.stderr
|
self.env.stdout = self.env.stderr
|
||||||
self.env.stdout_isatty = self.env.stderr_isatty
|
self.env.stdout_isatty = self.env.stderr_isatty
|
||||||
|
|
||||||
elif self.args.output_file:
|
elif self.args.output_file:
|
||||||
# When not `--download`ing, then `--output` simply replaces
|
# When not `--download`ing, then `--output` simply replaces
|
||||||
# `stdout`. The file is opened for appending, which isn't what
|
# `stdout`. The file is opened for appending, which isn't what
|
||||||
@ -144,7 +176,7 @@ class HTTPieArgumentParser(argparse.ArgumentParser):
|
|||||||
self.args.output_file.seek(0)
|
self.args.output_file.seek(0)
|
||||||
try:
|
try:
|
||||||
self.args.output_file.truncate()
|
self.args.output_file.truncate()
|
||||||
except IOError as e:
|
except OSError as e:
|
||||||
if e.errno == errno.EINVAL:
|
if e.errno == errno.EINVAL:
|
||||||
# E.g. /dev/null on Linux.
|
# E.g. /dev/null on Linux.
|
||||||
pass
|
pass
|
||||||
@ -153,8 +185,13 @@ class HTTPieArgumentParser(argparse.ArgumentParser):
|
|||||||
self.env.stdout = self.args.output_file
|
self.env.stdout = self.args.output_file
|
||||||
self.env.stdout_isatty = False
|
self.env.stdout_isatty = False
|
||||||
|
|
||||||
|
if self.args.quiet:
|
||||||
|
self.env.stderr = self.env.devnull
|
||||||
|
if not (self.args.output_file_specified and not self.args.download):
|
||||||
|
self.env.stdout = self.env.devnull
|
||||||
|
|
||||||
def _process_auth(self):
|
def _process_auth(self):
|
||||||
# TODO: refactor
|
# TODO: refactor & simplify this method.
|
||||||
self.args.auth_plugin = None
|
self.args.auth_plugin = None
|
||||||
default_auth_plugin = plugin_manager.get_auth_plugins()[0]
|
default_auth_plugin = plugin_manager.get_auth_plugins()[0]
|
||||||
auth_type_set = self.args.auth_type is not None
|
auth_type_set = self.args.auth_type is not None
|
||||||
@ -177,6 +214,19 @@ class HTTPieArgumentParser(argparse.ArgumentParser):
|
|||||||
self.args.auth_type = default_auth_plugin.auth_type
|
self.args.auth_type = default_auth_plugin.auth_type
|
||||||
plugin = plugin_manager.get_auth_plugin(self.args.auth_type)()
|
plugin = plugin_manager.get_auth_plugin(self.args.auth_type)()
|
||||||
|
|
||||||
|
if (not self.args.ignore_netrc
|
||||||
|
and self.args.auth is None
|
||||||
|
and plugin.netrc_parse):
|
||||||
|
# Only host needed, so it’s OK URL not finalized.
|
||||||
|
netrc_credentials = get_netrc_auth(self.args.url)
|
||||||
|
if netrc_credentials:
|
||||||
|
self.args.auth = AuthCredentials(
|
||||||
|
key=netrc_credentials[0],
|
||||||
|
value=netrc_credentials[1],
|
||||||
|
sep=SEPARATOR_CREDENTIALS,
|
||||||
|
orig=SEPARATOR_CREDENTIALS.join(netrc_credentials)
|
||||||
|
)
|
||||||
|
|
||||||
if plugin.auth_require and self.args.auth is None:
|
if plugin.auth_require and self.args.auth is None:
|
||||||
self.error('--auth required')
|
self.error('--auth required')
|
||||||
|
|
||||||
@ -234,21 +284,34 @@ class HTTPieArgumentParser(argparse.ArgumentParser):
|
|||||||
invalid.append(option)
|
invalid.append(option)
|
||||||
|
|
||||||
if invalid:
|
if invalid:
|
||||||
msg = 'unrecognized arguments: %s'
|
self.error(f'unrecognized arguments: {" ".join(invalid)}')
|
||||||
self.error(msg % ' '.join(invalid))
|
|
||||||
|
|
||||||
def _body_from_file(self, fd):
|
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.
|
Bytes are always read.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
if self.args.data or self.args.files:
|
self._ensure_one_data_source(self.args.data, self.args.files)
|
||||||
self.error('Request body (from stdin or a file) and request '
|
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 '
|
'data (key=value) cannot be mixed. Pass '
|
||||||
'--ignore-stdin to let key/value take priority. '
|
'--ignore-stdin to let key/value take priority. '
|
||||||
'See https://httpie.org/doc#scripting for details.')
|
'See https://httpie.org/doc#scripting for details.')
|
||||||
self.args.data = getattr(fd, 'buffer', fd).read()
|
|
||||||
|
|
||||||
def _guess_method(self):
|
def _guess_method(self):
|
||||||
"""Set `args.method` if not specified to either POST or GET
|
"""Set `args.method` if not specified to either POST or GET
|
||||||
@ -258,7 +321,7 @@ class HTTPieArgumentParser(argparse.ArgumentParser):
|
|||||||
if self.args.method is None:
|
if self.args.method is None:
|
||||||
# Invoked as `http URL'.
|
# Invoked as `http URL'.
|
||||||
assert not self.args.request_items
|
assert not self.args.request_items
|
||||||
if self.has_stdin_data:
|
if self.has_input_data:
|
||||||
self.args.method = HTTP_POST
|
self.args.method = HTTP_POST
|
||||||
else:
|
else:
|
||||||
self.args.method = HTTP_GET
|
self.args.method = HTTP_GET
|
||||||
@ -282,7 +345,7 @@ class HTTPieArgumentParser(argparse.ArgumentParser):
|
|||||||
self.args.url = self.args.method
|
self.args.url = self.args.method
|
||||||
# Infer the method
|
# Infer the method
|
||||||
has_data = (
|
has_data = (
|
||||||
self.has_stdin_data
|
self.has_input_data
|
||||||
or any(
|
or any(
|
||||||
item.sep in SEPARATOR_GROUP_DATA_ITEMS
|
item.sep in SEPARATOR_GROUP_DATA_ITEMS
|
||||||
for item in self.args.request_items)
|
for item in self.args.request_items)
|
||||||
@ -309,16 +372,21 @@ class HTTPieArgumentParser(argparse.ArgumentParser):
|
|||||||
self.args.data = request_items.data
|
self.args.data = request_items.data
|
||||||
self.args.files = request_items.files
|
self.args.files = request_items.files
|
||||||
self.args.params = request_items.params
|
self.args.params = request_items.params
|
||||||
|
self.args.multipart_data = request_items.multipart_data
|
||||||
|
|
||||||
if self.args.files and not self.args.form:
|
if self.args.files and not self.args.form:
|
||||||
# `http url @/path/to/file`
|
# `http url @/path/to/file`
|
||||||
file_fields = list(self.args.files.keys())
|
request_file = None
|
||||||
if file_fields != ['']:
|
for key, file in self.args.files.items():
|
||||||
self.error(
|
if key != '':
|
||||||
'Invalid file fields (perhaps you meant --form?): %s'
|
self.error(
|
||||||
% ','.join(file_fields))
|
'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.args.files = {}
|
||||||
|
|
||||||
self._body_from_file(fd)
|
self._body_from_file(fd)
|
||||||
@ -338,10 +406,7 @@ class HTTPieArgumentParser(argparse.ArgumentParser):
|
|||||||
def check_options(value, option):
|
def check_options(value, option):
|
||||||
unknown = set(value) - OUTPUT_OPTIONS
|
unknown = set(value) - OUTPUT_OPTIONS
|
||||||
if unknown:
|
if unknown:
|
||||||
self.error('Unknown output options: {0}={1}'.format(
|
self.error(f'Unknown output options: {option}={",".join(unknown)}')
|
||||||
option,
|
|
||||||
','.join(unknown)
|
|
||||||
))
|
|
||||||
|
|
||||||
if self.args.verbose:
|
if self.args.verbose:
|
||||||
self.args.all = True
|
self.args.all = True
|
||||||
@ -390,3 +455,9 @@ class HTTPieArgumentParser(argparse.ArgumentParser):
|
|||||||
if self.args.download_resume and not (
|
if self.args.download_resume and not (
|
||||||
self.args.download and self.args.output_file):
|
self.args.download and self.args.output_file):
|
||||||
self.error('--continue requires --output to be specified')
|
self.error('--continue requires --output to be specified')
|
||||||
|
|
||||||
|
def _process_format_options(self):
|
||||||
|
parsed_options = PARSED_DEFAULT_FORMAT_OPTIONS
|
||||||
|
for options_group in self.args.format_options or []:
|
||||||
|
parsed_options = parse_format_options(options_group, defaults=parsed_options)
|
||||||
|
self.args.format_options = parsed_options
|
||||||
|
@ -2,10 +2,11 @@ import argparse
|
|||||||
import getpass
|
import getpass
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
from typing import Union, List, Optional
|
from copy import deepcopy
|
||||||
|
from typing import List, Optional, Union
|
||||||
|
|
||||||
from httpie.cli.constants import SEPARATOR_CREDENTIALS
|
from .constants import DEFAULT_FORMAT_OPTIONS, SEPARATOR_CREDENTIALS
|
||||||
from httpie.sessions import VALID_SESSION_NAME_PATTERN
|
from ..sessions import VALID_SESSION_NAME_PATTERN
|
||||||
|
|
||||||
|
|
||||||
class KeyValueArg:
|
class KeyValueArg:
|
||||||
@ -179,5 +180,65 @@ def readable_file_arg(filename):
|
|||||||
try:
|
try:
|
||||||
with open(filename, 'rb'):
|
with open(filename, 'rb'):
|
||||||
return filename
|
return filename
|
||||||
except IOError as ex:
|
except OSError as ex:
|
||||||
raise argparse.ArgumentTypeError(f'{filename}: {ex.args[1]}')
|
raise argparse.ArgumentTypeError(f'{ex.filename}: {ex.strerror}')
|
||||||
|
|
||||||
|
|
||||||
|
def parse_format_options(s: str, defaults: Optional[dict]) -> dict:
|
||||||
|
"""
|
||||||
|
Parse `s` and update `defaults` with the parsed values.
|
||||||
|
|
||||||
|
>>> parse_format_options(
|
||||||
|
... defaults={'json': {'indent': 4, 'sort_keys': True}},
|
||||||
|
... s='json.indent:2,json.sort_keys:False',
|
||||||
|
... )
|
||||||
|
{'json': {'indent': 2, 'sort_keys': False}}
|
||||||
|
|
||||||
|
"""
|
||||||
|
value_map = {
|
||||||
|
'true': True,
|
||||||
|
'false': False,
|
||||||
|
}
|
||||||
|
options = deepcopy(defaults or {})
|
||||||
|
for option in s.split(','):
|
||||||
|
try:
|
||||||
|
path, value = option.lower().split(':')
|
||||||
|
section, key = path.split('.')
|
||||||
|
except ValueError:
|
||||||
|
raise argparse.ArgumentTypeError(f'invalid option {option!r}')
|
||||||
|
|
||||||
|
if value in value_map:
|
||||||
|
parsed_value = value_map[value]
|
||||||
|
else:
|
||||||
|
if value.isnumeric():
|
||||||
|
parsed_value = int(value)
|
||||||
|
else:
|
||||||
|
parsed_value = value
|
||||||
|
|
||||||
|
if defaults is None:
|
||||||
|
options.setdefault(section, {})
|
||||||
|
else:
|
||||||
|
try:
|
||||||
|
default_value = defaults[section][key]
|
||||||
|
except KeyError:
|
||||||
|
raise argparse.ArgumentTypeError(
|
||||||
|
f'invalid key {path!r}')
|
||||||
|
|
||||||
|
default_type, parsed_type = type(default_value), type(parsed_value)
|
||||||
|
if parsed_type is not default_type:
|
||||||
|
raise argparse.ArgumentTypeError(
|
||||||
|
'invalid value'
|
||||||
|
f' {value!r} in {option!r}'
|
||||||
|
f' (expected {default_type.__name__}'
|
||||||
|
f' got {parsed_type.__name__})'
|
||||||
|
)
|
||||||
|
|
||||||
|
options[section][key] = parsed_value
|
||||||
|
|
||||||
|
return options
|
||||||
|
|
||||||
|
|
||||||
|
PARSED_DEFAULT_FORMAT_OPTIONS = parse_format_options(
|
||||||
|
s=','.join(DEFAULT_FORMAT_OPTIONS),
|
||||||
|
defaults=None,
|
||||||
|
)
|
||||||
|
@ -1,16 +1,10 @@
|
|||||||
"""Parsing and processing of CLI input (args, auth credentials, files, stdin).
|
"""Parsing and processing of CLI input (args, auth credentials, files, stdin).
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
import enum
|
||||||
import re
|
import re
|
||||||
import ssl
|
|
||||||
|
|
||||||
|
|
||||||
# TODO: Use MultiDict for headers once added to `requests`.
|
|
||||||
# <https://github.com/jakubroztocil/httpie/issues/130>
|
|
||||||
|
|
||||||
|
|
||||||
# ALPHA *( ALPHA / DIGIT / "+" / "-" / "." )
|
|
||||||
# <https://tools.ietf.org/html/rfc3986#section-3.1>
|
|
||||||
URL_SCHEME_RE = re.compile(r'^[a-z][a-z0-9.+-]*://', re.IGNORECASE)
|
URL_SCHEME_RE = re.compile(r'^[a-z][a-z0-9.+-]*://', re.IGNORECASE)
|
||||||
|
|
||||||
HTTP_POST = 'POST'
|
HTTP_POST = 'POST'
|
||||||
@ -24,6 +18,7 @@ SEPARATOR_PROXY = ':'
|
|||||||
SEPARATOR_DATA_STRING = '='
|
SEPARATOR_DATA_STRING = '='
|
||||||
SEPARATOR_DATA_RAW_JSON = ':='
|
SEPARATOR_DATA_RAW_JSON = ':='
|
||||||
SEPARATOR_FILE_UPLOAD = '@'
|
SEPARATOR_FILE_UPLOAD = '@'
|
||||||
|
SEPARATOR_FILE_UPLOAD_TYPE = ';type=' # in already parsed file upload path only
|
||||||
SEPARATOR_DATA_EMBED_FILE_CONTENTS = '=@'
|
SEPARATOR_DATA_EMBED_FILE_CONTENTS = '=@'
|
||||||
SEPARATOR_DATA_EMBED_RAW_JSON_FILE = ':=@'
|
SEPARATOR_DATA_EMBED_RAW_JSON_FILE = ':=@'
|
||||||
SEPARATOR_QUERY_PARAM = '=='
|
SEPARATOR_QUERY_PARAM = '=='
|
||||||
@ -37,6 +32,12 @@ SEPARATOR_GROUP_DATA_ITEMS = frozenset({
|
|||||||
SEPARATOR_DATA_EMBED_RAW_JSON_FILE
|
SEPARATOR_DATA_EMBED_RAW_JSON_FILE
|
||||||
})
|
})
|
||||||
|
|
||||||
|
SEPARATORS_GROUP_MULTIPART = frozenset({
|
||||||
|
SEPARATOR_DATA_STRING,
|
||||||
|
SEPARATOR_DATA_EMBED_FILE_CONTENTS,
|
||||||
|
SEPARATOR_FILE_UPLOAD,
|
||||||
|
})
|
||||||
|
|
||||||
# Separators for items whose value is a filename to be embedded
|
# Separators for items whose value is a filename to be embedded
|
||||||
SEPARATOR_GROUP_DATA_EMBED_ITEMS = frozenset({
|
SEPARATOR_GROUP_DATA_EMBED_ITEMS = frozenset({
|
||||||
SEPARATOR_DATA_EMBED_FILE_CONTENTS,
|
SEPARATOR_DATA_EMBED_FILE_CONTENTS,
|
||||||
@ -83,21 +84,30 @@ PRETTY_MAP = {
|
|||||||
}
|
}
|
||||||
PRETTY_STDOUT_TTY_ONLY = object()
|
PRETTY_STDOUT_TTY_ONLY = object()
|
||||||
|
|
||||||
|
|
||||||
|
DEFAULT_FORMAT_OPTIONS = [
|
||||||
|
'headers.sort:true',
|
||||||
|
'json.format:true',
|
||||||
|
'json.indent:4',
|
||||||
|
'json.sort_keys:true',
|
||||||
|
'xml.format:true',
|
||||||
|
'xml.indent:2',
|
||||||
|
]
|
||||||
|
SORTED_FORMAT_OPTIONS = [
|
||||||
|
'headers.sort:true',
|
||||||
|
'json.sort_keys:true',
|
||||||
|
]
|
||||||
|
SORTED_FORMAT_OPTIONS_STRING = ','.join(SORTED_FORMAT_OPTIONS)
|
||||||
|
UNSORTED_FORMAT_OPTIONS_STRING = ','.join(
|
||||||
|
option.replace('true', 'false') for option in SORTED_FORMAT_OPTIONS)
|
||||||
|
|
||||||
# Defaults
|
# Defaults
|
||||||
OUTPUT_OPTIONS_DEFAULT = OUT_RESP_HEAD + OUT_RESP_BODY
|
OUTPUT_OPTIONS_DEFAULT = OUT_RESP_HEAD + OUT_RESP_BODY
|
||||||
OUTPUT_OPTIONS_DEFAULT_STDOUT_REDIRECTED = OUT_RESP_BODY
|
OUTPUT_OPTIONS_DEFAULT_STDOUT_REDIRECTED = OUT_RESP_BODY
|
||||||
OUTPUT_OPTIONS_DEFAULT_OFFLINE = OUT_REQ_HEAD + OUT_REQ_BODY
|
OUTPUT_OPTIONS_DEFAULT_OFFLINE = OUT_REQ_HEAD + OUT_REQ_BODY
|
||||||
|
|
||||||
SSL_VERSION_ARG_MAPPING = {
|
|
||||||
'ssl2.3': 'PROTOCOL_SSLv23',
|
class RequestType(enum.Enum):
|
||||||
'ssl3': 'PROTOCOL_SSLv3',
|
FORM = enum.auto()
|
||||||
'tls1': 'PROTOCOL_TLSv1',
|
MULTIPART = enum.auto()
|
||||||
'tls1.1': 'PROTOCOL_TLSv1_1',
|
JSON = enum.auto()
|
||||||
'tls1.2': 'PROTOCOL_TLSv1_2',
|
|
||||||
'tls1.3': 'PROTOCOL_TLSv1_3',
|
|
||||||
}
|
|
||||||
SSL_VERSION_ARG_MAPPING = {
|
|
||||||
cli_arg: getattr(ssl, ssl_constant)
|
|
||||||
for cli_arg, ssl_constant in SSL_VERSION_ARG_MAPPING.items()
|
|
||||||
if hasattr(ssl, ssl_constant)
|
|
||||||
}
|
|
||||||
|
@ -5,36 +5,41 @@ CLI arguments definition.
|
|||||||
from argparse import (FileType, OPTIONAL, SUPPRESS, ZERO_OR_MORE)
|
from argparse import (FileType, OPTIONAL, SUPPRESS, ZERO_OR_MORE)
|
||||||
from textwrap import dedent, wrap
|
from textwrap import dedent, wrap
|
||||||
|
|
||||||
from httpie import __doc__, __version__
|
from .. import __doc__, __version__
|
||||||
from httpie.cli.argparser import HTTPieArgumentParser
|
from .argparser import HTTPieArgumentParser
|
||||||
from httpie.cli.argtypes import (
|
from .argtypes import (
|
||||||
KeyValueArgType, SessionNameValidator, readable_file_arg,
|
KeyValueArgType, SessionNameValidator,
|
||||||
|
readable_file_arg,
|
||||||
)
|
)
|
||||||
from httpie.cli.constants import (
|
from .constants import (
|
||||||
OUTPUT_OPTIONS, OUTPUT_OPTIONS_DEFAULT, OUT_REQ_BODY, OUT_REQ_HEAD,
|
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,
|
OUT_RESP_BODY, OUT_RESP_HEAD, PRETTY_MAP, PRETTY_STDOUT_TTY_ONLY,
|
||||||
SEPARATOR_GROUP_ALL_ITEMS, SEPARATOR_PROXY, SSL_VERSION_ARG_MAPPING,
|
RequestType, SEPARATOR_GROUP_ALL_ITEMS, SEPARATOR_PROXY,
|
||||||
|
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,
|
AUTO_STYLE, AVAILABLE_STYLES, DEFAULT_STYLE,
|
||||||
)
|
)
|
||||||
from httpie.plugins import plugin_manager
|
from ..plugins.builtin import BuiltinAuthPlugin
|
||||||
from httpie.plugins.builtin import BuiltinAuthPlugin
|
from ..plugins.registry import plugin_manager
|
||||||
from httpie.sessions import DEFAULT_SESSIONS_DIR
|
from ..sessions import DEFAULT_SESSIONS_DIR
|
||||||
|
from ..ssl import AVAILABLE_SSL_VERSION_ARG_MAPPING, DEFAULT_SSL_CIPHERS
|
||||||
|
|
||||||
|
|
||||||
parser = HTTPieArgumentParser(
|
parser = HTTPieArgumentParser(
|
||||||
prog='http',
|
prog='http',
|
||||||
description='%s <https://httpie.org>' % __doc__.strip(),
|
description=f'{__doc__.strip()} <https://httpie.org>',
|
||||||
epilog=dedent("""
|
epilog=dedent('''
|
||||||
For every --OPTION there is also a --no-OPTION that reverts OPTION
|
For every --OPTION there is also a --no-OPTION that reverts OPTION
|
||||||
to its default value.
|
to its default value.
|
||||||
|
|
||||||
Suggestions and bug reports are greatly appreciated:
|
Suggestions and bug reports are greatly appreciated:
|
||||||
|
|
||||||
https://github.com/jakubroztocil/httpie/issues
|
https://github.com/httpie/httpie/issues
|
||||||
|
|
||||||
"""),
|
'''),
|
||||||
)
|
)
|
||||||
|
|
||||||
#######################################################################
|
#######################################################################
|
||||||
@ -43,18 +48,18 @@ parser = HTTPieArgumentParser(
|
|||||||
|
|
||||||
positional = parser.add_argument_group(
|
positional = parser.add_argument_group(
|
||||||
title='Positional Arguments',
|
title='Positional Arguments',
|
||||||
description=dedent("""
|
description=dedent('''
|
||||||
These arguments come after any flags and in the order they are listed here.
|
These arguments come after any flags and in the order they are listed here.
|
||||||
Only URL is required.
|
Only URL is required.
|
||||||
|
|
||||||
""")
|
''')
|
||||||
)
|
)
|
||||||
positional.add_argument(
|
positional.add_argument(
|
||||||
dest='method',
|
dest='method',
|
||||||
metavar='METHOD',
|
metavar='METHOD',
|
||||||
nargs=OPTIONAL,
|
nargs=OPTIONAL,
|
||||||
default=None,
|
default=None,
|
||||||
help="""
|
help='''
|
||||||
The HTTP method to be used for the request (GET, POST, PUT, DELETE, ...).
|
The HTTP method to be used for the request (GET, POST, PUT, DELETE, ...).
|
||||||
|
|
||||||
This argument can be omitted in which case HTTPie will use POST if there
|
This argument can be omitted in which case HTTPie will use POST if there
|
||||||
@ -63,12 +68,12 @@ positional.add_argument(
|
|||||||
$ http example.org # => GET
|
$ http example.org # => GET
|
||||||
$ http example.org hello=world # => POST
|
$ http example.org hello=world # => POST
|
||||||
|
|
||||||
"""
|
'''
|
||||||
)
|
)
|
||||||
positional.add_argument(
|
positional.add_argument(
|
||||||
dest='url',
|
dest='url',
|
||||||
metavar='URL',
|
metavar='URL',
|
||||||
help="""
|
help='''
|
||||||
The scheme defaults to 'http://' if the URL does not include one.
|
The scheme defaults to 'http://' if the URL does not include one.
|
||||||
(You can override this with: --default-scheme=https)
|
(You can override this with: --default-scheme=https)
|
||||||
|
|
||||||
@ -77,7 +82,7 @@ positional.add_argument(
|
|||||||
$ http :3000 # => http://localhost:3000
|
$ http :3000 # => http://localhost:3000
|
||||||
$ http :/foo # => http://localhost/foo
|
$ http :/foo # => http://localhost/foo
|
||||||
|
|
||||||
"""
|
'''
|
||||||
)
|
)
|
||||||
positional.add_argument(
|
positional.add_argument(
|
||||||
dest='request_items',
|
dest='request_items',
|
||||||
@ -85,7 +90,7 @@ positional.add_argument(
|
|||||||
nargs=ZERO_OR_MORE,
|
nargs=ZERO_OR_MORE,
|
||||||
default=None,
|
default=None,
|
||||||
type=KeyValueArgType(*SEPARATOR_GROUP_ALL_ITEMS),
|
type=KeyValueArgType(*SEPARATOR_GROUP_ALL_ITEMS),
|
||||||
help=r"""
|
help=r'''
|
||||||
Optional key-value pairs to be included in the request. The separator used
|
Optional key-value pairs to be included in the request. The separator used
|
||||||
determines the type:
|
determines the type:
|
||||||
|
|
||||||
@ -106,9 +111,10 @@ positional.add_argument(
|
|||||||
|
|
||||||
awesome:=true amount:=42 colors:='["red", "green", "blue"]'
|
awesome:=true amount:=42 colors:='["red", "green", "blue"]'
|
||||||
|
|
||||||
'@' Form file fields (only with --form, -f):
|
'@' Form file fields (only with --form or --multipart):
|
||||||
|
|
||||||
cs@~/Documents/CV.pdf
|
cv@~/Documents/CV.pdf
|
||||||
|
cv@'~/Documents/CV.pdf;type=application/pdf'
|
||||||
|
|
||||||
'=@' A data field like '=', but takes a file path and embeds its content:
|
'=@' A data field like '=', but takes a file path and embeds its content:
|
||||||
|
|
||||||
@ -122,7 +128,7 @@ positional.add_argument(
|
|||||||
|
|
||||||
field-name-with\:colon=value
|
field-name-with\:colon=value
|
||||||
|
|
||||||
"""
|
'''
|
||||||
)
|
)
|
||||||
|
|
||||||
#######################################################################
|
#######################################################################
|
||||||
@ -136,26 +142,69 @@ content_type = parser.add_argument_group(
|
|||||||
|
|
||||||
content_type.add_argument(
|
content_type.add_argument(
|
||||||
'--json', '-j',
|
'--json', '-j',
|
||||||
action='store_true',
|
action='store_const',
|
||||||
help="""
|
const=RequestType.JSON,
|
||||||
|
dest='request_type',
|
||||||
|
help='''
|
||||||
(default) Data items from the command line are serialized as a JSON object.
|
(default) Data items from the command line are serialized as a JSON object.
|
||||||
The Content-Type and Accept headers are set to application/json
|
The Content-Type and Accept headers are set to application/json
|
||||||
(if not specified).
|
(if not specified).
|
||||||
|
|
||||||
"""
|
'''
|
||||||
)
|
)
|
||||||
content_type.add_argument(
|
content_type.add_argument(
|
||||||
'--form', '-f',
|
'--form', '-f',
|
||||||
action='store_true',
|
action='store_const',
|
||||||
help="""
|
const=RequestType.FORM,
|
||||||
|
dest='request_type',
|
||||||
|
help='''
|
||||||
Data items from the command line are serialized as form fields.
|
Data items from the command line are serialized as form fields.
|
||||||
|
|
||||||
The Content-Type is set to application/x-www-form-urlencoded (if not
|
The Content-Type is set to application/x-www-form-urlencoded (if not
|
||||||
specified). The presence of any file fields results in a
|
specified). The presence of any file fields results in a
|
||||||
multipart/form-data request.
|
multipart/form-data request.
|
||||||
|
|
||||||
"""
|
'''
|
||||||
)
|
)
|
||||||
|
content_type.add_argument(
|
||||||
|
'--multipart',
|
||||||
|
action='store_const',
|
||||||
|
const=RequestType.MULTIPART,
|
||||||
|
dest='request_type',
|
||||||
|
help='''
|
||||||
|
Similar to --form, but always sends a multipart/form-data
|
||||||
|
request (i.e., even without files).
|
||||||
|
|
||||||
|
'''
|
||||||
|
)
|
||||||
|
content_type.add_argument(
|
||||||
|
'--boundary',
|
||||||
|
help='''
|
||||||
|
Specify a custom boundary string for multipart/form-data requests.
|
||||||
|
Only has effect only together with --form.
|
||||||
|
|
||||||
|
'''
|
||||||
|
)
|
||||||
|
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
|
||||||
|
|
||||||
|
|
||||||
|
'''
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
#######################################################################
|
#######################################################################
|
||||||
# Content processing.
|
# Content processing.
|
||||||
@ -170,14 +219,14 @@ content_processing.add_argument(
|
|||||||
'--compress', '-x',
|
'--compress', '-x',
|
||||||
action='count',
|
action='count',
|
||||||
default=0,
|
default=0,
|
||||||
help="""
|
help='''
|
||||||
Content compressed (encoded) with Deflate algorithm.
|
Content compressed (encoded) with Deflate algorithm.
|
||||||
The Content-Encoding header is set to deflate.
|
The Content-Encoding header is set to deflate.
|
||||||
|
|
||||||
Compression is skipped if it appears that compression ratio is
|
Compression is skipped if it appears that compression ratio is
|
||||||
negative. Compression can be forced by repeating the argument.
|
negative. Compression can be forced by repeating the argument.
|
||||||
|
|
||||||
"""
|
'''
|
||||||
)
|
)
|
||||||
|
|
||||||
#######################################################################
|
#######################################################################
|
||||||
@ -191,12 +240,12 @@ output_processing.add_argument(
|
|||||||
dest='prettify',
|
dest='prettify',
|
||||||
default=PRETTY_STDOUT_TTY_ONLY,
|
default=PRETTY_STDOUT_TTY_ONLY,
|
||||||
choices=sorted(PRETTY_MAP.keys()),
|
choices=sorted(PRETTY_MAP.keys()),
|
||||||
help="""
|
help='''
|
||||||
Controls output processing. The value can be "none" to not prettify
|
Controls output processing. The value can be "none" to not prettify
|
||||||
the output (default for redirected output), "all" to apply both colors
|
the output (default for redirected output), "all" to apply both colors
|
||||||
and formatting (default for terminal output), "colors", or "format".
|
and formatting (default for terminal output), "colors", or "format".
|
||||||
|
|
||||||
"""
|
'''
|
||||||
)
|
)
|
||||||
output_processing.add_argument(
|
output_processing.add_argument(
|
||||||
'--style', '-s',
|
'--style', '-s',
|
||||||
@ -204,10 +253,10 @@ output_processing.add_argument(
|
|||||||
metavar='STYLE',
|
metavar='STYLE',
|
||||||
default=DEFAULT_STYLE,
|
default=DEFAULT_STYLE,
|
||||||
choices=AVAILABLE_STYLES,
|
choices=AVAILABLE_STYLES,
|
||||||
help="""
|
help='''
|
||||||
Output coloring style (default is "{default}"). One of:
|
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.
|
The "{auto_style}" style follows your terminal's ANSI color styles.
|
||||||
|
|
||||||
@ -215,15 +264,75 @@ output_processing.add_argument(
|
|||||||
$TERM environment variable is set to "xterm-256color" or similar
|
$TERM environment variable is set to "xterm-256color" or similar
|
||||||
(e.g., via `export TERM=xterm-256color' in your ~/.bashrc).
|
(e.g., via `export TERM=xterm-256color' in your ~/.bashrc).
|
||||||
|
|
||||||
""".format(
|
'''.format(
|
||||||
default=DEFAULT_STYLE,
|
default=DEFAULT_STYLE,
|
||||||
available_styles='\n'.join(
|
available_styles='\n'.join(
|
||||||
'{0}{1}'.format(8 * ' ', line.strip())
|
f' {line.strip()}'
|
||||||
for line in wrap(', '.join(sorted(AVAILABLE_STYLES)), 60)
|
for line in wrap(', '.join(sorted(AVAILABLE_STYLES)), 60)
|
||||||
).rstrip(),
|
).strip(),
|
||||||
auto_style=AUTO_STYLE,
|
auto_style=AUTO_STYLE,
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
_sorted_kwargs = {
|
||||||
|
'action': 'append_const',
|
||||||
|
'const': SORTED_FORMAT_OPTIONS_STRING,
|
||||||
|
'dest': 'format_options'
|
||||||
|
}
|
||||||
|
_unsorted_kwargs = {
|
||||||
|
'action': 'append_const',
|
||||||
|
'const': UNSORTED_FORMAT_OPTIONS_STRING,
|
||||||
|
'dest': 'format_options'
|
||||||
|
}
|
||||||
|
# The closest approx. of the documented resetting to default via --no-<option>.
|
||||||
|
# We hide them from the doc because they act only as low-level aliases here.
|
||||||
|
output_processing.add_argument('--no-unsorted', **_sorted_kwargs, help=SUPPRESS)
|
||||||
|
output_processing.add_argument('--no-sorted', **_unsorted_kwargs, help=SUPPRESS)
|
||||||
|
|
||||||
|
output_processing.add_argument(
|
||||||
|
'--unsorted',
|
||||||
|
**_unsorted_kwargs,
|
||||||
|
help=f'''
|
||||||
|
Disables all sorting while formatting output. It is a shortcut for:
|
||||||
|
|
||||||
|
--format-options={UNSORTED_FORMAT_OPTIONS_STRING}
|
||||||
|
|
||||||
|
'''
|
||||||
|
)
|
||||||
|
output_processing.add_argument(
|
||||||
|
'--sorted',
|
||||||
|
**_sorted_kwargs,
|
||||||
|
help=f'''
|
||||||
|
Re-enables all sorting options while formatting output. It is a shortcut for:
|
||||||
|
|
||||||
|
--format-options={SORTED_FORMAT_OPTIONS_STRING}
|
||||||
|
|
||||||
|
'''
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
output_processing.add_argument(
|
||||||
|
'--format-options',
|
||||||
|
action='append',
|
||||||
|
help='''
|
||||||
|
Controls output formatting. Only relevant when formatting is enabled
|
||||||
|
through (explicit or implied) --pretty=all or --pretty=format.
|
||||||
|
The following are the default options:
|
||||||
|
|
||||||
|
{option_list}
|
||||||
|
|
||||||
|
You may use this option multiple times, as well as specify multiple
|
||||||
|
comma-separated options at the same time. For example, this modifies the
|
||||||
|
settings to disable the sorting of JSON keys, and sets the indent size to 2:
|
||||||
|
|
||||||
|
--format-options json.sort_keys:false,json.indent:2
|
||||||
|
|
||||||
|
This is something you will typically put into your config file.
|
||||||
|
|
||||||
|
'''.format(
|
||||||
|
option_list='\n'.join(
|
||||||
|
f' {option}' for option in DEFAULT_FORMAT_OPTIONS).strip()
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
#######################################################################
|
#######################################################################
|
||||||
# Output options
|
# Output options
|
||||||
@ -234,7 +343,7 @@ output_options.add_argument(
|
|||||||
'--print', '-p',
|
'--print', '-p',
|
||||||
dest='output_options',
|
dest='output_options',
|
||||||
metavar='WHAT',
|
metavar='WHAT',
|
||||||
help=f"""
|
help=f'''
|
||||||
String specifying what the output should contain:
|
String specifying what the output should contain:
|
||||||
|
|
||||||
'{OUT_REQ_HEAD}' request headers
|
'{OUT_REQ_HEAD}' request headers
|
||||||
@ -247,70 +356,70 @@ output_options.add_argument(
|
|||||||
If the output is piped to another program or to a file, then only the
|
If the output is piped to another program or to a file, then only the
|
||||||
response body is printed by default.
|
response body is printed by default.
|
||||||
|
|
||||||
"""
|
'''
|
||||||
)
|
)
|
||||||
output_options.add_argument(
|
output_options.add_argument(
|
||||||
'--headers', '-h',
|
'--headers', '-h',
|
||||||
dest='output_options',
|
dest='output_options',
|
||||||
action='store_const',
|
action='store_const',
|
||||||
const=OUT_RESP_HEAD,
|
const=OUT_RESP_HEAD,
|
||||||
help=f"""
|
help=f'''
|
||||||
Print only the response headers. Shortcut for --print={OUT_RESP_HEAD}.
|
Print only the response headers. Shortcut for --print={OUT_RESP_HEAD}.
|
||||||
|
|
||||||
"""
|
'''
|
||||||
)
|
)
|
||||||
output_options.add_argument(
|
output_options.add_argument(
|
||||||
'--body', '-b',
|
'--body', '-b',
|
||||||
dest='output_options',
|
dest='output_options',
|
||||||
action='store_const',
|
action='store_const',
|
||||||
const=OUT_RESP_BODY,
|
const=OUT_RESP_BODY,
|
||||||
help=f"""
|
help=f'''
|
||||||
Print only the response body. Shortcut for --print={OUT_RESP_BODY}.
|
Print only the response body. Shortcut for --print={OUT_RESP_BODY}.
|
||||||
|
|
||||||
"""
|
'''
|
||||||
)
|
)
|
||||||
|
|
||||||
output_options.add_argument(
|
output_options.add_argument(
|
||||||
'--verbose', '-v',
|
'--verbose', '-v',
|
||||||
dest='verbose',
|
dest='verbose',
|
||||||
action='store_true',
|
action='store_true',
|
||||||
help="""
|
help=f'''
|
||||||
Verbose output. Print the whole request as well as the response. Also print
|
Verbose output. Print the whole request as well as the response. Also print
|
||||||
any intermediary requests/responses (such as redirects).
|
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(
|
output_options.add_argument(
|
||||||
'--all',
|
'--all',
|
||||||
default=False,
|
default=False,
|
||||||
action='store_true',
|
action='store_true',
|
||||||
help="""
|
help='''
|
||||||
By default, only the final request/response is shown. Use this flag to show
|
By default, only the final request/response is shown. Use this flag to show
|
||||||
any intermediary requests/responses as well. Intermediary requests include
|
any intermediary requests/responses as well. Intermediary requests include
|
||||||
followed redirects (with --follow), the first unauthorized request when
|
followed redirects (with --follow), the first unauthorized request when
|
||||||
Digest auth is used (--auth=digest), etc.
|
Digest auth is used (--auth=digest), etc.
|
||||||
|
|
||||||
"""
|
'''
|
||||||
)
|
)
|
||||||
output_options.add_argument(
|
output_options.add_argument(
|
||||||
'--history-print', '-P',
|
'--history-print', '-P',
|
||||||
dest='output_options_history',
|
dest='output_options_history',
|
||||||
metavar='WHAT',
|
metavar='WHAT',
|
||||||
help="""
|
help='''
|
||||||
The same as --print, -p but applies only to intermediary requests/responses
|
The same as --print, -p but applies only to intermediary requests/responses
|
||||||
(such as redirects) when their inclusion is enabled with --all. If this
|
(such as redirects) when their inclusion is enabled with --all. If this
|
||||||
options is not specified, then they are formatted the same way as the final
|
options is not specified, then they are formatted the same way as the final
|
||||||
response.
|
response.
|
||||||
|
|
||||||
"""
|
'''
|
||||||
)
|
)
|
||||||
output_options.add_argument(
|
output_options.add_argument(
|
||||||
'--stream', '-S',
|
'--stream', '-S',
|
||||||
action='store_true',
|
action='store_true',
|
||||||
default=False,
|
default=False,
|
||||||
help="""
|
help='''
|
||||||
Always stream the output by line, i.e., behave like `tail -f'.
|
Always stream the response body by line, i.e., behave like `tail -f'.
|
||||||
|
|
||||||
Without --stream and with --pretty (either set or implied),
|
Without --stream and with --pretty (either set or implied),
|
||||||
HTTPie fetches the whole response before it outputs the processed data.
|
HTTPie fetches the whole response before it outputs the processed data.
|
||||||
@ -321,19 +430,19 @@ output_options.add_argument(
|
|||||||
It is useful also without --pretty: It ensures that the output is flushed
|
It is useful also without --pretty: It ensures that the output is flushed
|
||||||
more often and in smaller chunks.
|
more often and in smaller chunks.
|
||||||
|
|
||||||
"""
|
'''
|
||||||
)
|
)
|
||||||
output_options.add_argument(
|
output_options.add_argument(
|
||||||
'--output', '-o',
|
'--output', '-o',
|
||||||
type=FileType('a+b'),
|
type=FileType('a+b'),
|
||||||
dest='output_file',
|
dest='output_file',
|
||||||
metavar='FILE',
|
metavar='FILE',
|
||||||
help="""
|
help='''
|
||||||
Save output to FILE instead of stdout. If --download is also set, then only
|
Save output to FILE instead of stdout. If --download is also set, then only
|
||||||
the response body is saved to FILE. Other parts of the HTTP exchange are
|
the response body is saved to FILE. Other parts of the HTTP exchange are
|
||||||
printed to stderr.
|
printed to stderr.
|
||||||
|
|
||||||
"""
|
'''
|
||||||
|
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -341,12 +450,12 @@ output_options.add_argument(
|
|||||||
'--download', '-d',
|
'--download', '-d',
|
||||||
action='store_true',
|
action='store_true',
|
||||||
default=False,
|
default=False,
|
||||||
help="""
|
help='''
|
||||||
Do not print the response body to stdout. Rather, download it and store it
|
Do not print the response body to stdout. Rather, download it and store it
|
||||||
in a file. The filename is guessed unless specified with --output
|
in a file. The filename is guessed unless specified with --output
|
||||||
[filename]. This action is similar to the default behaviour of wget.
|
[filename]. This action is similar to the default behaviour of wget.
|
||||||
|
|
||||||
"""
|
'''
|
||||||
)
|
)
|
||||||
|
|
||||||
output_options.add_argument(
|
output_options.add_argument(
|
||||||
@ -354,11 +463,22 @@ output_options.add_argument(
|
|||||||
dest='download_resume',
|
dest='download_resume',
|
||||||
action='store_true',
|
action='store_true',
|
||||||
default=False,
|
default=False,
|
||||||
help="""
|
help='''
|
||||||
Resume an interrupted download. Note that the --output option needs to be
|
Resume an interrupted download. Note that the --output option needs to be
|
||||||
specified as well.
|
specified as well.
|
||||||
|
|
||||||
"""
|
'''
|
||||||
|
)
|
||||||
|
|
||||||
|
output_options.add_argument(
|
||||||
|
'--quiet', '-q',
|
||||||
|
action='store_true',
|
||||||
|
default=False,
|
||||||
|
help='''
|
||||||
|
Do not print to stdout or stderr.
|
||||||
|
stdout is still redirected if --output is specified.
|
||||||
|
Flag doesn't affect behaviour of download beyond not printing to terminal.
|
||||||
|
'''
|
||||||
)
|
)
|
||||||
|
|
||||||
#######################################################################
|
#######################################################################
|
||||||
@ -376,7 +496,7 @@ sessions.add_argument(
|
|||||||
'--session',
|
'--session',
|
||||||
metavar='SESSION_NAME_OR_PATH',
|
metavar='SESSION_NAME_OR_PATH',
|
||||||
type=session_name_validator,
|
type=session_name_validator,
|
||||||
help=f"""
|
help=f'''
|
||||||
Create, or reuse and update a session. Within a session, custom headers,
|
Create, or reuse and update a session. Within a session, custom headers,
|
||||||
auth credential, as well as any cookies sent by the server persist between
|
auth credential, as well as any cookies sent by the server persist between
|
||||||
requests.
|
requests.
|
||||||
@ -385,17 +505,17 @@ sessions.add_argument(
|
|||||||
|
|
||||||
{DEFAULT_SESSIONS_DIR}/<HOST>/<SESSION_NAME>.json.
|
{DEFAULT_SESSIONS_DIR}/<HOST>/<SESSION_NAME>.json.
|
||||||
|
|
||||||
"""
|
'''
|
||||||
)
|
)
|
||||||
sessions.add_argument(
|
sessions.add_argument(
|
||||||
'--session-read-only',
|
'--session-read-only',
|
||||||
metavar='SESSION_NAME_OR_PATH',
|
metavar='SESSION_NAME_OR_PATH',
|
||||||
type=session_name_validator,
|
type=session_name_validator,
|
||||||
help="""
|
help='''
|
||||||
Create or read a session without updating it form the request/response
|
Create or read a session without updating it form the request/response
|
||||||
exchange.
|
exchange.
|
||||||
|
|
||||||
"""
|
'''
|
||||||
)
|
)
|
||||||
|
|
||||||
#######################################################################
|
#######################################################################
|
||||||
@ -408,11 +528,11 @@ auth.add_argument(
|
|||||||
'--auth', '-a',
|
'--auth', '-a',
|
||||||
default=None,
|
default=None,
|
||||||
metavar='USER[:PASS]',
|
metavar='USER[:PASS]',
|
||||||
help="""
|
help='''
|
||||||
If only the username is provided (-a username), HTTPie will prompt
|
If only the username is provided (-a username), HTTPie will prompt
|
||||||
for the password.
|
for the password.
|
||||||
|
|
||||||
""",
|
''',
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@ -431,18 +551,18 @@ auth.add_argument(
|
|||||||
'--auth-type', '-A',
|
'--auth-type', '-A',
|
||||||
choices=_AuthTypeLazyChoices(),
|
choices=_AuthTypeLazyChoices(),
|
||||||
default=None,
|
default=None,
|
||||||
help="""
|
help='''
|
||||||
The authentication mechanism to be used. Defaults to "{default}".
|
The authentication mechanism to be used. Defaults to "{default}".
|
||||||
|
|
||||||
{types}
|
{types}
|
||||||
|
|
||||||
""".format(default=_auth_plugins[0].auth_type, types='\n '.join(
|
'''.format(default=_auth_plugins[0].auth_type, types='\n '.join(
|
||||||
'"{type}": {name}{package}{description}'.format(
|
'"{type}": {name}{package}{description}'.format(
|
||||||
type=plugin.auth_type,
|
type=plugin.auth_type,
|
||||||
name=plugin.name,
|
name=plugin.name,
|
||||||
package=(
|
package=(
|
||||||
'' if issubclass(plugin, BuiltinAuthPlugin)
|
'' if issubclass(plugin, BuiltinAuthPlugin)
|
||||||
else ' (provided by %s)' % plugin.package_name
|
else f' (provided by {plugin.package_name})'
|
||||||
),
|
),
|
||||||
description=(
|
description=(
|
||||||
'' if not plugin.description else
|
'' if not plugin.description else
|
||||||
@ -456,10 +576,10 @@ auth.add_argument(
|
|||||||
'--ignore-netrc',
|
'--ignore-netrc',
|
||||||
default=False,
|
default=False,
|
||||||
action='store_true',
|
action='store_true',
|
||||||
help="""
|
help='''
|
||||||
Ignore credentials from .netrc.
|
Ignore credentials from .netrc.
|
||||||
|
|
||||||
""",
|
''',
|
||||||
)
|
)
|
||||||
|
|
||||||
#######################################################################
|
#######################################################################
|
||||||
@ -472,9 +592,9 @@ network.add_argument(
|
|||||||
'--offline',
|
'--offline',
|
||||||
default=False,
|
default=False,
|
||||||
action='store_true',
|
action='store_true',
|
||||||
help="""
|
help='''
|
||||||
Build the request and print it but don’t actually send it.
|
Build the request and print it but don’t actually send it.
|
||||||
"""
|
'''
|
||||||
)
|
)
|
||||||
network.add_argument(
|
network.add_argument(
|
||||||
'--proxy',
|
'--proxy',
|
||||||
@ -482,43 +602,43 @@ network.add_argument(
|
|||||||
action='append',
|
action='append',
|
||||||
metavar='PROTOCOL:PROXY_URL',
|
metavar='PROTOCOL:PROXY_URL',
|
||||||
type=KeyValueArgType(SEPARATOR_PROXY),
|
type=KeyValueArgType(SEPARATOR_PROXY),
|
||||||
help="""
|
help='''
|
||||||
String mapping protocol to the URL of the proxy
|
String mapping protocol to the URL of the proxy
|
||||||
(e.g. http:http://foo.bar:3128). You can specify multiple proxies with
|
(e.g. http:http://foo.bar:3128). You can specify multiple proxies with
|
||||||
different protocols. The environment variables $ALL_PROXY, $HTTP_PROXY,
|
different protocols. The environment variables $ALL_PROXY, $HTTP_PROXY,
|
||||||
and $HTTPS_proxy are supported as well.
|
and $HTTPS_proxy are supported as well.
|
||||||
|
|
||||||
"""
|
'''
|
||||||
)
|
)
|
||||||
network.add_argument(
|
network.add_argument(
|
||||||
'--follow', '-F',
|
'--follow', '-F',
|
||||||
default=False,
|
default=False,
|
||||||
action='store_true',
|
action='store_true',
|
||||||
help="""
|
help='''
|
||||||
Follow 30x Location redirects.
|
Follow 30x Location redirects.
|
||||||
|
|
||||||
"""
|
'''
|
||||||
)
|
)
|
||||||
|
|
||||||
network.add_argument(
|
network.add_argument(
|
||||||
'--max-redirects',
|
'--max-redirects',
|
||||||
type=int,
|
type=int,
|
||||||
default=30,
|
default=30,
|
||||||
help="""
|
help='''
|
||||||
By default, requests have a limit of 30 redirects (works with --follow).
|
By default, requests have a limit of 30 redirects (works with --follow).
|
||||||
|
|
||||||
"""
|
'''
|
||||||
)
|
)
|
||||||
|
|
||||||
network.add_argument(
|
network.add_argument(
|
||||||
'--max-headers',
|
'--max-headers',
|
||||||
type=int,
|
type=int,
|
||||||
default=0,
|
default=0,
|
||||||
help="""
|
help='''
|
||||||
The maximum number of response headers to be read before giving up
|
The maximum number of response headers to be read before giving up
|
||||||
(default 0, i.e., no limit).
|
(default 0, i.e., no limit).
|
||||||
|
|
||||||
"""
|
'''
|
||||||
)
|
)
|
||||||
|
|
||||||
network.add_argument(
|
network.add_argument(
|
||||||
@ -526,7 +646,7 @@ network.add_argument(
|
|||||||
type=float,
|
type=float,
|
||||||
default=0,
|
default=0,
|
||||||
metavar='SECONDS',
|
metavar='SECONDS',
|
||||||
help="""
|
help='''
|
||||||
The connection timeout of the request in seconds.
|
The connection timeout of the request in seconds.
|
||||||
The default value is 0, i.e., there is no timeout limit.
|
The default value is 0, i.e., there is no timeout limit.
|
||||||
This is not a time limit on the entire response download;
|
This is not a time limit on the entire response download;
|
||||||
@ -534,13 +654,13 @@ network.add_argument(
|
|||||||
timeout seconds (more precisely, if no bytes have been received on
|
timeout seconds (more precisely, if no bytes have been received on
|
||||||
the underlying socket for timeout seconds).
|
the underlying socket for timeout seconds).
|
||||||
|
|
||||||
"""
|
'''
|
||||||
)
|
)
|
||||||
network.add_argument(
|
network.add_argument(
|
||||||
'--check-status',
|
'--check-status',
|
||||||
default=False,
|
default=False,
|
||||||
action='store_true',
|
action='store_true',
|
||||||
help="""
|
help='''
|
||||||
By default, HTTPie exits with 0 when no network or other fatal errors
|
By default, HTTPie exits with 0 when no network or other fatal errors
|
||||||
occur. This flag instructs HTTPie to also check the HTTP status code and
|
occur. This flag instructs HTTPie to also check the HTTP status code and
|
||||||
exit with an error if the status indicates one.
|
exit with an error if the status indicates one.
|
||||||
@ -550,15 +670,24 @@ network.add_argument(
|
|||||||
3xx (Redirect) and --follow hasn't been set, then the exit status is 3.
|
3xx (Redirect) and --follow hasn't been set, then the exit status is 3.
|
||||||
Also an error message is written to stderr if stdout is redirected.
|
Also an error message is written to stderr if stdout is redirected.
|
||||||
|
|
||||||
"""
|
'''
|
||||||
)
|
)
|
||||||
network.add_argument(
|
network.add_argument(
|
||||||
'--path-as-is',
|
'--path-as-is',
|
||||||
default=False,
|
default=False,
|
||||||
action='store_true',
|
action='store_true',
|
||||||
help="""
|
help='''
|
||||||
Bypass dot segment (/../ or /./) URL squashing.
|
Bypass dot segment (/../ or /./) URL squashing.
|
||||||
|
|
||||||
|
'''
|
||||||
|
)
|
||||||
|
|
||||||
|
network.add_argument(
|
||||||
|
'--chunked',
|
||||||
|
default=False,
|
||||||
|
action='store_true',
|
||||||
|
help="""
|
||||||
|
|
||||||
"""
|
"""
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -570,47 +699,58 @@ ssl = parser.add_argument_group(title='SSL')
|
|||||||
ssl.add_argument(
|
ssl.add_argument(
|
||||||
'--verify',
|
'--verify',
|
||||||
default='yes',
|
default='yes',
|
||||||
help="""
|
help='''
|
||||||
Set to "no" (or "false") to skip checking the host's SSL certificate.
|
Set to "no" (or "false") to skip checking the host's SSL certificate.
|
||||||
Defaults to "yes" ("true"). You can also pass the path to a CA_BUNDLE file
|
Defaults to "yes" ("true"). You can also pass the path to a CA_BUNDLE file
|
||||||
for private certs. (Or you can set the REQUESTS_CA_BUNDLE environment
|
for private certs. (Or you can set the REQUESTS_CA_BUNDLE environment
|
||||||
variable instead.)
|
variable instead.)
|
||||||
"""
|
'''
|
||||||
)
|
)
|
||||||
ssl.add_argument(
|
ssl.add_argument(
|
||||||
'--ssl', # TODO: Maybe something more general, such as --secure-protocol?
|
'--ssl',
|
||||||
dest='ssl_version',
|
dest='ssl_version',
|
||||||
choices=list(sorted(SSL_VERSION_ARG_MAPPING.keys())),
|
choices=sorted(AVAILABLE_SSL_VERSION_ARG_MAPPING.keys()),
|
||||||
help="""
|
help='''
|
||||||
The desired protocol version to use. This will default to
|
The desired protocol version to use. This will default to
|
||||||
SSL v2.3 which will negotiate the highest protocol that both
|
SSL v2.3 which will negotiate the highest protocol that both
|
||||||
the server and your installation of OpenSSL support. Available protocols
|
the server and your installation of OpenSSL support. Available protocols
|
||||||
may vary depending on OpenSSL installation (only the supported ones
|
may vary depending on OpenSSL installation (only the supported ones
|
||||||
are shown here).
|
are shown here).
|
||||||
|
|
||||||
"""
|
'''
|
||||||
|
)
|
||||||
|
ssl.add_argument(
|
||||||
|
'--ciphers',
|
||||||
|
help=f'''
|
||||||
|
|
||||||
|
A string in the OpenSSL cipher list format. By default, the following
|
||||||
|
is used:
|
||||||
|
|
||||||
|
{DEFAULT_SSL_CIPHERS}
|
||||||
|
|
||||||
|
'''
|
||||||
)
|
)
|
||||||
ssl.add_argument(
|
ssl.add_argument(
|
||||||
'--cert',
|
'--cert',
|
||||||
default=None,
|
default=None,
|
||||||
type=readable_file_arg,
|
type=readable_file_arg,
|
||||||
help="""
|
help='''
|
||||||
You can specify a local cert to use as client side SSL certificate.
|
You can specify a local cert to use as client side SSL certificate.
|
||||||
This file may either contain both private key and certificate or you may
|
This file may either contain both private key and certificate or you may
|
||||||
specify --cert-key separately.
|
specify --cert-key separately.
|
||||||
|
|
||||||
"""
|
'''
|
||||||
)
|
)
|
||||||
|
|
||||||
ssl.add_argument(
|
ssl.add_argument(
|
||||||
'--cert-key',
|
'--cert-key',
|
||||||
default=None,
|
default=None,
|
||||||
type=readable_file_arg,
|
type=readable_file_arg,
|
||||||
help="""
|
help='''
|
||||||
The private key to use with SSL. Only needed if --cert is given and the
|
The private key to use with SSL. Only needed if --cert is given and the
|
||||||
certificate file does not contain the private key.
|
certificate file does not contain the private key.
|
||||||
|
|
||||||
"""
|
'''
|
||||||
)
|
)
|
||||||
|
|
||||||
#######################################################################
|
#######################################################################
|
||||||
@ -623,53 +763,53 @@ troubleshooting.add_argument(
|
|||||||
'--ignore-stdin', '-I',
|
'--ignore-stdin', '-I',
|
||||||
action='store_true',
|
action='store_true',
|
||||||
default=False,
|
default=False,
|
||||||
help="""
|
help='''
|
||||||
Do not attempt to read stdin.
|
Do not attempt to read stdin.
|
||||||
|
|
||||||
"""
|
'''
|
||||||
)
|
)
|
||||||
troubleshooting.add_argument(
|
troubleshooting.add_argument(
|
||||||
'--help',
|
'--help',
|
||||||
action='help',
|
action='help',
|
||||||
default=SUPPRESS,
|
default=SUPPRESS,
|
||||||
help="""
|
help='''
|
||||||
Show this help message and exit.
|
Show this help message and exit.
|
||||||
|
|
||||||
"""
|
'''
|
||||||
)
|
)
|
||||||
troubleshooting.add_argument(
|
troubleshooting.add_argument(
|
||||||
'--version',
|
'--version',
|
||||||
action='version',
|
action='version',
|
||||||
version=__version__,
|
version=__version__,
|
||||||
help="""
|
help='''
|
||||||
Show version and exit.
|
Show version and exit.
|
||||||
|
|
||||||
"""
|
'''
|
||||||
)
|
)
|
||||||
troubleshooting.add_argument(
|
troubleshooting.add_argument(
|
||||||
'--traceback',
|
'--traceback',
|
||||||
action='store_true',
|
action='store_true',
|
||||||
default=False,
|
default=False,
|
||||||
help="""
|
help='''
|
||||||
Prints the exception traceback should one occur.
|
Prints the exception traceback should one occur.
|
||||||
|
|
||||||
"""
|
'''
|
||||||
)
|
)
|
||||||
troubleshooting.add_argument(
|
troubleshooting.add_argument(
|
||||||
'--default-scheme',
|
'--default-scheme',
|
||||||
default="http",
|
default="http",
|
||||||
help="""
|
help='''
|
||||||
The default scheme to use if not specified in the URL.
|
The default scheme to use if not specified in the URL.
|
||||||
|
|
||||||
"""
|
'''
|
||||||
)
|
)
|
||||||
troubleshooting.add_argument(
|
troubleshooting.add_argument(
|
||||||
'--debug',
|
'--debug',
|
||||||
action='store_true',
|
action='store_true',
|
||||||
default=False,
|
default=False,
|
||||||
help="""
|
help='''
|
||||||
Prints the exception traceback should one occur, as well as other
|
Prints the exception traceback should one occur, as well as other
|
||||||
information useful for debugging HTTPie itself and for reporting bugs.
|
information useful for debugging HTTPie itself and for reporting bugs.
|
||||||
|
|
||||||
"""
|
'''
|
||||||
)
|
)
|
||||||
|
@ -34,20 +34,25 @@ class MultiValueOrderedDict(OrderedDict):
|
|||||||
super().__setitem__(key, [self[key]])
|
super().__setitem__(key, [self[key]])
|
||||||
self[key].append(value)
|
self[key].append(value)
|
||||||
|
|
||||||
|
|
||||||
class RequestQueryParamsDict(MultiValueOrderedDict):
|
|
||||||
pass
|
|
||||||
|
|
||||||
|
|
||||||
class RequestDataDict(MultiValueOrderedDict):
|
|
||||||
|
|
||||||
def items(self):
|
def items(self):
|
||||||
for key, values in super(MultiValueOrderedDict, self).items():
|
for key, values in super().items():
|
||||||
if not isinstance(values, list):
|
if not isinstance(values, list):
|
||||||
values = [values]
|
values = [values]
|
||||||
for value in values:
|
for value in values:
|
||||||
yield key, value
|
yield key, value
|
||||||
|
|
||||||
|
|
||||||
|
class RequestQueryParamsDict(MultiValueOrderedDict):
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
class RequestDataDict(MultiValueOrderedDict):
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
class MultipartRequestDataDict(MultiValueOrderedDict):
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
class RequestFilesDict(RequestDataDict):
|
class RequestFilesDict(RequestDataDict):
|
||||||
pass
|
pass
|
||||||
|
@ -1,19 +1,21 @@
|
|||||||
import os
|
import os
|
||||||
from io import BytesIO
|
|
||||||
from typing import Callable, Dict, IO, List, Optional, Tuple, Union
|
from typing import Callable, Dict, IO, List, Optional, Tuple, Union
|
||||||
|
|
||||||
from httpie.cli.argtypes import KeyValueArg
|
from .argtypes import KeyValueArg
|
||||||
from httpie.cli.constants import (
|
from .constants import (
|
||||||
SEPARATOR_DATA_EMBED_FILE_CONTENTS, SEPARATOR_DATA_EMBED_RAW_JSON_FILE,
|
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_DATA_RAW_JSON, SEPARATOR_DATA_STRING, SEPARATOR_FILE_UPLOAD,
|
||||||
SEPARATOR_HEADER, SEPARATOR_HEADER_EMPTY, SEPARATOR_QUERY_PARAM,
|
SEPARATOR_FILE_UPLOAD_TYPE, SEPARATOR_HEADER, SEPARATOR_HEADER_EMPTY,
|
||||||
|
SEPARATOR_QUERY_PARAM,
|
||||||
)
|
)
|
||||||
from httpie.cli.dicts import (
|
from .dicts import (
|
||||||
RequestDataDict, RequestFilesDict, RequestHeadersDict, RequestJSONDataDict,
|
MultipartRequestDataDict, RequestDataDict, RequestFilesDict,
|
||||||
|
RequestHeadersDict, RequestJSONDataDict,
|
||||||
RequestQueryParamsDict,
|
RequestQueryParamsDict,
|
||||||
)
|
)
|
||||||
from httpie.cli.exceptions import ParseError
|
from .exceptions import ParseError
|
||||||
from httpie.utils import (get_content_type, load_json_preserve_order)
|
from ..utils import get_content_type, load_json_preserve_order
|
||||||
|
|
||||||
|
|
||||||
class RequestItems:
|
class RequestItems:
|
||||||
@ -23,6 +25,8 @@ class RequestItems:
|
|||||||
self.data = RequestDataDict() if as_form else RequestJSONDataDict()
|
self.data = RequestDataDict() if as_form else RequestJSONDataDict()
|
||||||
self.files = RequestFilesDict()
|
self.files = RequestFilesDict()
|
||||||
self.params = RequestQueryParamsDict()
|
self.params = RequestQueryParamsDict()
|
||||||
|
# To preserve the order of fields in file upload multipart requests.
|
||||||
|
self.multipart_data = MultipartRequestDataDict()
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def from_args(
|
def from_args(
|
||||||
@ -68,7 +72,11 @@ class RequestItems:
|
|||||||
|
|
||||||
for arg in request_item_args:
|
for arg in request_item_args:
|
||||||
processor_func, target_dict = rules[arg.sep]
|
processor_func, target_dict = rules[arg.sep]
|
||||||
target_dict[arg.key] = processor_func(arg)
|
value = processor_func(arg)
|
||||||
|
target_dict[arg.key] = value
|
||||||
|
|
||||||
|
if arg.sep in SEPARATORS_GROUP_MULTIPART:
|
||||||
|
instance.multipart_data[arg.key] = value
|
||||||
|
|
||||||
return instance
|
return instance
|
||||||
|
|
||||||
@ -81,13 +89,11 @@ def process_header_arg(arg: KeyValueArg) -> Optional[str]:
|
|||||||
|
|
||||||
|
|
||||||
def process_empty_header_arg(arg: KeyValueArg) -> str:
|
def process_empty_header_arg(arg: KeyValueArg) -> str:
|
||||||
if arg.value:
|
if not arg.value:
|
||||||
raise ParseError(
|
return arg.value
|
||||||
'Invalid item "%s" '
|
raise ParseError(
|
||||||
'(to specify an empty header use `Header;`)'
|
f'Invalid item {arg.orig!r} (to specify an empty header use `Header;`)'
|
||||||
% arg.orig
|
)
|
||||||
)
|
|
||||||
return arg.value
|
|
||||||
|
|
||||||
|
|
||||||
def process_query_param_arg(arg: KeyValueArg) -> str:
|
def process_query_param_arg(arg: KeyValueArg) -> str:
|
||||||
@ -95,16 +101,17 @@ def process_query_param_arg(arg: KeyValueArg) -> str:
|
|||||||
|
|
||||||
|
|
||||||
def process_file_upload_arg(arg: KeyValueArg) -> Tuple[str, IO, str]:
|
def process_file_upload_arg(arg: KeyValueArg) -> Tuple[str, IO, str]:
|
||||||
filename = arg.value
|
parts = arg.value.split(SEPARATOR_FILE_UPLOAD_TYPE)
|
||||||
|
filename = parts[0]
|
||||||
|
mime_type = parts[1] if len(parts) > 1 else None
|
||||||
try:
|
try:
|
||||||
with open(os.path.expanduser(filename), 'rb') as f:
|
f = open(os.path.expanduser(filename), 'rb')
|
||||||
contents = f.read()
|
except OSError as e:
|
||||||
except IOError as e:
|
raise ParseError(f'{arg.orig!r}: {e}')
|
||||||
raise ParseError('"%s": %s' % (arg.orig, e))
|
|
||||||
return (
|
return (
|
||||||
os.path.basename(filename),
|
os.path.basename(filename),
|
||||||
BytesIO(contents),
|
f,
|
||||||
get_content_type(filename),
|
mime_type or get_content_type(filename),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@ -132,13 +139,12 @@ def load_text_file(item: KeyValueArg) -> str:
|
|||||||
try:
|
try:
|
||||||
with open(os.path.expanduser(path), 'rb') as f:
|
with open(os.path.expanduser(path), 'rb') as f:
|
||||||
return f.read().decode()
|
return f.read().decode()
|
||||||
except IOError as e:
|
except OSError as e:
|
||||||
raise ParseError('"%s": %s' % (item.orig, e))
|
raise ParseError(f'{item.orig!r}: {e}')
|
||||||
except UnicodeDecodeError:
|
except UnicodeDecodeError:
|
||||||
raise ParseError(
|
raise ParseError(
|
||||||
'"%s": cannot embed the content of "%s",'
|
f'{item.orig!r}: cannot embed the content of {item.value!r},'
|
||||||
' not a UTF8 or ASCII-encoded text file'
|
' not a UTF-8 or ASCII-encoded text file'
|
||||||
% (item.orig, item.value)
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@ -146,4 +152,4 @@ def load_json(arg: KeyValueArg, contents: str) -> JSONType:
|
|||||||
try:
|
try:
|
||||||
return load_json_preserve_order(contents)
|
return load_json_preserve_order(contents)
|
||||||
except ValueError as e:
|
except ValueError as e:
|
||||||
raise ParseError('"%s": %s' % (arg.orig, e))
|
raise ParseError(f'{arg.orig!r}: {e}')
|
||||||
|
142
httpie/client.py
142
httpie/client.py
@ -2,33 +2,30 @@ import argparse
|
|||||||
import http.client
|
import http.client
|
||||||
import json
|
import json
|
||||||
import sys
|
import sys
|
||||||
import zlib
|
|
||||||
from contextlib import contextmanager
|
from contextlib import contextmanager
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from typing import Iterable, Union
|
from typing import Callable, Iterable, Union
|
||||||
from urllib.parse import urlparse, urlunparse
|
from urllib.parse import urlparse, urlunparse
|
||||||
|
|
||||||
import requests
|
import requests
|
||||||
from requests.adapters import HTTPAdapter
|
# noinspection PyPackageRequirements
|
||||||
|
import urllib3
|
||||||
from httpie import __version__
|
from . import __version__
|
||||||
from httpie.cli.constants import SSL_VERSION_ARG_MAPPING
|
from .cli.dicts import RequestHeadersDict
|
||||||
from httpie.cli.dicts import RequestHeadersDict
|
from .constants import UTF8
|
||||||
from httpie.plugins import plugin_manager
|
from .plugins.registry import plugin_manager
|
||||||
from httpie.sessions import get_httpie_session
|
from .sessions import get_httpie_session
|
||||||
from httpie.utils import repr_dict
|
from .ssl import AVAILABLE_SSL_VERSION_ARG_MAPPING, HTTPieHTTPSAdapter
|
||||||
|
from .uploads import (
|
||||||
|
compress_request, prepare_request_body,
|
||||||
|
get_multipart_data_and_content_type,
|
||||||
|
)
|
||||||
|
from .utils import get_expired_cookies, repr_dict
|
||||||
|
|
||||||
|
|
||||||
try:
|
urllib3.disable_warnings()
|
||||||
# noinspection PyPackageRequirements
|
|
||||||
import urllib3
|
|
||||||
# <https://urllib3.readthedocs.io/en/latest/security.html>
|
|
||||||
urllib3.disable_warnings()
|
|
||||||
except (ImportError, AttributeError):
|
|
||||||
pass
|
|
||||||
|
|
||||||
|
FORM_CONTENT_TYPE = f'application/x-www-form-urlencoded; charset={UTF8}'
|
||||||
FORM_CONTENT_TYPE = 'application/x-www-form-urlencoded; charset=utf-8'
|
|
||||||
JSON_CONTENT_TYPE = 'application/json'
|
JSON_CONTENT_TYPE = 'application/json'
|
||||||
JSON_ACCEPT = f'{JSON_CONTENT_TYPE}, */*;q=0.5'
|
JSON_ACCEPT = f'{JSON_CONTENT_TYPE}, */*;q=0.5'
|
||||||
DEFAULT_UA = f'HTTPie/{__version__}'
|
DEFAULT_UA = f'HTTPie/{__version__}'
|
||||||
@ -37,6 +34,7 @@ DEFAULT_UA = f'HTTPie/{__version__}'
|
|||||||
def collect_messages(
|
def collect_messages(
|
||||||
args: argparse.Namespace,
|
args: argparse.Namespace,
|
||||||
config_dir: Path,
|
config_dir: Path,
|
||||||
|
request_body_read_callback: Callable[[bytes], None] = None,
|
||||||
) -> Iterable[Union[requests.PreparedRequest, requests.Response]]:
|
) -> Iterable[Union[requests.PreparedRequest, requests.Response]]:
|
||||||
httpie_session = None
|
httpie_session = None
|
||||||
httpie_session_headers = None
|
httpie_session_headers = None
|
||||||
@ -52,11 +50,14 @@ def collect_messages(
|
|||||||
request_kwargs = make_request_kwargs(
|
request_kwargs = make_request_kwargs(
|
||||||
args=args,
|
args=args,
|
||||||
base_headers=httpie_session_headers,
|
base_headers=httpie_session_headers,
|
||||||
|
request_body_read_callback=request_body_read_callback
|
||||||
)
|
)
|
||||||
send_kwargs = make_send_kwargs(args)
|
send_kwargs = make_send_kwargs(args)
|
||||||
send_kwargs_mergeable_from_env = make_send_kwargs_mergeable_from_env(args)
|
send_kwargs_mergeable_from_env = make_send_kwargs_mergeable_from_env(args)
|
||||||
requests_session = build_requests_session(
|
requests_session = build_requests_session(
|
||||||
ssl_version=args.ssl_version,
|
ssl_version=args.ssl_version,
|
||||||
|
ciphers=args.ciphers,
|
||||||
|
verify=bool(send_kwargs_mergeable_from_env['verify'])
|
||||||
)
|
)
|
||||||
|
|
||||||
if httpie_session:
|
if httpie_session:
|
||||||
@ -84,8 +85,12 @@ def collect_messages(
|
|||||||
prepped_url=prepared_request.url,
|
prepped_url=prepared_request.url,
|
||||||
)
|
)
|
||||||
if args.compress and prepared_request.body:
|
if args.compress and prepared_request.body:
|
||||||
compress_body(prepared_request, always=args.compress > 1)
|
compress_request(
|
||||||
|
request=prepared_request,
|
||||||
|
always=args.compress > 1,
|
||||||
|
)
|
||||||
response_count = 0
|
response_count = 0
|
||||||
|
expired_cookies = []
|
||||||
while prepared_request:
|
while prepared_request:
|
||||||
yield prepared_request
|
yield prepared_request
|
||||||
if not args.offline:
|
if not args.offline:
|
||||||
@ -99,6 +104,11 @@ def collect_messages(
|
|||||||
**send_kwargs_merged,
|
**send_kwargs_merged,
|
||||||
**send_kwargs,
|
**send_kwargs,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
expired_cookies += get_expired_cookies(
|
||||||
|
response.headers.get('Set-Cookie', '')
|
||||||
|
)
|
||||||
|
|
||||||
response_count += 1
|
response_count += 1
|
||||||
if response.next:
|
if response.next:
|
||||||
if args.max_redirects and response_count == args.max_redirects:
|
if args.max_redirects and response_count == args.max_redirects:
|
||||||
@ -114,13 +124,18 @@ def collect_messages(
|
|||||||
if httpie_session:
|
if httpie_session:
|
||||||
if httpie_session.is_new() or not args.session_read_only:
|
if httpie_session.is_new() or not args.session_read_only:
|
||||||
httpie_session.cookies = requests_session.cookies
|
httpie_session.cookies = requests_session.cookies
|
||||||
|
httpie_session.remove_cookies(
|
||||||
|
# TODO: take path & domain into account?
|
||||||
|
cookie['name'] for cookie in expired_cookies
|
||||||
|
)
|
||||||
httpie_session.save()
|
httpie_session.save()
|
||||||
|
|
||||||
|
|
||||||
# noinspection PyProtectedMember
|
# noinspection PyProtectedMember
|
||||||
@contextmanager
|
@contextmanager
|
||||||
def max_headers(limit):
|
def max_headers(limit):
|
||||||
# <https://github.com/jakubroztocil/httpie/issues/802>
|
# <https://github.com/httpie/httpie/issues/802>
|
||||||
|
# noinspection PyUnresolvedReferences
|
||||||
orig = http.client._MAXHEADERS
|
orig = http.client._MAXHEADERS
|
||||||
http.client._MAXHEADERS = limit or float('Inf')
|
http.client._MAXHEADERS = limit or float('Inf')
|
||||||
try:
|
try:
|
||||||
@ -129,45 +144,23 @@ def max_headers(limit):
|
|||||||
http.client._MAXHEADERS = orig
|
http.client._MAXHEADERS = orig
|
||||||
|
|
||||||
|
|
||||||
def compress_body(request: requests.PreparedRequest, always: bool):
|
|
||||||
deflater = zlib.compressobj()
|
|
||||||
body_bytes = (
|
|
||||||
request.body
|
|
||||||
if isinstance(request.body, bytes)
|
|
||||||
else request.body.encode()
|
|
||||||
)
|
|
||||||
deflated_data = deflater.compress(body_bytes)
|
|
||||||
deflated_data += deflater.flush()
|
|
||||||
is_economical = len(deflated_data) < len(body_bytes)
|
|
||||||
if is_economical or always:
|
|
||||||
request.body = deflated_data
|
|
||||||
request.headers['Content-Encoding'] = 'deflate'
|
|
||||||
request.headers['Content-Length'] = str(len(deflated_data))
|
|
||||||
|
|
||||||
|
|
||||||
class HTTPieHTTPSAdapter(HTTPAdapter):
|
|
||||||
|
|
||||||
def __init__(self, ssl_version=None, **kwargs):
|
|
||||||
self._ssl_version = ssl_version
|
|
||||||
super().__init__(**kwargs)
|
|
||||||
|
|
||||||
def init_poolmanager(self, *args, **kwargs):
|
|
||||||
kwargs['ssl_version'] = self._ssl_version
|
|
||||||
super().init_poolmanager(*args, **kwargs)
|
|
||||||
|
|
||||||
|
|
||||||
def build_requests_session(
|
def build_requests_session(
|
||||||
|
verify: bool,
|
||||||
ssl_version: str = None,
|
ssl_version: str = None,
|
||||||
|
ciphers: str = None,
|
||||||
) -> requests.Session:
|
) -> requests.Session:
|
||||||
requests_session = requests.Session()
|
requests_session = requests.Session()
|
||||||
|
|
||||||
# Install our adapter.
|
# Install our adapter.
|
||||||
requests_session.mount('https://', HTTPieHTTPSAdapter(
|
https_adapter = HTTPieHTTPSAdapter(
|
||||||
|
ciphers=ciphers,
|
||||||
|
verify=verify,
|
||||||
ssl_version=(
|
ssl_version=(
|
||||||
SSL_VERSION_ARG_MAPPING[ssl_version]
|
AVAILABLE_SSL_VERSION_ARG_MAPPING[ssl_version]
|
||||||
if ssl_version else None
|
if ssl_version else None
|
||||||
)
|
),
|
||||||
))
|
)
|
||||||
|
requests_session.mount('https://', https_adapter)
|
||||||
|
|
||||||
# Install adapters from plugins.
|
# Install adapters from plugins.
|
||||||
for plugin_cls in plugin_manager.get_transport_plugins():
|
for plugin_cls in plugin_manager.get_transport_plugins():
|
||||||
@ -195,8 +188,8 @@ def finalize_headers(headers: RequestHeadersDict) -> RequestHeadersDict:
|
|||||||
# Also, requests raises `InvalidHeader` for leading spaces.
|
# Also, requests raises `InvalidHeader` for leading spaces.
|
||||||
value = value.strip()
|
value = value.strip()
|
||||||
if isinstance(value, str):
|
if isinstance(value, str):
|
||||||
# See <https://github.com/jakubroztocil/httpie/issues/212>
|
# See <https://github.com/httpie/httpie/issues/212>
|
||||||
value = value.encode('utf8')
|
value = value.encode()
|
||||||
final_headers[name] = value
|
final_headers[name] = value
|
||||||
return final_headers
|
return final_headers
|
||||||
|
|
||||||
@ -220,11 +213,10 @@ def make_default_headers(args: argparse.Namespace) -> RequestHeadersDict:
|
|||||||
|
|
||||||
|
|
||||||
def make_send_kwargs(args: argparse.Namespace) -> dict:
|
def make_send_kwargs(args: argparse.Namespace) -> dict:
|
||||||
kwargs = {
|
return {
|
||||||
'timeout': args.timeout or None,
|
'timeout': args.timeout or None,
|
||||||
'allow_redirects': False,
|
'allow_redirects': False,
|
||||||
}
|
}
|
||||||
return kwargs
|
|
||||||
|
|
||||||
|
|
||||||
def make_send_kwargs_mergeable_from_env(args: argparse.Namespace) -> dict:
|
def make_send_kwargs_mergeable_from_env(args: argparse.Namespace) -> dict:
|
||||||
@ -233,7 +225,7 @@ def make_send_kwargs_mergeable_from_env(args: argparse.Namespace) -> dict:
|
|||||||
cert = args.cert
|
cert = args.cert
|
||||||
if args.cert_key:
|
if args.cert_key:
|
||||||
cert = cert, args.cert_key
|
cert = cert, args.cert_key
|
||||||
kwargs = {
|
return {
|
||||||
'proxies': {p.key: p.value for p in args.proxy},
|
'proxies': {p.key: p.value for p in args.proxy},
|
||||||
'stream': True,
|
'stream': True,
|
||||||
'verify': {
|
'verify': {
|
||||||
@ -244,17 +236,18 @@ def make_send_kwargs_mergeable_from_env(args: argparse.Namespace) -> dict:
|
|||||||
}.get(args.verify.lower(), args.verify),
|
}.get(args.verify.lower(), args.verify),
|
||||||
'cert': cert,
|
'cert': cert,
|
||||||
}
|
}
|
||||||
return kwargs
|
|
||||||
|
|
||||||
|
|
||||||
def make_request_kwargs(
|
def make_request_kwargs(
|
||||||
args: argparse.Namespace,
|
args: argparse.Namespace,
|
||||||
base_headers: RequestHeadersDict = None
|
base_headers: RequestHeadersDict = None,
|
||||||
|
request_body_read_callback=lambda chunk: chunk
|
||||||
) -> dict:
|
) -> dict:
|
||||||
"""
|
"""
|
||||||
Translate our `args` into `requests.Request` keyword arguments.
|
Translate our `args` into `requests.Request` keyword arguments.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
files = args.files
|
||||||
# Serialize JSON data, if needed.
|
# Serialize JSON data, if needed.
|
||||||
data = args.data
|
data = args.data
|
||||||
auto_json = data and not args.form
|
auto_json = data and not args.form
|
||||||
@ -271,20 +264,34 @@ def make_request_kwargs(
|
|||||||
if base_headers:
|
if base_headers:
|
||||||
headers.update(base_headers)
|
headers.update(base_headers)
|
||||||
headers.update(args.headers)
|
headers.update(args.headers)
|
||||||
|
if args.offline and args.chunked and 'Transfer-Encoding' not in headers:
|
||||||
|
# When online, we let requests set the header instead to be able more
|
||||||
|
# easily verify chunking is taking place.
|
||||||
|
headers['Transfer-Encoding'] = 'chunked'
|
||||||
headers = finalize_headers(headers)
|
headers = finalize_headers(headers)
|
||||||
|
|
||||||
kwargs = {
|
if (args.form and files) or args.multipart:
|
||||||
|
data, headers['Content-Type'] = get_multipart_data_and_content_type(
|
||||||
|
data=args.multipart_data,
|
||||||
|
boundary=args.boundary,
|
||||||
|
content_type=args.headers.get('Content-Type'),
|
||||||
|
)
|
||||||
|
|
||||||
|
return {
|
||||||
'method': args.method.lower(),
|
'method': args.method.lower(),
|
||||||
'url': args.url,
|
'url': args.url,
|
||||||
'headers': headers,
|
'headers': headers,
|
||||||
'data': data,
|
'data': prepare_request_body(
|
||||||
|
body=data,
|
||||||
|
body_read_callback=request_body_read_callback,
|
||||||
|
chunked=args.chunked,
|
||||||
|
offline=args.offline,
|
||||||
|
content_length_header_value=headers.get('Content-Length'),
|
||||||
|
),
|
||||||
'auth': args.auth,
|
'auth': args.auth,
|
||||||
'params': args.params,
|
'params': args.params.items(),
|
||||||
'files': args.files,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return kwargs
|
|
||||||
|
|
||||||
|
|
||||||
def ensure_path_as_is(orig_url: str, prepped_url: str) -> str:
|
def ensure_path_as_is(orig_url: str, prepped_url: str) -> str:
|
||||||
"""
|
"""
|
||||||
@ -293,7 +300,7 @@ def ensure_path_as_is(orig_url: str, prepped_url: str) -> str:
|
|||||||
untouched because other (welcome) processing on the URL might have
|
untouched because other (welcome) processing on the URL might have
|
||||||
taken place.
|
taken place.
|
||||||
|
|
||||||
<https://github.com/jakubroztocil/httpie/issues/895>
|
<https://github.com/httpie/httpie/issues/895>
|
||||||
|
|
||||||
|
|
||||||
<https://ec.haxx.se/http/http-basics#path-as-is>
|
<https://ec.haxx.se/http/http-basics#path-as-is>
|
||||||
@ -309,5 +316,4 @@ def ensure_path_as_is(orig_url: str, prepped_url: str) -> str:
|
|||||||
**parsed_prepped._asdict(),
|
**parsed_prepped._asdict(),
|
||||||
'path': parsed_orig.path,
|
'path': parsed_orig.path,
|
||||||
}
|
}
|
||||||
final_url = urlunparse(tuple(final_dict.values()))
|
return urlunparse(tuple(final_dict.values()))
|
||||||
return final_url
|
|
||||||
|
103
httpie/config.py
103
httpie/config.py
@ -1,18 +1,61 @@
|
|||||||
import errno
|
|
||||||
import json
|
import json
|
||||||
import os
|
import os
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from typing import Union
|
from typing import Union
|
||||||
|
|
||||||
from httpie import __version__
|
from . import __version__
|
||||||
from httpie.compat import is_windows
|
from .compat import is_windows
|
||||||
|
from .constants import UTF8
|
||||||
|
|
||||||
|
|
||||||
DEFAULT_CONFIG_DIR = Path(os.environ.get(
|
ENV_XDG_CONFIG_HOME = 'XDG_CONFIG_HOME'
|
||||||
'HTTPIE_CONFIG_DIR',
|
ENV_HTTPIE_CONFIG_DIR = 'HTTPIE_CONFIG_DIR'
|
||||||
os.path.expanduser('~/.httpie') if not is_windows else
|
DEFAULT_CONFIG_DIRNAME = 'httpie'
|
||||||
os.path.expandvars(r'%APPDATA%\\httpie')
|
DEFAULT_RELATIVE_XDG_CONFIG_HOME = Path('.config')
|
||||||
))
|
DEFAULT_RELATIVE_LEGACY_CONFIG_DIR = Path('.httpie')
|
||||||
|
DEFAULT_WINDOWS_CONFIG_DIR = Path(
|
||||||
|
os.path.expandvars('%APPDATA%')) / DEFAULT_CONFIG_DIRNAME
|
||||||
|
|
||||||
|
|
||||||
|
def get_default_config_dir() -> Path:
|
||||||
|
"""
|
||||||
|
Return the path to the httpie configuration directory.
|
||||||
|
|
||||||
|
This directory isn't guaranteed to exist, and nor are any of its
|
||||||
|
ancestors (only the legacy ~/.httpie, if returned, is guaranteed to exist).
|
||||||
|
|
||||||
|
XDG Base Directory Specification support:
|
||||||
|
|
||||||
|
<https://wiki.archlinux.org/index.php/XDG_Base_Directory>
|
||||||
|
|
||||||
|
$XDG_CONFIG_HOME is supported; $XDG_CONFIG_DIRS is not
|
||||||
|
|
||||||
|
"""
|
||||||
|
# 1. explicitly set through env
|
||||||
|
env_config_dir = os.environ.get(ENV_HTTPIE_CONFIG_DIR)
|
||||||
|
if env_config_dir:
|
||||||
|
return Path(env_config_dir)
|
||||||
|
|
||||||
|
# 2. Windows
|
||||||
|
if is_windows:
|
||||||
|
return DEFAULT_WINDOWS_CONFIG_DIR
|
||||||
|
|
||||||
|
home_dir = Path.home()
|
||||||
|
|
||||||
|
# 3. legacy ~/.httpie
|
||||||
|
legacy_config_dir = home_dir / DEFAULT_RELATIVE_LEGACY_CONFIG_DIR
|
||||||
|
if legacy_config_dir.exists():
|
||||||
|
return legacy_config_dir
|
||||||
|
|
||||||
|
# 4. XDG
|
||||||
|
xdg_config_home_dir = os.environ.get(
|
||||||
|
ENV_XDG_CONFIG_HOME, # 4.1. explicit
|
||||||
|
home_dir / DEFAULT_RELATIVE_XDG_CONFIG_HOME # 4.2. default
|
||||||
|
)
|
||||||
|
return Path(xdg_config_home_dir) / DEFAULT_CONFIG_DIRNAME
|
||||||
|
|
||||||
|
|
||||||
|
DEFAULT_CONFIG_DIR = get_default_config_dir()
|
||||||
|
|
||||||
|
|
||||||
class ConfigFileError(Exception):
|
class ConfigFileError(Exception):
|
||||||
@ -29,11 +72,7 @@ class BaseConfigDict(dict):
|
|||||||
self.path = path
|
self.path = path
|
||||||
|
|
||||||
def ensure_directory(self):
|
def ensure_directory(self):
|
||||||
try:
|
self.path.parent.mkdir(mode=0o700, parents=True, exist_ok=True)
|
||||||
self.path.parent.mkdir(mode=0o700, parents=True)
|
|
||||||
except OSError as e:
|
|
||||||
if e.errno != errno.EEXIST:
|
|
||||||
raise
|
|
||||||
|
|
||||||
def is_new(self) -> bool:
|
def is_new(self) -> bool:
|
||||||
return not self.path.exists()
|
return not self.path.exists()
|
||||||
@ -41,7 +80,7 @@ class BaseConfigDict(dict):
|
|||||||
def load(self):
|
def load(self):
|
||||||
config_type = type(self).__name__.lower()
|
config_type = type(self).__name__.lower()
|
||||||
try:
|
try:
|
||||||
with self.path.open('rt') as f:
|
with self.path.open(encoding=UTF8) as f:
|
||||||
try:
|
try:
|
||||||
data = json.load(f)
|
data = json.load(f)
|
||||||
except ValueError as e:
|
except ValueError as e:
|
||||||
@ -49,11 +88,12 @@ class BaseConfigDict(dict):
|
|||||||
f'invalid {config_type} file: {e} [{self.path}]'
|
f'invalid {config_type} file: {e} [{self.path}]'
|
||||||
)
|
)
|
||||||
self.update(data)
|
self.update(data)
|
||||||
except IOError as e:
|
except FileNotFoundError:
|
||||||
if e.errno != errno.ENOENT:
|
pass
|
||||||
raise ConfigFileError(f'cannot read {config_type} file: {e}')
|
except OSError as e:
|
||||||
|
raise ConfigFileError(f'cannot read {config_type} file: {e}')
|
||||||
|
|
||||||
def save(self, fail_silently=False):
|
def save(self):
|
||||||
self['__meta__'] = {
|
self['__meta__'] = {
|
||||||
'httpie': __version__
|
'httpie': __version__
|
||||||
}
|
}
|
||||||
@ -65,26 +105,13 @@ class BaseConfigDict(dict):
|
|||||||
|
|
||||||
self.ensure_directory()
|
self.ensure_directory()
|
||||||
|
|
||||||
try:
|
json_string = json.dumps(
|
||||||
with self.path.open('w') as f:
|
obj=self,
|
||||||
json.dump(
|
indent=4,
|
||||||
obj=self,
|
sort_keys=True,
|
||||||
fp=f,
|
ensure_ascii=True,
|
||||||
indent=4,
|
)
|
||||||
sort_keys=True,
|
self.path.write_text(json_string + '\n', encoding=UTF8)
|
||||||
ensure_ascii=True,
|
|
||||||
)
|
|
||||||
f.write('\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
|
|
||||||
|
|
||||||
|
|
||||||
class Config(BaseConfigDict):
|
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'
|
@ -1,4 +1,5 @@
|
|||||||
import sys
|
import sys
|
||||||
|
import os
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from typing import IO, Optional
|
from typing import IO, Optional
|
||||||
|
|
||||||
@ -8,10 +9,11 @@ try:
|
|||||||
except ImportError:
|
except ImportError:
|
||||||
curses = None # Compiled w/o curses
|
curses = None # Compiled w/o curses
|
||||||
|
|
||||||
from httpie.compat import is_windows
|
from .compat import is_windows
|
||||||
from httpie.config import DEFAULT_CONFIG_DIR, Config, ConfigFileError
|
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:
|
class Environment:
|
||||||
@ -56,7 +58,7 @@ class Environment:
|
|||||||
)
|
)
|
||||||
del colorama
|
del colorama
|
||||||
|
|
||||||
def __init__(self, **kwargs):
|
def __init__(self, devnull=None, **kwargs):
|
||||||
"""
|
"""
|
||||||
Use keyword arguments to overwrite
|
Use keyword arguments to overwrite
|
||||||
any of the class attributes for this instance.
|
any of the class attributes for this instance.
|
||||||
@ -65,10 +67,14 @@ class Environment:
|
|||||||
assert all(hasattr(type(self), attr) for attr in kwargs.keys())
|
assert all(hasattr(type(self), attr) for attr in kwargs.keys())
|
||||||
self.__dict__.update(**kwargs)
|
self.__dict__.update(**kwargs)
|
||||||
|
|
||||||
# Keyword arguments > stream.encoding > default utf8
|
# The original STDERR unaffected by --quiet’ing.
|
||||||
|
self._orig_stderr = self.stderr
|
||||||
|
self._devnull = devnull
|
||||||
|
|
||||||
|
# Keyword arguments > stream.encoding > default UTF-8
|
||||||
if self.stdin and self.stdin_encoding is None:
|
if self.stdin and self.stdin_encoding is None:
|
||||||
self.stdin_encoding = getattr(
|
self.stdin_encoding = getattr(
|
||||||
self.stdin, 'encoding', None) or 'utf8'
|
self.stdin, 'encoding', None) or UTF8
|
||||||
if self.stdout_encoding is None:
|
if self.stdout_encoding is None:
|
||||||
actual_stdout = self.stdout
|
actual_stdout = self.stdout
|
||||||
if is_windows:
|
if is_windows:
|
||||||
@ -78,7 +84,7 @@ class Environment:
|
|||||||
# noinspection PyUnresolvedReferences
|
# noinspection PyUnresolvedReferences
|
||||||
actual_stdout = self.stdout.wrapped
|
actual_stdout = self.stdout.wrapped
|
||||||
self.stdout_encoding = getattr(
|
self.stdout_encoding = getattr(
|
||||||
actual_stdout, 'encoding', None) or 'utf8'
|
actual_stdout, 'encoding', None) or UTF8
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
defaults = dict(type(self).__dict__)
|
defaults = dict(type(self).__dict__)
|
||||||
@ -108,6 +114,12 @@ class Environment:
|
|||||||
self.log_error(e, level='warning')
|
self.log_error(e, level='warning')
|
||||||
return config
|
return config
|
||||||
|
|
||||||
|
@property
|
||||||
|
def devnull(self) -> IO:
|
||||||
|
if self._devnull is None:
|
||||||
|
self._devnull = open(os.devnull, 'w+')
|
||||||
|
return self._devnull
|
||||||
|
|
||||||
def log_error(self, msg, level='error'):
|
def log_error(self, msg, level='error'):
|
||||||
assert level in ['error', 'warning']
|
assert level in ['error', 'warning']
|
||||||
self.stderr.write(f'\n{self.program_name}: {level}: {msg}\n\n')
|
self._orig_stderr.write(f'\n{self.program_name}: {level}: {msg}\n\n')
|
||||||
|
138
httpie/core.py
138
httpie/core.py
@ -2,25 +2,24 @@ import argparse
|
|||||||
import os
|
import os
|
||||||
import platform
|
import platform
|
||||||
import sys
|
import sys
|
||||||
from typing import List, Union
|
from typing import List, Optional, Tuple, Union
|
||||||
|
|
||||||
import requests
|
import requests
|
||||||
from pygments import __version__ as pygments_version
|
from pygments import __version__ as pygments_version
|
||||||
from requests import __version__ as requests_version
|
from requests import __version__ as requests_version
|
||||||
|
|
||||||
from httpie import __version__ as httpie_version
|
from . import __version__ as httpie_version
|
||||||
from httpie.client import collect_messages
|
from .cli.constants import OUT_REQ_BODY, OUT_REQ_HEAD, OUT_RESP_BODY, OUT_RESP_HEAD
|
||||||
from httpie.context import Environment
|
from .client import collect_messages
|
||||||
from httpie.downloads import Downloader
|
from .context import Environment
|
||||||
from httpie.output.writer import write_message, write_stream
|
from .downloads import Downloader
|
||||||
from httpie.plugins import plugin_manager
|
from .output.writer import write_message, write_stream, MESSAGE_SEPARATOR_BYTES
|
||||||
from httpie.status import ExitStatus, http_status_to_exit_status
|
from .plugins.registry import plugin_manager
|
||||||
|
from .status import ExitStatus, http_status_to_exit_status
|
||||||
|
|
||||||
|
|
||||||
def main(
|
# noinspection PyDefaultArgument
|
||||||
args: List[Union[str, bytes]] = sys.argv,
|
def main(args: List[Union[str, bytes]] = sys.argv, env=Environment()) -> ExitStatus:
|
||||||
env=Environment(),
|
|
||||||
) -> ExitStatus:
|
|
||||||
"""
|
"""
|
||||||
The main function.
|
The main function.
|
||||||
|
|
||||||
@ -35,7 +34,7 @@ def main(
|
|||||||
args = decode_raw_args(args, env.stdin_encoding)
|
args = decode_raw_args(args, env.stdin_encoding)
|
||||||
plugin_manager.load_installed_plugins()
|
plugin_manager.load_installed_plugins()
|
||||||
|
|
||||||
from httpie.cli.definition import parser
|
from .cli.definition import parser
|
||||||
|
|
||||||
if env.config.default_options:
|
if env.config.default_options:
|
||||||
args = env.config.default_options + args
|
args = env.config.default_options + args
|
||||||
@ -110,80 +109,111 @@ def main(
|
|||||||
return exit_status
|
return exit_status
|
||||||
|
|
||||||
|
|
||||||
def program(
|
def get_output_options(
|
||||||
args: argparse.Namespace,
|
args: argparse.Namespace,
|
||||||
env: Environment,
|
message: Union[requests.PreparedRequest, requests.Response]
|
||||||
) -> ExitStatus:
|
) -> Tuple[bool, bool]:
|
||||||
|
return {
|
||||||
|
requests.PreparedRequest: (
|
||||||
|
OUT_REQ_HEAD in args.output_options,
|
||||||
|
OUT_REQ_BODY in args.output_options,
|
||||||
|
),
|
||||||
|
requests.Response: (
|
||||||
|
OUT_RESP_HEAD in args.output_options,
|
||||||
|
OUT_RESP_BODY in args.output_options,
|
||||||
|
),
|
||||||
|
}[type(message)]
|
||||||
|
|
||||||
|
|
||||||
|
def program(args: argparse.Namespace, env: Environment) -> ExitStatus:
|
||||||
"""
|
"""
|
||||||
The main program without error handling.
|
The main program without error handling.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
# TODO: Refactor and drastically simplify, especially so that the separator logic is elsewhere.
|
||||||
exit_status = ExitStatus.SUCCESS
|
exit_status = ExitStatus.SUCCESS
|
||||||
downloader = None
|
downloader = None
|
||||||
|
initial_request: Optional[requests.PreparedRequest] = None
|
||||||
|
final_response: Optional[requests.Response] = None
|
||||||
|
|
||||||
|
def separate():
|
||||||
|
getattr(env.stdout, 'buffer', env.stdout).write(MESSAGE_SEPARATOR_BYTES)
|
||||||
|
|
||||||
|
def request_body_read_callback(chunk: bytes):
|
||||||
|
should_pipe_to_stdout = bool(
|
||||||
|
# Request body output desired
|
||||||
|
OUT_REQ_BODY in args.output_options
|
||||||
|
# & not `.read()` already pre-request (e.g., for compression)
|
||||||
|
and initial_request
|
||||||
|
# & non-EOF chunk
|
||||||
|
and chunk
|
||||||
|
)
|
||||||
|
if should_pipe_to_stdout:
|
||||||
|
msg = requests.PreparedRequest()
|
||||||
|
msg.is_body_upload_chunk = True
|
||||||
|
msg.body = chunk
|
||||||
|
msg.headers = initial_request.headers
|
||||||
|
write_message(requests_message=msg, env=env, args=args, with_body=True, with_headers=False)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
if args.download:
|
if args.download:
|
||||||
args.follow = True # --download implies --follow.
|
args.follow = True # --download implies --follow.
|
||||||
downloader = Downloader(
|
downloader = Downloader(output_file=args.output_file, progress_file=env.stderr, resume=args.download_resume)
|
||||||
output_file=args.output_file,
|
|
||||||
progress_file=env.stderr,
|
|
||||||
resume=args.download_resume
|
|
||||||
)
|
|
||||||
downloader.pre_request(args.headers)
|
downloader.pre_request(args.headers)
|
||||||
|
messages = collect_messages(args=args, config_dir=env.config.directory,
|
||||||
|
request_body_read_callback=request_body_read_callback)
|
||||||
|
force_separator = False
|
||||||
|
prev_with_body = False
|
||||||
|
|
||||||
initial_request = None
|
# Process messages as they’re generated
|
||||||
final_response = None
|
for message in messages:
|
||||||
|
is_request = isinstance(message, requests.PreparedRequest)
|
||||||
for message in collect_messages(args, env.config.directory):
|
with_headers, with_body = get_output_options(args=args, message=message)
|
||||||
write_message(
|
do_write_body = with_body
|
||||||
requests_message=message,
|
if prev_with_body and (with_headers or with_body) and (force_separator or not env.stdout_isatty):
|
||||||
env=env,
|
# Separate after a previous message with body, if needed. See test_tokens.py.
|
||||||
args=args,
|
separate()
|
||||||
)
|
force_separator = False
|
||||||
if isinstance(message, requests.PreparedRequest):
|
if is_request:
|
||||||
if not initial_request:
|
if not initial_request:
|
||||||
initial_request = message
|
initial_request = message
|
||||||
|
if with_body:
|
||||||
|
is_streamed_upload = not isinstance(message.body, (str, bytes))
|
||||||
|
do_write_body = not is_streamed_upload
|
||||||
|
force_separator = is_streamed_upload and env.stdout_isatty
|
||||||
else:
|
else:
|
||||||
final_response = message
|
final_response = message
|
||||||
if args.check_status or downloader:
|
if args.check_status or downloader:
|
||||||
exit_status = http_status_to_exit_status(
|
exit_status = http_status_to_exit_status(http_status=message.status_code, follow=args.follow)
|
||||||
http_status=message.status_code,
|
if exit_status != ExitStatus.SUCCESS and (not env.stdout_isatty or args.quiet):
|
||||||
follow=args.follow
|
env.log_error(f'HTTP {message.raw.status} {message.raw.reason}', level='warning')
|
||||||
)
|
write_message(requests_message=message, env=env, args=args, with_headers=with_headers,
|
||||||
if (not env.stdout_isatty
|
with_body=do_write_body)
|
||||||
and exit_status != ExitStatus.SUCCESS):
|
prev_with_body = with_body
|
||||||
env.log_error(
|
|
||||||
f'HTTP {message.raw.status} {message.raw.reason}',
|
|
||||||
level='warning'
|
|
||||||
)
|
|
||||||
|
|
||||||
|
# Cleanup
|
||||||
|
if force_separator:
|
||||||
|
separate()
|
||||||
if downloader and exit_status == ExitStatus.SUCCESS:
|
if downloader and exit_status == ExitStatus.SUCCESS:
|
||||||
# Last response body download.
|
# Last response body download.
|
||||||
download_stream, download_to = downloader.start(
|
download_stream, download_to = downloader.start(
|
||||||
initial_url=initial_request.url,
|
initial_url=initial_request.url,
|
||||||
final_response=final_response,
|
final_response=final_response,
|
||||||
)
|
)
|
||||||
write_stream(
|
write_stream(stream=download_stream, outfile=download_to, flush=False)
|
||||||
stream=download_stream,
|
|
||||||
outfile=download_to,
|
|
||||||
flush=False,
|
|
||||||
)
|
|
||||||
downloader.finish()
|
downloader.finish()
|
||||||
if downloader.interrupted:
|
if downloader.interrupted:
|
||||||
exit_status = ExitStatus.ERROR
|
exit_status = ExitStatus.ERROR
|
||||||
env.log_error(
|
env.log_error(
|
||||||
'Incomplete download: size=%d; downloaded=%d' % (
|
f'Incomplete download: size={downloader.status.total_size};'
|
||||||
downloader.status.total_size,
|
f' downloaded={downloader.status.downloaded}'
|
||||||
downloader.status.downloaded
|
)
|
||||||
))
|
|
||||||
return exit_status
|
return exit_status
|
||||||
|
|
||||||
finally:
|
finally:
|
||||||
if downloader and not downloader.finished:
|
if downloader and not downloader.finished:
|
||||||
downloader.failed()
|
downloader.failed()
|
||||||
|
if args.output_file and args.output_file_specified:
|
||||||
if (not isinstance(args, list) and args.output_file
|
|
||||||
and args.output_file_specified):
|
|
||||||
args.output_file.close()
|
args.output_file.close()
|
||||||
|
|
||||||
|
|
||||||
@ -211,6 +241,6 @@ def decode_raw_args(
|
|||||||
"""
|
"""
|
||||||
return [
|
return [
|
||||||
arg.decode(stdin_encoding)
|
arg.decode(stdin_encoding)
|
||||||
if type(arg) == bytes else arg
|
if type(arg) is bytes else arg
|
||||||
for arg in args
|
for arg in args
|
||||||
]
|
]
|
||||||
|
@ -1,26 +1,22 @@
|
|||||||
# coding=utf-8
|
|
||||||
"""
|
"""
|
||||||
Download mode implementation.
|
Download mode implementation.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
from __future__ import division
|
|
||||||
|
|
||||||
import errno
|
|
||||||
import mimetypes
|
import mimetypes
|
||||||
import os
|
import os
|
||||||
import re
|
import re
|
||||||
import sys
|
import sys
|
||||||
import threading
|
import threading
|
||||||
from mailbox import Message
|
from mailbox import Message
|
||||||
from time import sleep, time
|
from time import sleep, monotonic
|
||||||
from typing import IO, Optional, Tuple
|
from typing import IO, Optional, Tuple
|
||||||
from urllib.parse import urlsplit
|
from urllib.parse import urlsplit
|
||||||
|
|
||||||
import requests
|
import requests
|
||||||
|
|
||||||
from httpie.models import HTTPResponse
|
from .models import HTTPResponse
|
||||||
from httpie.output.streams import RawStream
|
from .output.streams import RawStream
|
||||||
from httpie.utils import humanize_bytes
|
from .utils import humanize_bytes
|
||||||
|
|
||||||
|
|
||||||
PARTIAL_CONTENT = 206
|
PARTIAL_CONTENT = 206
|
||||||
@ -64,7 +60,7 @@ def parse_content_range(content_range: str, resumed_from: int) -> int:
|
|||||||
|
|
||||||
if not match:
|
if not match:
|
||||||
raise ContentRangeError(
|
raise ContentRangeError(
|
||||||
'Invalid Content-Range format %r' % content_range)
|
f'Invalid Content-Range format {content_range!r}')
|
||||||
|
|
||||||
content_range_dict = match.groupdict()
|
content_range_dict = match.groupdict()
|
||||||
first_byte_pos = int(content_range_dict['first_byte_pos'])
|
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
|
# last-byte-pos value, is invalid. The recipient of an invalid
|
||||||
# byte-content-range- spec MUST ignore it and any content
|
# byte-content-range- spec MUST ignore it and any content
|
||||||
# transferred along with it."
|
# transferred along with it."
|
||||||
if (first_byte_pos >= last_byte_pos
|
if (first_byte_pos > last_byte_pos
|
||||||
or (instance_length is not None
|
or (instance_length is not None
|
||||||
and instance_length <= last_byte_pos)):
|
and instance_length <= last_byte_pos)):
|
||||||
raise ContentRangeError(
|
raise ContentRangeError(
|
||||||
'Invalid Content-Range returned: %r' % content_range)
|
f'Invalid Content-Range returned: {content_range!r}')
|
||||||
|
|
||||||
if (first_byte_pos != resumed_from
|
if (first_byte_pos != resumed_from
|
||||||
or (instance_length is not None
|
or (instance_length is not None
|
||||||
and last_byte_pos + 1 != instance_length)):
|
and last_byte_pos + 1 != instance_length)):
|
||||||
# Not what we asked for.
|
# Not what we asked for.
|
||||||
raise ContentRangeError(
|
raise ContentRangeError(
|
||||||
'Unexpected Content-Range returned (%r)'
|
f'Unexpected Content-Range returned ({content_range!r})'
|
||||||
' for the requested Range ("bytes=%d-")'
|
f' for the requested Range ("bytes={resumed_from}-")'
|
||||||
% (content_range, resumed_from)
|
|
||||||
)
|
)
|
||||||
|
|
||||||
return last_byte_pos + 1
|
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
|
# 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()
|
filename = msg.get_filename()
|
||||||
if filename:
|
if filename:
|
||||||
# Basic sanitation.
|
# Basic sanitation.
|
||||||
@ -132,7 +127,7 @@ def filename_from_url(url: str, content_type: Optional[str]) -> str:
|
|||||||
else:
|
else:
|
||||||
ext = mimetypes.guess_extension(content_type)
|
ext = mimetypes.guess_extension(content_type)
|
||||||
|
|
||||||
if ext == '.htm': # Python 3
|
if ext == '.htm':
|
||||||
ext = '.html'
|
ext = '.html'
|
||||||
|
|
||||||
if ext:
|
if ext:
|
||||||
@ -154,16 +149,8 @@ def trim_filename(filename: str, max_len: int) -> str:
|
|||||||
|
|
||||||
def get_filename_max_length(directory: str) -> int:
|
def get_filename_max_length(directory: str) -> int:
|
||||||
max_len = 255
|
max_len = 255
|
||||||
try:
|
if hasattr(os, 'pathconf') and 'PC_NAME_MAX' in os.pathconf_names:
|
||||||
pathconf = os.pathconf
|
max_len = os.pathconf(directory, 'PC_NAME_MAX')
|
||||||
except AttributeError:
|
|
||||||
pass # non-posix
|
|
||||||
else:
|
|
||||||
try:
|
|
||||||
max_len = pathconf(directory, 'PC_NAME_MAX')
|
|
||||||
except OSError as e:
|
|
||||||
if e.errno != errno.EINVAL:
|
|
||||||
raise
|
|
||||||
return max_len
|
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:
|
def get_unique_filename(filename: str, exists=os.path.exists) -> str:
|
||||||
attempt = 0
|
attempt = 0
|
||||||
while True:
|
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 = trim_filename_if_needed(filename, extra=len(suffix))
|
||||||
try_filename += suffix
|
try_filename += suffix
|
||||||
if not exists(try_filename):
|
if not exists(try_filename):
|
||||||
@ -226,7 +213,7 @@ class Downloader:
|
|||||||
if bytes_have:
|
if bytes_have:
|
||||||
# Set ``Range`` header to resume the download
|
# Set ``Range`` header to resume the download
|
||||||
# TODO: Use "If-Range: mtime" to make sure it's fresh?
|
# 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
|
self._resumed_from = bytes_have
|
||||||
|
|
||||||
def start(
|
def start(
|
||||||
@ -247,7 +234,7 @@ class Downloader:
|
|||||||
assert not self.status.time_started
|
assert not self.status.time_started
|
||||||
|
|
||||||
# FIXME: some servers still might sent Content-Encoding: gzip
|
# FIXME: some servers still might sent Content-Encoding: gzip
|
||||||
# <https://github.com/jakubroztocil/httpie/issues/423>
|
# <https://github.com/httpie/httpie/issues/423>
|
||||||
try:
|
try:
|
||||||
total_size = int(final_response.headers['Content-Length'])
|
total_size = int(final_response.headers['Content-Length'])
|
||||||
except (KeyError, ValueError, TypeError):
|
except (KeyError, ValueError, TypeError):
|
||||||
@ -271,7 +258,7 @@ class Downloader:
|
|||||||
try:
|
try:
|
||||||
self._output_file.seek(0)
|
self._output_file.seek(0)
|
||||||
self._output_file.truncate()
|
self._output_file.truncate()
|
||||||
except IOError:
|
except OSError:
|
||||||
pass # stdout
|
pass # stdout
|
||||||
|
|
||||||
self.status.started(
|
self.status.started(
|
||||||
@ -288,12 +275,8 @@ class Downloader:
|
|||||||
)
|
)
|
||||||
|
|
||||||
self._progress_reporter.output.write(
|
self._progress_reporter.output.write(
|
||||||
'Downloading %sto "%s"\n' % (
|
f'Downloading {humanize_bytes(total_size) + " " if total_size is not None else ""}'
|
||||||
(humanize_bytes(total_size) + ' '
|
f'to "{self._output_file.name}"\n'
|
||||||
if total_size is not None
|
|
||||||
else ''),
|
|
||||||
self._output_file.name
|
|
||||||
)
|
|
||||||
)
|
)
|
||||||
self._progress_reporter.start()
|
self._progress_reporter.start()
|
||||||
|
|
||||||
@ -358,7 +341,7 @@ class DownloadStatus:
|
|||||||
assert self.time_started is None
|
assert self.time_started is None
|
||||||
self.total_size = total_size
|
self.total_size = total_size
|
||||||
self.downloaded = self.resumed_from = resumed_from
|
self.downloaded = self.resumed_from = resumed_from
|
||||||
self.time_started = time()
|
self.time_started = monotonic()
|
||||||
|
|
||||||
def chunk_downloaded(self, size):
|
def chunk_downloaded(self, size):
|
||||||
assert self.time_finished is None
|
assert self.time_finished is None
|
||||||
@ -371,7 +354,7 @@ class DownloadStatus:
|
|||||||
def finished(self):
|
def finished(self):
|
||||||
assert self.time_started is not None
|
assert self.time_started is not None
|
||||||
assert self.time_finished is None
|
assert self.time_finished is None
|
||||||
self.time_finished = time()
|
self.time_finished = monotonic()
|
||||||
|
|
||||||
|
|
||||||
class ProgressReporterThread(threading.Thread):
|
class ProgressReporterThread(threading.Thread):
|
||||||
@ -397,7 +380,7 @@ class ProgressReporterThread(threading.Thread):
|
|||||||
self._spinner_pos = 0
|
self._spinner_pos = 0
|
||||||
self._status_line = ''
|
self._status_line = ''
|
||||||
self._prev_bytes = 0
|
self._prev_bytes = 0
|
||||||
self._prev_time = time()
|
self._prev_time = monotonic()
|
||||||
self._should_stop = threading.Event()
|
self._should_stop = threading.Event()
|
||||||
|
|
||||||
def stop(self):
|
def stop(self):
|
||||||
@ -414,16 +397,11 @@ class ProgressReporterThread(threading.Thread):
|
|||||||
sleep(self._tick)
|
sleep(self._tick)
|
||||||
|
|
||||||
def report_speed(self):
|
def report_speed(self):
|
||||||
|
now = monotonic()
|
||||||
now = time()
|
|
||||||
|
|
||||||
if now - self._prev_time >= self._update_interval:
|
if now - self._prev_time >= self._update_interval:
|
||||||
downloaded = self.status.downloaded
|
downloaded = self.status.downloaded
|
||||||
try:
|
speed = ((downloaded - self._prev_bytes)
|
||||||
speed = ((downloaded - self._prev_bytes)
|
/ (now - self._prev_time))
|
||||||
/ (now - self._prev_time))
|
|
||||||
except ZeroDivisionError:
|
|
||||||
speed = 0
|
|
||||||
|
|
||||||
if not self.status.total_size:
|
if not self.status.total_size:
|
||||||
self._status_line = PROGRESS_NO_CONTENT_LENGTH.format(
|
self._status_line = PROGRESS_NO_CONTENT_LENGTH.format(
|
||||||
@ -431,10 +409,9 @@ class ProgressReporterThread(threading.Thread):
|
|||||||
speed=humanize_bytes(speed),
|
speed=humanize_bytes(speed),
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
try:
|
percentage = (downloaded / self.status.total_size * 100
|
||||||
percentage = downloaded / self.status.total_size * 100
|
if self.status.total_size
|
||||||
except ZeroDivisionError:
|
else 0)
|
||||||
percentage = 0
|
|
||||||
|
|
||||||
if not speed:
|
if not speed:
|
||||||
eta = '-:--:--'
|
eta = '-:--:--'
|
||||||
@ -442,7 +419,7 @@ class ProgressReporterThread(threading.Thread):
|
|||||||
s = int((self.status.total_size - downloaded) / speed)
|
s = int((self.status.total_size - downloaded) / speed)
|
||||||
h, s = divmod(s, 60 * 60)
|
h, s = divmod(s, 60 * 60)
|
||||||
m, s = divmod(s, 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(
|
self._status_line = PROGRESS.format(
|
||||||
percentage=percentage,
|
percentage=percentage,
|
||||||
@ -455,33 +432,20 @@ class ProgressReporterThread(threading.Thread):
|
|||||||
self._prev_bytes = downloaded
|
self._prev_bytes = downloaded
|
||||||
|
|
||||||
self.output.write(
|
self.output.write(
|
||||||
CLEAR_LINE
|
f'{CLEAR_LINE} {SPINNER[self._spinner_pos]} {self._status_line}'
|
||||||
+ ' '
|
|
||||||
+ SPINNER[self._spinner_pos]
|
|
||||||
+ ' '
|
|
||||||
+ self._status_line
|
|
||||||
)
|
)
|
||||||
self.output.flush()
|
self.output.flush()
|
||||||
|
|
||||||
self._spinner_pos = (self._spinner_pos + 1
|
self._spinner_pos = (self._spinner_pos + 1) % len(SPINNER)
|
||||||
if self._spinner_pos + 1 != len(SPINNER)
|
|
||||||
else 0)
|
|
||||||
|
|
||||||
def sum_up(self):
|
def sum_up(self):
|
||||||
actually_downloaded = (
|
actually_downloaded = (
|
||||||
self.status.downloaded - self.status.resumed_from)
|
self.status.downloaded - self.status.resumed_from)
|
||||||
time_taken = self.status.time_finished - self.status.time_started
|
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)
|
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(
|
self.output.write(SUMMARY.format(
|
||||||
downloaded=humanize_bytes(actually_downloaded),
|
downloaded=humanize_bytes(actually_downloaded),
|
||||||
total=(self.status.total_size
|
total=(self.status.total_size
|
||||||
|
@ -1,30 +1,34 @@
|
|||||||
|
from abc import ABCMeta, abstractmethod
|
||||||
from typing import Iterable, Optional
|
from typing import Iterable, Optional
|
||||||
from urllib.parse import urlsplit
|
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."""
|
"""Abstract class for HTTP messages."""
|
||||||
|
|
||||||
def __init__(self, orig):
|
def __init__(self, orig):
|
||||||
self._orig = orig
|
self._orig = orig
|
||||||
|
|
||||||
|
@abstractmethod
|
||||||
def iter_body(self, chunk_size: int) -> Iterable[bytes]:
|
def iter_body(self, chunk_size: int) -> Iterable[bytes]:
|
||||||
"""Return an iterator over the body."""
|
"""Return an iterator over the body."""
|
||||||
raise NotImplementedError()
|
|
||||||
|
|
||||||
|
@abstractmethod
|
||||||
def iter_lines(self, chunk_size: int) -> Iterable[bytes]:
|
def iter_lines(self, chunk_size: int) -> Iterable[bytes]:
|
||||||
"""Return an iterator over the body yielding (`line`, `line_feed`)."""
|
"""Return an iterator over the body yielding (`line`, `line_feed`)."""
|
||||||
raise NotImplementedError()
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
|
@abstractmethod
|
||||||
def headers(self) -> str:
|
def headers(self) -> str:
|
||||||
"""Return a `str` with the message's headers."""
|
"""Return a `str` with the message's headers."""
|
||||||
raise NotImplementedError()
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
|
@abstractmethod
|
||||||
def encoding(self) -> Optional[str]:
|
def encoding(self) -> Optional[str]:
|
||||||
"""Return a `str` with the message's encoding, if known."""
|
"""Return a `str` with the message's encoding, if known."""
|
||||||
raise NotImplementedError()
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def body(self) -> bytes:
|
def body(self) -> bytes:
|
||||||
@ -36,7 +40,7 @@ class HTTPMessage:
|
|||||||
"""Return the message content type."""
|
"""Return the message content type."""
|
||||||
ct = self._orig.headers.get('Content-Type', '')
|
ct = self._orig.headers.get('Content-Type', '')
|
||||||
if not isinstance(ct, str):
|
if not isinstance(ct, str):
|
||||||
ct = ct.decode('utf8')
|
ct = ct.decode()
|
||||||
return ct
|
return ct
|
||||||
|
|
||||||
|
|
||||||
@ -52,32 +56,35 @@ class HTTPResponse(HTTPMessage):
|
|||||||
# noinspection PyProtectedMember
|
# noinspection PyProtectedMember
|
||||||
@property
|
@property
|
||||||
def headers(self):
|
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 = {
|
version = {
|
||||||
9: '0.9',
|
9: '0.9',
|
||||||
10: '1.0',
|
10: '1.0',
|
||||||
11: '1.1',
|
11: '1.1',
|
||||||
20: '2',
|
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]
|
headers = [status_line]
|
||||||
try:
|
headers.extend(
|
||||||
# `original.msg` is a `http.client.HTTPMessage` on Python 3
|
': '.join(header)
|
||||||
# `_headers` is a 2-tuple
|
for header in original.headers.items()
|
||||||
headers.extend(
|
if header[0] != 'Set-Cookie'
|
||||||
'%s: %s' % header for header in original.msg._headers)
|
)
|
||||||
except AttributeError:
|
headers.extend(
|
||||||
# and a `httplib.HTTPMessage` on Python 2.x
|
f'Set-Cookie: {cookie}'
|
||||||
# `headers` is a list of `name: val<CRLF>`.
|
for cookie in split_cookies(original.headers.get('Set-Cookie'))
|
||||||
headers.extend(h.strip() for h in original.msg.headers)
|
)
|
||||||
|
|
||||||
return '\r\n'.join(headers)
|
return '\r\n'.join(headers)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def encoding(self):
|
def encoding(self):
|
||||||
return self._orig.encoding or 'utf8'
|
return self._orig.encoding or UTF8
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def body(self):
|
def body(self):
|
||||||
@ -102,7 +109,7 @@ class HTTPRequest(HTTPMessage):
|
|||||||
request_line = '{method} {path}{query} HTTP/1.1'.format(
|
request_line = '{method} {path}{query} HTTP/1.1'.format(
|
||||||
method=self._orig.method,
|
method=self._orig.method,
|
||||||
path=url.path or '/',
|
path=url.path or '/',
|
||||||
query='?' + url.query if url.query else ''
|
query=f'?{url.query}' if url.query else ''
|
||||||
)
|
)
|
||||||
|
|
||||||
headers = dict(self._orig.headers)
|
headers = dict(self._orig.headers)
|
||||||
@ -110,29 +117,22 @@ class HTTPRequest(HTTPMessage):
|
|||||||
headers['Host'] = url.netloc.split('@')[-1]
|
headers['Host'] = url.netloc.split('@')[-1]
|
||||||
|
|
||||||
headers = [
|
headers = [
|
||||||
'%s: %s' % (
|
f'{name}: {value if isinstance(value, str) else value.decode()}'
|
||||||
name,
|
|
||||||
value if isinstance(value, str) else value.decode('utf8')
|
|
||||||
)
|
|
||||||
for name, value in headers.items()
|
for name, value in headers.items()
|
||||||
]
|
]
|
||||||
|
|
||||||
headers.insert(0, request_line)
|
headers.insert(0, request_line)
|
||||||
headers = '\r\n'.join(headers).strip()
|
headers = '\r\n'.join(headers).strip()
|
||||||
|
|
||||||
if isinstance(headers, bytes):
|
|
||||||
# Python < 3
|
|
||||||
headers = headers.decode('utf8')
|
|
||||||
return headers
|
return headers
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def encoding(self):
|
def encoding(self):
|
||||||
return 'utf8'
|
return UTF8
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def body(self):
|
def body(self):
|
||||||
body = self._orig.body
|
body = self._orig.body
|
||||||
if isinstance(body, str):
|
if isinstance(body, str):
|
||||||
# Happens with JSON/form request data parsed from the command line.
|
# Happens with JSON/form request data parsed from the command line.
|
||||||
body = body.encode('utf8')
|
body = body.encode()
|
||||||
return body or b''
|
return body or b''
|
||||||
|
@ -1,5 +1,3 @@
|
|||||||
from __future__ import absolute_import
|
|
||||||
|
|
||||||
import json
|
import json
|
||||||
from typing import Optional, Type
|
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.lexers.text import HttpLexer as PygmentsHttpLexer
|
||||||
from pygments.util import ClassNotFound
|
from pygments.util import ClassNotFound
|
||||||
|
|
||||||
from httpie.compat import is_windows
|
from ...compat import is_windows
|
||||||
from httpie.context import Environment
|
from ...context import Environment
|
||||||
from httpie.plugins import FormatterPlugin
|
from ...plugins import FormatterPlugin
|
||||||
|
|
||||||
|
|
||||||
AUTO_STYLE = 'auto' # Follows terminal ANSI color styles
|
AUTO_STYLE = 'auto' # Follows terminal ANSI color styles
|
||||||
@ -86,7 +84,7 @@ class ColorFormatter(FormatterPlugin):
|
|||||||
lexer=lexer,
|
lexer=lexer,
|
||||||
formatter=self.formatter,
|
formatter=self.formatter,
|
||||||
)
|
)
|
||||||
return body.strip()
|
return body
|
||||||
|
|
||||||
def get_lexer_for_body(
|
def get_lexer_for_body(
|
||||||
self, mime: str,
|
self, mime: str,
|
||||||
@ -120,8 +118,8 @@ def get_lexer(
|
|||||||
subtype_name, subtype_suffix = subtype.split('+', 1)
|
subtype_name, subtype_suffix = subtype.split('+', 1)
|
||||||
lexer_names.extend([subtype_name, subtype_suffix])
|
lexer_names.extend([subtype_name, subtype_suffix])
|
||||||
mime_types.extend([
|
mime_types.extend([
|
||||||
'%s/%s' % (type_, subtype_name),
|
f'{type_}/{subtype_name}',
|
||||||
'%s/%s' % (type_, subtype_suffix)
|
f'{type_}/{subtype_suffix}',
|
||||||
])
|
])
|
||||||
|
|
||||||
# As a last resort, if no lexer feels responsible, and
|
# As a last resort, if no lexer feels responsible, and
|
||||||
|
@ -1,8 +1,12 @@
|
|||||||
from httpie.plugins import FormatterPlugin
|
from ...plugins import FormatterPlugin
|
||||||
|
|
||||||
|
|
||||||
class HeadersFormatter(FormatterPlugin):
|
class HeadersFormatter(FormatterPlugin):
|
||||||
|
|
||||||
|
def __init__(self, **kwargs):
|
||||||
|
super().__init__(**kwargs)
|
||||||
|
self.enabled = self.format_options['headers']['sort']
|
||||||
|
|
||||||
def format_headers(self, headers: str) -> str:
|
def format_headers(self, headers: str) -> str:
|
||||||
"""
|
"""
|
||||||
Sorts headers by name while retaining relative
|
Sorts headers by name while retaining relative
|
||||||
|
@ -1,14 +1,14 @@
|
|||||||
from __future__ import absolute_import
|
|
||||||
import json
|
import json
|
||||||
|
|
||||||
from httpie.plugins import FormatterPlugin
|
from ...plugins import FormatterPlugin
|
||||||
|
|
||||||
|
|
||||||
DEFAULT_INDENT = 4
|
|
||||||
|
|
||||||
|
|
||||||
class JSONFormatter(FormatterPlugin):
|
class JSONFormatter(FormatterPlugin):
|
||||||
|
|
||||||
|
def __init__(self, **kwargs):
|
||||||
|
super().__init__(**kwargs)
|
||||||
|
self.enabled = self.format_options['json']['format']
|
||||||
|
|
||||||
def format_body(self, body: str, mime: str) -> str:
|
def format_body(self, body: str, mime: str) -> str:
|
||||||
maybe_json = [
|
maybe_json = [
|
||||||
'json',
|
'json',
|
||||||
@ -26,8 +26,8 @@ class JSONFormatter(FormatterPlugin):
|
|||||||
# unicode escapes to improve readability.
|
# unicode escapes to improve readability.
|
||||||
body = json.dumps(
|
body = json.dumps(
|
||||||
obj=obj,
|
obj=obj,
|
||||||
sort_keys=True,
|
sort_keys=self.format_options['json']['sort_keys'],
|
||||||
ensure_ascii=False,
|
ensure_ascii=False,
|
||||||
indent=DEFAULT_INDENT
|
indent=self.format_options['json']['indent']
|
||||||
)
|
)
|
||||||
return body
|
return body
|
||||||
|
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,8 +1,9 @@
|
|||||||
import re
|
import re
|
||||||
from typing import Optional, List
|
from typing import Optional, List
|
||||||
|
|
||||||
from httpie.plugins import plugin_manager, ConverterPlugin
|
from ..plugins import ConverterPlugin
|
||||||
from httpie.context import Environment
|
from ..plugins.registry import plugin_manager
|
||||||
|
from ..context import Environment
|
||||||
|
|
||||||
|
|
||||||
MIME_RE = re.compile(r'^[^/]+/[^/]+$')
|
MIME_RE = re.compile(r'^[^/]+/[^/]+$')
|
||||||
|
@ -1,9 +1,11 @@
|
|||||||
|
from abc import ABCMeta, abstractmethod
|
||||||
from itertools import chain
|
from itertools import chain
|
||||||
from typing import Callable, Iterable, Union
|
from typing import Callable, Iterable, Union
|
||||||
|
|
||||||
from httpie.context import Environment
|
from ..context import Environment
|
||||||
from httpie.models import HTTPMessage
|
from ..constants import UTF8
|
||||||
from httpie.output.processing import Conversion, Formatting
|
from ..models import HTTPMessage
|
||||||
|
from .processing import Conversion, Formatting
|
||||||
|
|
||||||
|
|
||||||
BINARY_SUPPRESSED_NOTICE = (
|
BINARY_SUPPRESSED_NOTICE = (
|
||||||
@ -14,14 +16,17 @@ BINARY_SUPPRESSED_NOTICE = (
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
class BinarySuppressedError(Exception):
|
class DataSuppressedError(Exception):
|
||||||
|
message = None
|
||||||
|
|
||||||
|
|
||||||
|
class BinarySuppressedError(DataSuppressedError):
|
||||||
"""An error indicating that the body is binary and won't be written,
|
"""An error indicating that the body is binary and won't be written,
|
||||||
e.g., for terminal output)."""
|
e.g., for terminal output)."""
|
||||||
|
|
||||||
message = BINARY_SUPPRESSED_NOTICE
|
message = BINARY_SUPPRESSED_NOTICE
|
||||||
|
|
||||||
|
|
||||||
class BaseStream:
|
class BaseStream(metaclass=ABCMeta):
|
||||||
"""Base HTTP message output stream class."""
|
"""Base HTTP message output stream class."""
|
||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
@ -45,11 +50,11 @@ class BaseStream:
|
|||||||
|
|
||||||
def get_headers(self) -> bytes:
|
def get_headers(self) -> bytes:
|
||||||
"""Return the headers' bytes."""
|
"""Return the headers' bytes."""
|
||||||
return self.msg.headers.encode('utf8')
|
return self.msg.headers.encode()
|
||||||
|
|
||||||
|
@abstractmethod
|
||||||
def iter_body(self) -> Iterable[bytes]:
|
def iter_body(self) -> Iterable[bytes]:
|
||||||
"""Return an iterator over the message body."""
|
"""Return an iterator over the message body."""
|
||||||
raise NotImplementedError()
|
|
||||||
|
|
||||||
def __iter__(self) -> Iterable[bytes]:
|
def __iter__(self) -> Iterable[bytes]:
|
||||||
"""Return an iterator over `self.msg`."""
|
"""Return an iterator over `self.msg`."""
|
||||||
@ -63,7 +68,7 @@ class BaseStream:
|
|||||||
yield chunk
|
yield chunk
|
||||||
if self.on_body_chunk_downloaded:
|
if self.on_body_chunk_downloaded:
|
||||||
self.on_body_chunk_downloaded(chunk)
|
self.on_body_chunk_downloaded(chunk)
|
||||||
except BinarySuppressedError as e:
|
except DataSuppressedError as e:
|
||||||
if self.with_headers:
|
if self.with_headers:
|
||||||
yield b'\n'
|
yield b'\n'
|
||||||
yield e.message
|
yield e.message
|
||||||
@ -101,8 +106,8 @@ class EncodedStream(BaseStream):
|
|||||||
else:
|
else:
|
||||||
# Preserve the message encoding.
|
# Preserve the message encoding.
|
||||||
output_encoding = self.msg.encoding
|
output_encoding = self.msg.encoding
|
||||||
# Default to utf8 when unsure.
|
# Default to UTF-8 when unsure.
|
||||||
self.output_encoding = output_encoding or 'utf8'
|
self.output_encoding = output_encoding or UTF8
|
||||||
|
|
||||||
def iter_body(self) -> Iterable[bytes]:
|
def iter_body(self) -> Iterable[bytes]:
|
||||||
for line, lf in self.msg.iter_lines(self.CHUNK_SIZE):
|
for line, lf in self.msg.iter_lines(self.CHUNK_SIZE):
|
||||||
|
@ -1,46 +1,37 @@
|
|||||||
import argparse
|
import argparse
|
||||||
import errno
|
import errno
|
||||||
from typing import Union, IO, TextIO, Tuple, Type
|
from typing import IO, TextIO, Tuple, Type, Union
|
||||||
|
|
||||||
import requests
|
import requests
|
||||||
|
|
||||||
from httpie.context import Environment
|
from ..context import Environment
|
||||||
from httpie.models import HTTPRequest, HTTPResponse
|
from ..models import HTTPRequest, HTTPResponse
|
||||||
from httpie.output.processing import Conversion, Formatting
|
from .processing import Conversion, Formatting
|
||||||
from httpie.output.streams import (
|
from .streams import (
|
||||||
RawStream, PrettyStream,
|
BaseStream, BufferedPrettyStream, EncodedStream, PrettyStream, RawStream,
|
||||||
BufferedPrettyStream, EncodedStream,
|
|
||||||
BaseStream,
|
|
||||||
)
|
|
||||||
from httpie.cli.constants import (
|
|
||||||
OUT_REQ_BODY, OUT_REQ_HEAD, OUT_RESP_BODY, OUT_RESP_HEAD,
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
MESSAGE_SEPARATOR = '\n\n'
|
||||||
|
MESSAGE_SEPARATOR_BYTES = MESSAGE_SEPARATOR.encode()
|
||||||
|
|
||||||
|
|
||||||
def write_message(
|
def write_message(
|
||||||
requests_message: Union[requests.PreparedRequest, requests.Response],
|
requests_message: Union[requests.PreparedRequest, requests.Response],
|
||||||
env: Environment,
|
env: Environment,
|
||||||
args: argparse.Namespace,
|
args: argparse.Namespace,
|
||||||
|
with_headers=False,
|
||||||
|
with_body=False,
|
||||||
):
|
):
|
||||||
output_options_by_message_type = {
|
if not (with_body or with_headers):
|
||||||
requests.PreparedRequest: {
|
|
||||||
'with_headers': OUT_REQ_HEAD in args.output_options,
|
|
||||||
'with_body': OUT_REQ_BODY in args.output_options,
|
|
||||||
},
|
|
||||||
requests.Response: {
|
|
||||||
'with_headers': OUT_RESP_HEAD in args.output_options,
|
|
||||||
'with_body': OUT_RESP_BODY in args.output_options,
|
|
||||||
},
|
|
||||||
}
|
|
||||||
output_options = output_options_by_message_type[type(requests_message)]
|
|
||||||
if not any(output_options.values()):
|
|
||||||
return
|
return
|
||||||
write_stream_kwargs = {
|
write_stream_kwargs = {
|
||||||
'stream': build_output_stream_for_message(
|
'stream': build_output_stream_for_message(
|
||||||
args=args,
|
args=args,
|
||||||
env=env,
|
env=env,
|
||||||
requests_message=requests_message,
|
requests_message=requests_message,
|
||||||
**output_options,
|
with_body=with_body,
|
||||||
|
with_headers=with_headers,
|
||||||
),
|
),
|
||||||
# NOTE: `env.stdout` will in fact be `stderr` with `--download`
|
# NOTE: `env.stdout` will in fact be `stderr` with `--download`
|
||||||
'outfile': env.stdout,
|
'outfile': env.stdout,
|
||||||
@ -48,10 +39,10 @@ def write_message(
|
|||||||
}
|
}
|
||||||
try:
|
try:
|
||||||
if env.is_windows and 'colors' in args.prettify:
|
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:
|
else:
|
||||||
write_stream(**write_stream_kwargs)
|
write_stream(**write_stream_kwargs)
|
||||||
except IOError as e:
|
except OSError as e:
|
||||||
show_traceback = args.debug or args.traceback
|
show_traceback = args.debug or args.traceback
|
||||||
if not show_traceback and e.errno == errno.EPIPE:
|
if not show_traceback and e.errno == errno.EPIPE:
|
||||||
# Ignore broken pipes unless --traceback.
|
# Ignore broken pipes unless --traceback.
|
||||||
@ -67,7 +58,7 @@ def write_stream(
|
|||||||
):
|
):
|
||||||
"""Write the output stream."""
|
"""Write the output stream."""
|
||||||
try:
|
try:
|
||||||
# Writing bytes so we use the buffer interface (Python 3).
|
# Writing bytes so we use the buffer interface.
|
||||||
buf = outfile.buffer
|
buf = outfile.buffer
|
||||||
except AttributeError:
|
except AttributeError:
|
||||||
buf = outfile
|
buf = outfile
|
||||||
@ -78,14 +69,14 @@ def write_stream(
|
|||||||
outfile.flush()
|
outfile.flush()
|
||||||
|
|
||||||
|
|
||||||
def write_stream_with_colors_win_py3(
|
def write_stream_with_colors_win(
|
||||||
stream: 'BaseStream',
|
stream: 'BaseStream',
|
||||||
outfile: TextIO,
|
outfile: TextIO,
|
||||||
flush: bool
|
flush: bool
|
||||||
):
|
):
|
||||||
"""Like `write`, but colorized chunks are written as text
|
"""Like `write`, but colorized chunks are written as text
|
||||||
directly to `outfile` to ensure it gets processed by colorama.
|
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['
|
color = b'\x1b['
|
||||||
@ -120,10 +111,11 @@ def build_output_stream_for_message(
|
|||||||
with_body=with_body,
|
with_body=with_body,
|
||||||
**stream_kwargs,
|
**stream_kwargs,
|
||||||
)
|
)
|
||||||
if env.stdout_isatty and with_body:
|
if (env.stdout_isatty and with_body
|
||||||
|
and not getattr(requests_message, 'is_body_upload_chunk', False)):
|
||||||
# Ensure a blank line after the response body.
|
# Ensure a blank line after the response body.
|
||||||
# For terminal output only.
|
# For terminal output only.
|
||||||
yield b'\n\n'
|
yield MESSAGE_SEPARATOR_BYTES
|
||||||
|
|
||||||
|
|
||||||
def get_stream_type_and_kwargs(
|
def get_stream_type_and_kwargs(
|
||||||
@ -152,6 +144,7 @@ def get_stream_type_and_kwargs(
|
|||||||
groups=args.prettify,
|
groups=args.prettify,
|
||||||
color_scheme=args.style,
|
color_scheme=args.style,
|
||||||
explicit_json=args.json,
|
explicit_json=args.json,
|
||||||
|
format_options=args.format_options,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
else:
|
else:
|
||||||
|
@ -3,22 +3,9 @@ WARNING: The plugin API is still work in progress and will
|
|||||||
probably be completely reworked in the future.
|
probably be completely reworked in the future.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
from httpie.plugins.base import (
|
from .base import (
|
||||||
AuthPlugin, FormatterPlugin,
|
AuthPlugin, FormatterPlugin,
|
||||||
ConverterPlugin, TransportPlugin
|
ConverterPlugin, TransportPlugin
|
||||||
)
|
)
|
||||||
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
|
|
||||||
|
|
||||||
|
__all__ = ('AuthPlugin', 'ConverterPlugin', 'FormatterPlugin', 'TransportPlugin')
|
||||||
plugin_manager = PluginManager()
|
|
||||||
plugin_manager.register(
|
|
||||||
BasicAuthPlugin,
|
|
||||||
DigestAuthPlugin,
|
|
||||||
HeadersFormatter,
|
|
||||||
JSONFormatter,
|
|
||||||
ColorFormatter,
|
|
||||||
)
|
|
||||||
|
@ -3,7 +3,7 @@ class BasePlugin:
|
|||||||
# The name of the plugin, eg. "My auth".
|
# The name of the plugin, eg. "My auth".
|
||||||
name = None
|
name = None
|
||||||
|
|
||||||
# Optional short description. Will be be shown in the help
|
# Optional short description. It will be shown in the help
|
||||||
# under --auth-type.
|
# under --auth-type.
|
||||||
description = None
|
description = None
|
||||||
|
|
||||||
@ -15,7 +15,9 @@ class AuthPlugin(BasePlugin):
|
|||||||
"""
|
"""
|
||||||
Base auth plugin class.
|
Base auth plugin class.
|
||||||
|
|
||||||
See <https://github.com/httpie/httpie-ntlm> for an example auth plugin.
|
See httpie-ntlm for an example auth plugin:
|
||||||
|
|
||||||
|
<https://github.com/httpie/httpie-ntlm>
|
||||||
|
|
||||||
See also `test_auth_plugins.py`
|
See also `test_auth_plugins.py`
|
||||||
|
|
||||||
@ -33,13 +35,22 @@ class AuthPlugin(BasePlugin):
|
|||||||
# Set this to `False` to disable the parsing and error handling.
|
# Set this to `False` to disable the parsing and error handling.
|
||||||
auth_parse = True
|
auth_parse = True
|
||||||
|
|
||||||
|
# Set to `True` to make it possible for this auth
|
||||||
|
# plugin to acquire credentials from the user’s netrc file(s).
|
||||||
|
# It is used as a fallback when the credentials are not provided explicitly
|
||||||
|
# through `--auth, -a`. Enabling this will allow skipping `--auth, -a`
|
||||||
|
# even when `auth_require` is set `True` (provided that netrc provides
|
||||||
|
# credential for a given host).
|
||||||
|
netrc_parse = False
|
||||||
|
|
||||||
# If both `auth_parse` and `prompt_password` are set to `True`,
|
# If both `auth_parse` and `prompt_password` are set to `True`,
|
||||||
# and the value of `-a` lacks the password part,
|
# and the value of `-a` lacks the password part,
|
||||||
# then the user will be prompted to type the password in.
|
# then the user will be prompted to type the password in.
|
||||||
prompt_password = True
|
prompt_password = True
|
||||||
|
|
||||||
# Will be set to the raw value of `-a` (if provided) before
|
# Will be set to the raw value of `-a` (if provided) before
|
||||||
# `get_auth()` gets called.
|
# `get_auth()` gets called. If the credentials came from a netrc file,
|
||||||
|
# then this is `None`.
|
||||||
raw_auth = None
|
raw_auth = None
|
||||||
|
|
||||||
def get_auth(self, username=None, password=None):
|
def get_auth(self, username=None, password=None):
|
||||||
@ -58,8 +69,13 @@ class AuthPlugin(BasePlugin):
|
|||||||
|
|
||||||
class TransportPlugin(BasePlugin):
|
class TransportPlugin(BasePlugin):
|
||||||
"""
|
"""
|
||||||
|
Requests transport adapter docs:
|
||||||
|
|
||||||
https://2.python-requests.org/en/latest/user/advanced/#transport-adapters
|
<https://requests.readthedocs.io/en/latest/user/advanced/#transport-adapters>
|
||||||
|
|
||||||
|
See httpie-unixsocket for an example transport plugin:
|
||||||
|
|
||||||
|
<https://github.com/httpie/httpie-unixsocket>
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
@ -76,6 +92,14 @@ class TransportPlugin(BasePlugin):
|
|||||||
|
|
||||||
|
|
||||||
class ConverterPlugin(BasePlugin):
|
class ConverterPlugin(BasePlugin):
|
||||||
|
"""
|
||||||
|
Possibly converts response data for prettified terminal display.
|
||||||
|
|
||||||
|
See httpie-msgpack for an example converter plugin:
|
||||||
|
|
||||||
|
<https://github.com/rasky/httpie-msgpack>.
|
||||||
|
|
||||||
|
"""
|
||||||
|
|
||||||
def __init__(self, mime):
|
def __init__(self, mime):
|
||||||
self.mime = mime
|
self.mime = mime
|
||||||
@ -89,17 +113,22 @@ class ConverterPlugin(BasePlugin):
|
|||||||
|
|
||||||
|
|
||||||
class FormatterPlugin(BasePlugin):
|
class FormatterPlugin(BasePlugin):
|
||||||
|
"""
|
||||||
|
Possibly formats response body & headers for prettified terminal display.
|
||||||
|
|
||||||
|
"""
|
||||||
group_name = 'format'
|
group_name = 'format'
|
||||||
|
|
||||||
def __init__(self, **kwargs):
|
def __init__(self, **kwargs):
|
||||||
"""
|
"""
|
||||||
:param env: an class:`Environment` instance
|
:param env: an class:`Environment` instance
|
||||||
:param kwargs: additional keyword argument that some
|
:param kwargs: additional keyword argument that some
|
||||||
processor might require.
|
formatters might require.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
self.enabled = True
|
self.enabled = True
|
||||||
self.kwargs = kwargs
|
self.kwargs = kwargs
|
||||||
|
self.format_options = kwargs['format_options']
|
||||||
|
|
||||||
def format_headers(self, headers: str) -> str:
|
def format_headers(self, headers: str) -> str:
|
||||||
"""Return processed `headers`
|
"""Return processed `headers`
|
||||||
|
@ -2,7 +2,7 @@ from base64 import b64encode
|
|||||||
|
|
||||||
import requests.auth
|
import requests.auth
|
||||||
|
|
||||||
from httpie.plugins.base import AuthPlugin
|
from .base import AuthPlugin
|
||||||
|
|
||||||
|
|
||||||
# noinspection PyAbstractClass
|
# noinspection PyAbstractClass
|
||||||
@ -19,23 +19,25 @@ class HTTPBasicAuth(requests.auth.HTTPBasicAuth):
|
|||||||
"""
|
"""
|
||||||
Override username/password serialization to allow unicode.
|
Override username/password serialization to allow unicode.
|
||||||
|
|
||||||
See https://github.com/jakubroztocil/httpie/issues/212
|
See https://github.com/httpie/httpie/issues/212
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
# noinspection PyTypeChecker
|
||||||
request.headers['Authorization'] = type(self).make_header(
|
request.headers['Authorization'] = type(self).make_header(
|
||||||
self.username, self.password).encode('latin1')
|
self.username, self.password).encode('latin1')
|
||||||
return request
|
return request
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def make_header(username: str, password: str) -> str:
|
def make_header(username: str, password: str) -> str:
|
||||||
credentials = u'%s:%s' % (username, password)
|
credentials = f'{username}:{password}'
|
||||||
token = b64encode(credentials.encode('utf8')).strip().decode('latin1')
|
token = b64encode(credentials.encode()).strip().decode('latin1')
|
||||||
return 'Basic %s' % token
|
return f'Basic {token}'
|
||||||
|
|
||||||
|
|
||||||
class BasicAuthPlugin(BuiltinAuthPlugin):
|
class BasicAuthPlugin(BuiltinAuthPlugin):
|
||||||
name = 'Basic HTTP auth'
|
name = 'Basic HTTP auth'
|
||||||
auth_type = 'basic'
|
auth_type = 'basic'
|
||||||
|
netrc_parse = True
|
||||||
|
|
||||||
# noinspection PyMethodOverriding
|
# noinspection PyMethodOverriding
|
||||||
def get_auth(self, username: str, password: str) -> HTTPBasicAuth:
|
def get_auth(self, username: str, password: str) -> HTTPBasicAuth:
|
||||||
@ -43,9 +45,9 @@ class BasicAuthPlugin(BuiltinAuthPlugin):
|
|||||||
|
|
||||||
|
|
||||||
class DigestAuthPlugin(BuiltinAuthPlugin):
|
class DigestAuthPlugin(BuiltinAuthPlugin):
|
||||||
|
|
||||||
name = 'Digest HTTP auth'
|
name = 'Digest HTTP auth'
|
||||||
auth_type = 'digest'
|
auth_type = 'digest'
|
||||||
|
netrc_parse = True
|
||||||
|
|
||||||
# noinspection PyMethodOverriding
|
# noinspection PyMethodOverriding
|
||||||
def get_auth(
|
def get_auth(
|
||||||
|
@ -4,8 +4,8 @@ from typing import Dict, List, Type
|
|||||||
|
|
||||||
from pkg_resources import iter_entry_points
|
from pkg_resources import iter_entry_points
|
||||||
|
|
||||||
from httpie.plugins import AuthPlugin, ConverterPlugin, FormatterPlugin
|
from . import AuthPlugin, ConverterPlugin, FormatterPlugin
|
||||||
from httpie.plugins.base import BasePlugin, TransportPlugin
|
from .base import BasePlugin, TransportPlugin
|
||||||
|
|
||||||
|
|
||||||
ENTRY_POINT_NAMES = [
|
ENTRY_POINT_NAMES = [
|
||||||
|
20
httpie/plugins/registry.py
Normal file
20
httpie/plugins/registry.py
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
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()
|
||||||
|
|
||||||
|
|
||||||
|
# Register all built-in plugins.
|
||||||
|
plugin_manager.register(
|
||||||
|
BasicAuthPlugin,
|
||||||
|
DigestAuthPlugin,
|
||||||
|
HeadersFormatter,
|
||||||
|
JSONFormatter,
|
||||||
|
XMLFormatter,
|
||||||
|
ColorFormatter,
|
||||||
|
)
|
@ -4,16 +4,18 @@ Persistent, JSON-serialized sessions.
|
|||||||
"""
|
"""
|
||||||
import os
|
import os
|
||||||
import re
|
import re
|
||||||
|
|
||||||
|
from http.cookies import SimpleCookie
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from typing import Optional, Union
|
from typing import Iterable, Optional, Union
|
||||||
from urllib.parse import urlsplit
|
from urllib.parse import urlsplit
|
||||||
|
|
||||||
from requests.auth import AuthBase
|
from requests.auth import AuthBase
|
||||||
from requests.cookies import RequestsCookieJar, create_cookie
|
from requests.cookies import RequestsCookieJar, create_cookie
|
||||||
|
|
||||||
from httpie.cli.dicts import RequestHeadersDict
|
from .cli.dicts import RequestHeadersDict
|
||||||
from httpie.config import BaseConfigDict, DEFAULT_CONFIG_DIR
|
from .config import BaseConfigDict, DEFAULT_CONFIG_DIR
|
||||||
from httpie.plugins import plugin_manager
|
from .plugins.registry import plugin_manager
|
||||||
|
|
||||||
|
|
||||||
SESSIONS_DIR_NAME = 'sessions'
|
SESSIONS_DIR_NAME = 'sessions'
|
||||||
@ -70,13 +72,21 @@ class Session(BaseConfigDict):
|
|||||||
|
|
||||||
"""
|
"""
|
||||||
headers = self.headers
|
headers = self.headers
|
||||||
for name, value in request_headers.items():
|
for name, value in request_headers.copy().items():
|
||||||
|
|
||||||
if value is None:
|
if value is None:
|
||||||
continue # Ignore explicitly unset headers
|
continue # Ignore explicitly unset headers
|
||||||
|
|
||||||
value = value.decode('utf8')
|
if type(value) is not str:
|
||||||
if name == 'User-Agent' and value.startswith('HTTPie/'):
|
value = value.decode()
|
||||||
|
|
||||||
|
if name.lower() == 'user-agent' and value.startswith('HTTPie/'):
|
||||||
|
continue
|
||||||
|
|
||||||
|
if name.lower() == 'cookie':
|
||||||
|
for cookie_name, morsel in SimpleCookie(value).items():
|
||||||
|
self['cookies'][cookie_name] = {'value': morsel.value}
|
||||||
|
del request_headers[name]
|
||||||
continue
|
continue
|
||||||
|
|
||||||
for prefix in SESSION_IGNORED_HEADER_PREFIXES:
|
for prefix in SESSION_IGNORED_HEADER_PREFIXES:
|
||||||
@ -131,7 +141,7 @@ class Session(BaseConfigDict):
|
|||||||
}
|
}
|
||||||
else:
|
else:
|
||||||
if plugin.auth_parse:
|
if plugin.auth_parse:
|
||||||
from httpie.cli.argtypes import parse_auth
|
from .cli.argtypes import parse_auth
|
||||||
parsed = parse_auth(plugin.raw_auth)
|
parsed = parse_auth(plugin.raw_auth)
|
||||||
credentials = {
|
credentials = {
|
||||||
'username': parsed.key,
|
'username': parsed.key,
|
||||||
@ -144,3 +154,8 @@ class Session(BaseConfigDict):
|
|||||||
def auth(self, auth: dict):
|
def auth(self, auth: dict):
|
||||||
assert {'type', 'raw_auth'} == auth.keys()
|
assert {'type', 'raw_auth'} == auth.keys()
|
||||||
self['auth'] = auth
|
self['auth'] = auth
|
||||||
|
|
||||||
|
def remove_cookies(self, names: Iterable[str]):
|
||||||
|
for name in names:
|
||||||
|
if name in self['cookies']:
|
||||||
|
del self['cookies'][name]
|
||||||
|
63
httpie/ssl.py
Normal file
63
httpie/ssl.py
Normal file
@ -0,0 +1,63 @@
|
|||||||
|
import ssl
|
||||||
|
|
||||||
|
from requests.adapters import HTTPAdapter
|
||||||
|
# noinspection PyPackageRequirements
|
||||||
|
from urllib3.util.ssl_ import (
|
||||||
|
DEFAULT_CIPHERS, create_urllib3_context,
|
||||||
|
resolve_ssl_version,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
DEFAULT_SSL_CIPHERS = DEFAULT_CIPHERS
|
||||||
|
SSL_VERSION_ARG_MAPPING = {
|
||||||
|
'ssl2.3': 'PROTOCOL_SSLv23',
|
||||||
|
'ssl3': 'PROTOCOL_SSLv3',
|
||||||
|
'tls1': 'PROTOCOL_TLSv1',
|
||||||
|
'tls1.1': 'PROTOCOL_TLSv1_1',
|
||||||
|
'tls1.2': 'PROTOCOL_TLSv1_2',
|
||||||
|
'tls1.3': 'PROTOCOL_TLSv1_3',
|
||||||
|
}
|
||||||
|
AVAILABLE_SSL_VERSION_ARG_MAPPING = {
|
||||||
|
arg: getattr(ssl, constant_name)
|
||||||
|
for arg, constant_name in SSL_VERSION_ARG_MAPPING.items()
|
||||||
|
if hasattr(ssl, constant_name)
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
class HTTPieHTTPSAdapter(HTTPAdapter):
|
||||||
|
def __init__(
|
||||||
|
self,
|
||||||
|
verify: bool,
|
||||||
|
ssl_version: str = None,
|
||||||
|
ciphers: str = None,
|
||||||
|
**kwargs
|
||||||
|
):
|
||||||
|
self._ssl_context = self._create_ssl_context(
|
||||||
|
verify=verify,
|
||||||
|
ssl_version=ssl_version,
|
||||||
|
ciphers=ciphers,
|
||||||
|
)
|
||||||
|
super().__init__(**kwargs)
|
||||||
|
|
||||||
|
def init_poolmanager(self, *args, **kwargs):
|
||||||
|
kwargs['ssl_context'] = self._ssl_context
|
||||||
|
return super().init_poolmanager(*args, **kwargs)
|
||||||
|
|
||||||
|
def proxy_manager_for(self, *args, **kwargs):
|
||||||
|
kwargs['ssl_context'] = self._ssl_context
|
||||||
|
return super().proxy_manager_for(*args, **kwargs)
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def _create_ssl_context(
|
||||||
|
verify: bool,
|
||||||
|
ssl_version: str = None,
|
||||||
|
ciphers: str = None,
|
||||||
|
) -> 'ssl.SSLContext':
|
||||||
|
return create_urllib3_context(
|
||||||
|
ciphers=ciphers,
|
||||||
|
ssl_version=resolve_ssl_version(ssl_version),
|
||||||
|
# Since we are using a custom SSL context, we need to pass this
|
||||||
|
# here manually, even though it’s also passed to the connection
|
||||||
|
# in `super().cert_verify()`.
|
||||||
|
cert_reqs=ssl.CERT_REQUIRED if verify else ssl.CERT_NONE
|
||||||
|
)
|
138
httpie/uploads.py
Normal file
138
httpie/uploads.py
Normal file
@ -0,0 +1,138 @@
|
|||||||
|
import zlib
|
||||||
|
from typing import Callable, IO, Iterable, Tuple, Union
|
||||||
|
from urllib.parse import urlencode
|
||||||
|
|
||||||
|
import requests
|
||||||
|
from requests.utils import super_len
|
||||||
|
from requests_toolbelt import MultipartEncoder
|
||||||
|
|
||||||
|
from .cli.dicts import MultipartRequestDataDict, RequestDataDict
|
||||||
|
|
||||||
|
|
||||||
|
class ChunkedUploadStream:
|
||||||
|
def __init__(self, stream: Iterable, callback: Callable):
|
||||||
|
self.callback = callback
|
||||||
|
self.stream = stream
|
||||||
|
|
||||||
|
def __iter__(self) -> Iterable[Union[str, bytes]]:
|
||||||
|
for chunk in self.stream:
|
||||||
|
self.callback(chunk)
|
||||||
|
yield chunk
|
||||||
|
|
||||||
|
|
||||||
|
class ChunkedMultipartUploadStream:
|
||||||
|
chunk_size = 100 * 1024
|
||||||
|
|
||||||
|
def __init__(self, encoder: MultipartEncoder):
|
||||||
|
self.encoder = encoder
|
||||||
|
|
||||||
|
def __iter__(self) -> Iterable[Union[str, bytes]]:
|
||||||
|
while True:
|
||||||
|
chunk = self.encoder.read(self.chunk_size)
|
||||||
|
if not chunk:
|
||||||
|
break
|
||||||
|
yield chunk
|
||||||
|
|
||||||
|
|
||||||
|
def prepare_request_body(
|
||||||
|
body: Union[str, bytes, IO, MultipartEncoder, RequestDataDict],
|
||||||
|
body_read_callback: Callable[[bytes], bytes],
|
||||||
|
content_length_header_value: int = None,
|
||||||
|
chunked=False,
|
||||||
|
offline=False,
|
||||||
|
) -> Union[str, bytes, IO, MultipartEncoder, ChunkedUploadStream]:
|
||||||
|
|
||||||
|
is_file_like = hasattr(body, 'read')
|
||||||
|
|
||||||
|
if isinstance(body, RequestDataDict):
|
||||||
|
body = urlencode(body, doseq=True)
|
||||||
|
|
||||||
|
if offline:
|
||||||
|
if is_file_like:
|
||||||
|
return body.read()
|
||||||
|
return body
|
||||||
|
|
||||||
|
if not is_file_like:
|
||||||
|
if chunked:
|
||||||
|
body = ChunkedUploadStream(
|
||||||
|
# Pass the entire body as one chunk.
|
||||||
|
stream=(chunk.encode() for chunk in [body]),
|
||||||
|
callback=body_read_callback,
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
# File-like object.
|
||||||
|
|
||||||
|
if not super_len(body):
|
||||||
|
# Zero-length -> assume stdin.
|
||||||
|
if content_length_header_value is None and not chunked:
|
||||||
|
#
|
||||||
|
# Read the whole stdin to determine `Content-Length`.
|
||||||
|
#
|
||||||
|
# TODO: Instead of opt-in --chunked, consider making
|
||||||
|
# `Transfer-Encoding: chunked` for STDIN opt-out via
|
||||||
|
# something like --no-chunked.
|
||||||
|
# This would be backwards-incompatible so wait until v3.0.0.
|
||||||
|
#
|
||||||
|
body = body.read()
|
||||||
|
else:
|
||||||
|
orig_read = body.read
|
||||||
|
|
||||||
|
def new_read(*args):
|
||||||
|
chunk = orig_read(*args)
|
||||||
|
body_read_callback(chunk)
|
||||||
|
return chunk
|
||||||
|
|
||||||
|
body.read = new_read
|
||||||
|
|
||||||
|
if chunked:
|
||||||
|
if isinstance(body, MultipartEncoder):
|
||||||
|
body = ChunkedMultipartUploadStream(
|
||||||
|
encoder=body,
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
body = ChunkedUploadStream(
|
||||||
|
stream=body,
|
||||||
|
callback=body_read_callback,
|
||||||
|
)
|
||||||
|
|
||||||
|
return body
|
||||||
|
|
||||||
|
|
||||||
|
def get_multipart_data_and_content_type(
|
||||||
|
data: MultipartRequestDataDict,
|
||||||
|
boundary: str = None,
|
||||||
|
content_type: str = None,
|
||||||
|
) -> Tuple[MultipartEncoder, str]:
|
||||||
|
encoder = MultipartEncoder(
|
||||||
|
fields=data.items(),
|
||||||
|
boundary=boundary,
|
||||||
|
)
|
||||||
|
if content_type:
|
||||||
|
content_type = content_type.strip()
|
||||||
|
if 'boundary=' not in content_type:
|
||||||
|
content_type = f'{content_type}; boundary={encoder.boundary_value}'
|
||||||
|
else:
|
||||||
|
content_type = encoder.content_type
|
||||||
|
|
||||||
|
data = encoder
|
||||||
|
return data, content_type
|
||||||
|
|
||||||
|
|
||||||
|
def compress_request(
|
||||||
|
request: requests.PreparedRequest,
|
||||||
|
always: bool,
|
||||||
|
):
|
||||||
|
deflater = zlib.compressobj()
|
||||||
|
if isinstance(request.body, str):
|
||||||
|
body_bytes = request.body.encode()
|
||||||
|
elif hasattr(request.body, 'read'):
|
||||||
|
body_bytes = request.body.read()
|
||||||
|
else:
|
||||||
|
body_bytes = request.body
|
||||||
|
deflated_data = deflater.compress(body_bytes)
|
||||||
|
deflated_data += deflater.flush()
|
||||||
|
is_economical = len(deflated_data) < len(body_bytes)
|
||||||
|
if is_economical or always:
|
||||||
|
request.body = deflated_data
|
||||||
|
request.headers['Content-Encoding'] = 'deflate'
|
||||||
|
request.headers['Content-Length'] = str(len(deflated_data))
|
@ -1,11 +1,16 @@
|
|||||||
from __future__ import division
|
|
||||||
import json
|
import json
|
||||||
import mimetypes
|
import mimetypes
|
||||||
|
import time
|
||||||
from collections import OrderedDict
|
from collections import OrderedDict
|
||||||
|
from http.cookiejar import parse_ns_headers
|
||||||
from pprint import pformat
|
from pprint import pformat
|
||||||
|
from typing import List, Optional, Tuple
|
||||||
|
import re
|
||||||
|
|
||||||
import requests.auth
|
import requests.auth
|
||||||
|
|
||||||
|
RE_COOKIE_SPLIT = re.compile(r', (?=[^ ;]+=)')
|
||||||
|
|
||||||
|
|
||||||
def load_json_preserve_order(s):
|
def load_json_preserve_order(s):
|
||||||
return json.loads(s, object_pairs_hook=OrderedDict)
|
return json.loads(s, object_pairs_hook=OrderedDict)
|
||||||
@ -21,8 +26,6 @@ def humanize_bytes(n, precision=2):
|
|||||||
# URL: https://code.activestate.com/recipes/577081/
|
# URL: https://code.activestate.com/recipes/577081/
|
||||||
"""Return a humanized string representation of a number of bytes.
|
"""Return a humanized string representation of a number of bytes.
|
||||||
|
|
||||||
Assumes `from __future__ import division`.
|
|
||||||
|
|
||||||
>>> humanize_bytes(1)
|
>>> humanize_bytes(1)
|
||||||
'1 B'
|
'1 B'
|
||||||
>>> humanize_bytes(1024, precision=1)
|
>>> humanize_bytes(1024, precision=1)
|
||||||
@ -58,7 +61,7 @@ def humanize_bytes(n, precision=2):
|
|||||||
break
|
break
|
||||||
|
|
||||||
# noinspection PyUnboundLocalVariable
|
# noinspection PyUnboundLocalVariable
|
||||||
return '%.*f %s' % (precision, n / factor, suffix)
|
return f'{n / factor:.{precision}f} {suffix}'
|
||||||
|
|
||||||
|
|
||||||
class ExplicitNullAuth(requests.auth.AuthBase):
|
class ExplicitNullAuth(requests.auth.AuthBase):
|
||||||
@ -77,9 +80,64 @@ def get_content_type(filename):
|
|||||||
to ``mimetypes``.
|
to ``mimetypes``.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
mime, encoding = mimetypes.guess_type(filename, strict=False)
|
return mimetypes.guess_type(filename, strict=False)[0]
|
||||||
if mime:
|
|
||||||
content_type = mime
|
|
||||||
if encoding:
|
def split_cookies(cookies):
|
||||||
content_type = '%s; charset=%s' % (mime, encoding)
|
"""
|
||||||
return content_type
|
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(
|
||||||
|
cookies: str,
|
||||||
|
now: float = None
|
||||||
|
) -> List[dict]:
|
||||||
|
|
||||||
|
now = now or time.time()
|
||||||
|
|
||||||
|
def is_expired(expires: Optional[float]) -> bool:
|
||||||
|
return expires is not None and expires <= now
|
||||||
|
|
||||||
|
attr_sets: List[Tuple[str, str]] = parse_ns_headers(
|
||||||
|
split_cookies(cookies)
|
||||||
|
)
|
||||||
|
|
||||||
|
cookies = [
|
||||||
|
# The first attr name is the cookie name.
|
||||||
|
dict(attrs[1:], name=attrs[0][0])
|
||||||
|
for attrs in attr_sets
|
||||||
|
]
|
||||||
|
|
||||||
|
_max_age_to_expires(cookies=cookies, now=now)
|
||||||
|
|
||||||
|
return [
|
||||||
|
{
|
||||||
|
'name': cookie['name'],
|
||||||
|
'path': cookie.get('path', '/')
|
||||||
|
}
|
||||||
|
for cookie in cookies
|
||||||
|
if is_expired(expires=cookie.get('expires'))
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
|
def _max_age_to_expires(cookies, now):
|
||||||
|
"""
|
||||||
|
Translate `max-age` into `expires` for Requests to take it into account.
|
||||||
|
|
||||||
|
HACK/FIXME: <https://github.com/psf/requests/issues/5743>
|
||||||
|
|
||||||
|
"""
|
||||||
|
for cookie in cookies:
|
||||||
|
if 'expires' in cookie:
|
||||||
|
continue
|
||||||
|
max_age = cookie.get('max-age')
|
||||||
|
if max_age and max_age.isdigit():
|
||||||
|
cookie['expires'] = now + float(max_age)
|
||||||
|
@ -1,9 +0,0 @@
|
|||||||
tox
|
|
||||||
mock
|
|
||||||
pytest
|
|
||||||
pytest-cov
|
|
||||||
pytest-httpbin>=0.0.6
|
|
||||||
docutils
|
|
||||||
wheel
|
|
||||||
pycodestyle
|
|
||||||
twine
|
|
18
setup.cfg
18
setup.cfg
@ -1,18 +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]
|
[wheel]
|
||||||
|
|
||||||
|
|
||||||
[tool:pytest]
|
[tool:pytest]
|
||||||
# <https://docs.pytest.org/en/latest/customize.html>
|
# <https://docs.pytest.org/en/latest/customize.html>
|
||||||
norecursedirs = tests/fixtures
|
norecursedirs = tests/fixtures .*
|
||||||
|
addopts = --tb=native --doctest-modules
|
||||||
|
|
||||||
|
|
||||||
[pycodestyle]
|
[flake8]
|
||||||
# <http://pycodestyle.pycqa.org/en/latest/intro.html#configuration>
|
# <https://flake8.pycqa.org/en/latest/user/error-codes.html>
|
||||||
|
|
||||||
exclude = .git,.idea,__pycache__,build,dist,.tox,.pytest_cache,*.egg-info
|
|
||||||
|
|
||||||
# <http://pycodestyle.pycqa.org/en/latest/intro.html#error-codes>
|
|
||||||
# E241 - multiple spaces after ‘,’
|
|
||||||
# E501 - line too long
|
# E501 - line too long
|
||||||
# W503 - line break before binary operator
|
# W503 - line break before binary operator
|
||||||
ignore = E241,E501,W503
|
ignore = E501,W503
|
||||||
|
62
setup.py
62
setup.py
@ -1,43 +1,35 @@
|
|||||||
# This is purely the result of trial and error.
|
# This is purely the result of trial and error.
|
||||||
|
|
||||||
import sys
|
import sys
|
||||||
import codecs
|
|
||||||
|
|
||||||
from setuptools import setup, find_packages
|
from setuptools import setup, find_packages
|
||||||
from setuptools.command.test import test as TestCommand
|
|
||||||
|
|
||||||
import httpie
|
import httpie
|
||||||
|
|
||||||
|
# Note: keep requirements here to ease distributions packaging
|
||||||
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))
|
|
||||||
|
|
||||||
|
|
||||||
tests_require = [
|
tests_require = [
|
||||||
'pytest-httpbin',
|
|
||||||
'pytest',
|
'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 = [
|
install_requires = [
|
||||||
'requests>=2.22.0',
|
'defusedxml>=0.6.0',
|
||||||
|
'requests[socks]>=2.22.0',
|
||||||
'Pygments>=2.5.2',
|
'Pygments>=2.5.2',
|
||||||
|
'requests-toolbelt>=0.9.1',
|
||||||
|
'setuptools',
|
||||||
]
|
]
|
||||||
install_requires_win_only = [
|
install_requires_win_only = [
|
||||||
'colorama>=0.2.4',
|
'colorama>=0.2.4',
|
||||||
@ -55,13 +47,15 @@ if 'bdist_wheel' not in sys.argv:
|
|||||||
|
|
||||||
# bdist_wheel
|
# bdist_wheel
|
||||||
extras_require = {
|
extras_require = {
|
||||||
|
'dev': dev_require,
|
||||||
|
'test': tests_require,
|
||||||
# https://wheel.readthedocs.io/en/latest/#defining-conditional-dependencies
|
# https://wheel.readthedocs.io/en/latest/#defining-conditional-dependencies
|
||||||
':sys_platform == "win32"': install_requires_win_only,
|
':sys_platform == "win32"': install_requires_win_only,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
def long_description():
|
def long_description():
|
||||||
with codecs.open('README.rst', encoding='utf8') as f:
|
with open('README.md', encoding='utf-8') as f:
|
||||||
return f.read()
|
return f.read()
|
||||||
|
|
||||||
|
|
||||||
@ -70,12 +64,13 @@ setup(
|
|||||||
version=httpie.__version__,
|
version=httpie.__version__,
|
||||||
description=httpie.__doc__.strip(),
|
description=httpie.__doc__.strip(),
|
||||||
long_description=long_description(),
|
long_description=long_description(),
|
||||||
|
long_description_content_type='text/markdown',
|
||||||
url='https://httpie.org/',
|
url='https://httpie.org/',
|
||||||
download_url=f'https://github.com/jakubroztocil/httpie/archive/{httpie.__version__}.tar.gz',
|
download_url=f'https://github.com/httpie/httpie/archive/{httpie.__version__}.tar.gz',
|
||||||
author=httpie.__author__,
|
author=httpie.__author__,
|
||||||
author_email='jakub@roztocil.co',
|
author_email='jakub@roztocil.co',
|
||||||
license=httpie.__licence__,
|
license=httpie.__licence__,
|
||||||
packages=find_packages(),
|
packages=find_packages(include=['httpie', 'httpie.*']),
|
||||||
entry_points={
|
entry_points={
|
||||||
'console_scripts': [
|
'console_scripts': [
|
||||||
'http = httpie.__main__:main',
|
'http = httpie.__main__:main',
|
||||||
@ -85,8 +80,6 @@ setup(
|
|||||||
python_requires='>=3.6',
|
python_requires='>=3.6',
|
||||||
extras_require=extras_require,
|
extras_require=extras_require,
|
||||||
install_requires=install_requires,
|
install_requires=install_requires,
|
||||||
tests_require=tests_require,
|
|
||||||
cmdclass={'test': PyTest},
|
|
||||||
classifiers=[
|
classifiers=[
|
||||||
'Development Status :: 5 - Production/Stable',
|
'Development Status :: 5 - Production/Stable',
|
||||||
'Programming Language :: Python',
|
'Programming Language :: Python',
|
||||||
@ -103,10 +96,9 @@ setup(
|
|||||||
'Topic :: Utilities'
|
'Topic :: Utilities'
|
||||||
],
|
],
|
||||||
project_urls={
|
project_urls={
|
||||||
|
'GitHub': 'https://github.com/httpie/httpie',
|
||||||
|
'Twitter': 'https://twitter.com/httpie',
|
||||||
'Documentation': 'https://httpie.org/docs',
|
'Documentation': 'https://httpie.org/docs',
|
||||||
'Source': 'https://github.com/jakubroztocil/httpie',
|
|
||||||
'Online Demo': 'https://httpie.org/run',
|
'Online Demo': 'https://httpie.org/run',
|
||||||
'Donate': 'https://httpie.org/donate',
|
|
||||||
'Twitter': 'https://twitter.com/clihttp',
|
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
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/jakubroztocil/httpie/blob/master/CONTRIBUTING.rst
|
|
0
tests/__init__.py
Normal file
0
tests/__init__.py
Normal file
@ -1,29 +1,31 @@
|
|||||||
-----BEGIN CERTIFICATE-----
|
-----BEGIN CERTIFICATE-----
|
||||||
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
|
||||||
-----END CERTIFICATE-----
|
-----END CERTIFICATE-----
|
||||||
|
@ -1,51 +1,51 @@
|
|||||||
-----BEGIN RSA PRIVATE KEY-----
|
-----BEGIN RSA PRIVATE KEY-----
|
||||||
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
|
||||||
-----END RSA PRIVATE KEY-----
|
-----END RSA PRIVATE KEY-----
|
||||||
|
@ -1,87 +1,82 @@
|
|||||||
Bag Attributes
|
|
||||||
localKeyID: 93 0C 3E A7 82 62 36 37 5E 73 9B 05 C4 98 DF DC 04 5C B4 C9
|
|
||||||
subject=/C=AU/ST=Some-State/O=Internet Widgits Pty Ltd
|
|
||||||
issuer=/C=US/ST=CA/L=SF/O=HTTPie/CN=HTTPie
|
|
||||||
-----BEGIN CERTIFICATE-----
|
-----BEGIN CERTIFICATE-----
|
||||||
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
|
||||||
-----END CERTIFICATE-----
|
-----END CERTIFICATE-----
|
||||||
Bag Attributes
|
|
||||||
localKeyID: 93 0C 3E A7 82 62 36 37 5E 73 9B 05 C4 98 DF DC 04 5C B4 C9
|
|
||||||
Key Attributes: <No Attributes>
|
|
||||||
-----BEGIN RSA PRIVATE KEY-----
|
-----BEGIN RSA PRIVATE KEY-----
|
||||||
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
|
||||||
-----END RSA PRIVATE KEY-----
|
-----END RSA PRIVATE KEY-----
|
||||||
|
@ -1,6 +1,9 @@
|
|||||||
|
import socket
|
||||||
import pytest
|
import pytest
|
||||||
from pytest_httpbin import certs
|
from pytest_httpbin import certs
|
||||||
|
|
||||||
|
from .utils import HTTPBIN_WITH_CHUNKED_SUPPORT_DOMAIN, HTTPBIN_WITH_CHUNKED_SUPPORT
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture(scope='function', autouse=True)
|
@pytest.fixture(scope='function', autouse=True)
|
||||||
def httpbin_add_ca_bundle(monkeypatch):
|
def httpbin_add_ca_bundle(monkeypatch):
|
||||||
@ -22,3 +25,19 @@ def httpbin_secure_untrusted(monkeypatch, httpbin_secure):
|
|||||||
"""
|
"""
|
||||||
monkeypatch.delenv('REQUESTS_CA_BUNDLE')
|
monkeypatch.delenv('REQUESTS_CA_BUNDLE')
|
||||||
return httpbin_secure
|
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
|
||||||
|
|
38
tests/fixtures/__init__.py
vendored
38
tests/fixtures/__init__.py
vendored
@ -1,6 +1,7 @@
|
|||||||
"""Test data"""
|
"""Test data"""
|
||||||
from os import path
|
from pathlib import Path
|
||||||
import codecs
|
|
||||||
|
from httpie.constants import UTF8
|
||||||
|
|
||||||
|
|
||||||
def patharg(path):
|
def patharg(path):
|
||||||
@ -9,32 +10,27 @@ def patharg(path):
|
|||||||
even in Windows paths.
|
even in Windows paths.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
return path.replace('\\', '\\\\\\')
|
return str(path).replace('\\', '\\\\\\')
|
||||||
|
|
||||||
|
|
||||||
FIXTURES_ROOT = path.join(path.abspath(path.dirname(__file__)))
|
FIXTURES_ROOT = Path(__file__).parent
|
||||||
FILE_PATH = path.join(FIXTURES_ROOT, 'test.txt')
|
FILE_PATH = FIXTURES_ROOT / 'test.txt'
|
||||||
JSON_FILE_PATH = path.join(FIXTURES_ROOT, 'test.json')
|
JSON_FILE_PATH = FIXTURES_ROOT / 'test.json'
|
||||||
BIN_FILE_PATH = path.join(FIXTURES_ROOT, 'test.bin')
|
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)
|
FILE_PATH_ARG = patharg(FILE_PATH)
|
||||||
BIN_FILE_PATH_ARG = patharg(BIN_FILE_PATH)
|
BIN_FILE_PATH_ARG = patharg(BIN_FILE_PATH)
|
||||||
JSON_FILE_PATH_ARG = patharg(JSON_FILE_PATH)
|
JSON_FILE_PATH_ARG = patharg(JSON_FILE_PATH)
|
||||||
|
|
||||||
|
# Strip because we don't want new lines in the data so that we can
|
||||||
with codecs.open(FILE_PATH, encoding='utf8') as f:
|
# easily count occurrences also when embedded in JSON (where the new
|
||||||
# Strip because we don't want new lines in the data so that we can
|
# line would be escaped).
|
||||||
# easily count occurrences also when embedded in JSON (where the new
|
FILE_CONTENT = FILE_PATH.read_text(encoding=UTF8).strip()
|
||||||
# line would be escaped).
|
|
||||||
FILE_CONTENT = f.read().strip()
|
|
||||||
|
|
||||||
|
|
||||||
with codecs.open(JSON_FILE_PATH, encoding='utf8') as f:
|
JSON_FILE_CONTENT = JSON_FILE_PATH.read_text(encoding=UTF8)
|
||||||
JSON_FILE_CONTENT = f.read()
|
BIN_FILE_CONTENT = BIN_FILE_PATH.read_bytes()
|
||||||
|
|
||||||
|
|
||||||
with open(BIN_FILE_PATH, 'rb') as f:
|
|
||||||
BIN_FILE_CONTENT = f.read()
|
|
||||||
|
|
||||||
UNICODE = FILE_CONTENT
|
UNICODE = FILE_CONTENT
|
||||||
|
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,10 +1,11 @@
|
|||||||
"""HTTP authentication-related tests."""
|
"""HTTP authentication-related tests."""
|
||||||
import mock
|
from unittest import mock
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from httpie.plugins.builtin import HTTPBasicAuth
|
from httpie.plugins.builtin import HTTPBasicAuth
|
||||||
|
from httpie.status import ExitStatus
|
||||||
from httpie.utils import ExplicitNullAuth
|
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.constants
|
||||||
import httpie.cli.definition
|
import httpie.cli.definition
|
||||||
|
|
||||||
@ -57,7 +58,7 @@ def test_credentials_in_url_auth_flag_has_priority(httpbin_both):
|
|||||||
])
|
])
|
||||||
def test_only_username_in_url(url):
|
def test_only_username_in_url(url):
|
||||||
"""
|
"""
|
||||||
https://github.com/jakubroztocil/httpie/issues/242
|
https://github.com/httpie/httpie/issues/242
|
||||||
|
|
||||||
"""
|
"""
|
||||||
args = httpie.cli.definition.parser.parse_args(args=[url], env=MockEnvironment())
|
args = httpie.cli.definition.parser.parse_args(args=[url], env=MockEnvironment())
|
||||||
@ -78,6 +79,8 @@ def test_missing_auth(httpbin):
|
|||||||
|
|
||||||
|
|
||||||
def test_netrc(httpbin_both):
|
def test_netrc(httpbin_both):
|
||||||
|
# This one gets handled by requests (no --auth, --auth-type present),
|
||||||
|
# that’s why we patch inside `requests.sessions`.
|
||||||
with mock.patch('requests.sessions.get_netrc_auth') as get_netrc_auth:
|
with mock.patch('requests.sessions.get_netrc_auth') as get_netrc_auth:
|
||||||
get_netrc_auth.return_value = ('httpie', 'password')
|
get_netrc_auth.return_value = ('httpie', 'password')
|
||||||
r = http(httpbin_both + '/basic-auth/httpie/password')
|
r = http(httpbin_both + '/basic-auth/httpie/password')
|
||||||
@ -86,24 +89,54 @@ def test_netrc(httpbin_both):
|
|||||||
|
|
||||||
|
|
||||||
def test_ignore_netrc(httpbin_both):
|
def test_ignore_netrc(httpbin_both):
|
||||||
with mock.patch('requests.sessions.get_netrc_auth') as get_netrc_auth:
|
with mock.patch('httpie.cli.argparser.get_netrc_auth') as get_netrc_auth:
|
||||||
get_netrc_auth.return_value = ('httpie', 'password')
|
get_netrc_auth.return_value = ('httpie', 'password')
|
||||||
r = http('--ignore-netrc', httpbin_both + '/basic-auth/httpie/password')
|
r = http('--ignore-netrc', httpbin_both + '/basic-auth/httpie/password')
|
||||||
assert get_netrc_auth.call_count == 0
|
assert get_netrc_auth.call_count == 0
|
||||||
assert 'HTTP/1.1 401 UNAUTHORIZED' in r
|
assert 'HTTP/1.1 401 UNAUTHORIZED' in r
|
||||||
|
|
||||||
|
|
||||||
def test_ignore_netrc_null_auth():
|
|
||||||
args = httpie.cli.definition.parser.parse_args(
|
|
||||||
args=['--ignore-netrc', 'example.org'],
|
|
||||||
env=MockEnvironment(),
|
|
||||||
)
|
|
||||||
assert isinstance(args.auth, ExplicitNullAuth)
|
|
||||||
|
|
||||||
|
|
||||||
def test_ignore_netrc_together_with_auth():
|
def test_ignore_netrc_together_with_auth():
|
||||||
args = httpie.cli.definition.parser.parse_args(
|
args = httpie.cli.definition.parser.parse_args(
|
||||||
args=['--ignore-netrc', '--auth=username:password', 'example.org'],
|
args=['--ignore-netrc', '--auth=username:password', 'example.org'],
|
||||||
env=MockEnvironment(),
|
env=MockEnvironment(),
|
||||||
)
|
)
|
||||||
assert isinstance(args.auth, HTTPBasicAuth)
|
assert isinstance(args.auth, HTTPBasicAuth)
|
||||||
|
|
||||||
|
|
||||||
|
def test_ignore_netrc_with_auth_type_resulting_in_missing_auth(httpbin):
|
||||||
|
with mock.patch('httpie.cli.argparser.get_netrc_auth') as get_netrc_auth:
|
||||||
|
get_netrc_auth.return_value = ('httpie', 'password')
|
||||||
|
r = http(
|
||||||
|
'--ignore-netrc',
|
||||||
|
'--auth-type=basic',
|
||||||
|
httpbin + '/basic-auth/httpie/password',
|
||||||
|
tolerate_error_exit_status=True,
|
||||||
|
)
|
||||||
|
assert get_netrc_auth.call_count == 0
|
||||||
|
assert r.exit_status == ExitStatus.ERROR
|
||||||
|
assert '--auth required' in r.stderr
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.parametrize(
|
||||||
|
argnames=['auth_type', 'endpoint'],
|
||||||
|
argvalues=[
|
||||||
|
('basic', '/basic-auth/httpie/password'),
|
||||||
|
('digest', '/digest-auth/auth/httpie/password'),
|
||||||
|
],
|
||||||
|
)
|
||||||
|
def test_auth_plugin_netrc_parse(auth_type, endpoint, httpbin):
|
||||||
|
# Test
|
||||||
|
with mock.patch('httpie.cli.argparser.get_netrc_auth') as get_netrc_auth:
|
||||||
|
get_netrc_auth.return_value = ('httpie', 'password')
|
||||||
|
r = http('--auth-type', auth_type, httpbin + endpoint)
|
||||||
|
assert get_netrc_auth.call_count == 1
|
||||||
|
assert HTTP_OK in r
|
||||||
|
|
||||||
|
|
||||||
|
def test_ignore_netrc_null_auth():
|
||||||
|
args = httpie.cli.definition.parser.parse_args(
|
||||||
|
args=['--ignore-netrc', 'example.org'],
|
||||||
|
env=MockEnvironment(),
|
||||||
|
)
|
||||||
|
assert isinstance(args.auth, ExplicitNullAuth)
|
||||||
|
@ -1,8 +1,10 @@
|
|||||||
from mock import mock
|
from unittest import mock
|
||||||
|
|
||||||
from httpie.cli.constants import SEPARATOR_CREDENTIALS
|
from httpie.cli.constants import SEPARATOR_CREDENTIALS
|
||||||
from httpie.plugins import AuthPlugin, plugin_manager
|
from httpie.plugins import AuthPlugin
|
||||||
from utils import http, HTTP_OK
|
from httpie.plugins.registry import plugin_manager
|
||||||
|
from .utils import http, HTTP_OK
|
||||||
|
|
||||||
|
|
||||||
# TODO: run all these tests in session mode as well
|
# TODO: run all these tests in session mode as well
|
||||||
|
|
||||||
@ -11,7 +13,7 @@ PASSWORD = 'password'
|
|||||||
# Basic auth encoded `USERNAME` and `PASSWORD`
|
# Basic auth encoded `USERNAME` and `PASSWORD`
|
||||||
# noinspection SpellCheckingInspection
|
# noinspection SpellCheckingInspection
|
||||||
BASIC_AUTH_HEADER_VALUE = 'Basic dXNlcjpwYXNzd29yZA=='
|
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}
|
AUTH_OK = {'authenticated': True, 'user': USERNAME}
|
||||||
|
|
||||||
|
|
||||||
|
@ -1,9 +1,9 @@
|
|||||||
"""Tests for dealing with binary request and response data."""
|
"""Tests for dealing with binary request and response data."""
|
||||||
import requests
|
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 httpie.output.streams import BINARY_SUPPRESSED_NOTICE
|
||||||
from utils import MockEnvironment, http
|
from .utils import MockEnvironment, http
|
||||||
|
|
||||||
|
|
||||||
class TestBinaryRequestData:
|
class TestBinaryRequestData:
|
||||||
|
@ -6,7 +6,7 @@ import pytest
|
|||||||
from requests.exceptions import InvalidSchema
|
from requests.exceptions import InvalidSchema
|
||||||
|
|
||||||
import httpie.cli.argparser
|
import httpie.cli.argparser
|
||||||
from fixtures import (
|
from .fixtures import (
|
||||||
FILE_CONTENT, FILE_PATH, FILE_PATH_ARG, JSON_FILE_CONTENT,
|
FILE_CONTENT, FILE_PATH, FILE_PATH_ARG, JSON_FILE_CONTENT,
|
||||||
JSON_FILE_PATH_ARG,
|
JSON_FILE_PATH_ARG,
|
||||||
)
|
)
|
||||||
@ -15,7 +15,7 @@ from httpie.cli import constants
|
|||||||
from httpie.cli.definition import parser
|
from httpie.cli.definition import parser
|
||||||
from httpie.cli.argtypes import KeyValueArg, KeyValueArgType
|
from httpie.cli.argtypes import KeyValueArg, KeyValueArgType
|
||||||
from httpie.cli.requestitems import RequestItems
|
from httpie.cli.requestitems import RequestItems
|
||||||
from utils import HTTP_OK, MockEnvironment, http
|
from .utils import HTTP_OK, MockEnvironment, StdinBytesIO, http
|
||||||
|
|
||||||
|
|
||||||
class TestItemParsing:
|
class TestItemParsing:
|
||||||
@ -36,7 +36,7 @@ class TestItemParsing:
|
|||||||
self.key_value_arg(r'baz\=bar=foo'),
|
self.key_value_arg(r'baz\=bar=foo'),
|
||||||
|
|
||||||
# files
|
# 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`
|
# `requests.structures.CaseInsensitiveDict` => `dict`
|
||||||
headers = dict(items.headers._store.values())
|
headers = dict(items.headers._store.values())
|
||||||
@ -118,7 +118,7 @@ class TestItemParsing:
|
|||||||
# Parsed file fields
|
# Parsed file fields
|
||||||
assert 'file' in items.files
|
assert 'file' in items.files
|
||||||
assert (items.files['file'][1].read().strip().
|
assert (items.files['file'][1].read().strip().
|
||||||
decode('utf8') == FILE_CONTENT)
|
decode() == FILE_CONTENT)
|
||||||
|
|
||||||
def test_multiple_file_fields_with_same_field_name(self):
|
def test_multiple_file_fields_with_same_field_name(self):
|
||||||
items = RequestItems.from_args([
|
items = RequestItems.from_args([
|
||||||
@ -148,16 +148,16 @@ class TestQuerystring:
|
|||||||
path = '/get?a=1&b=2'
|
path = '/get?a=1&b=2'
|
||||||
url = httpbin.url + path
|
url = httpbin.url + path
|
||||||
assert HTTP_OK in r
|
assert HTTP_OK in r
|
||||||
assert 'GET %s HTTP/1.1' % path in r
|
assert f'GET {path} HTTP/1.1' in r
|
||||||
assert '"url": "%s"' % url in r
|
assert f'"url": "{url}"' in r
|
||||||
|
|
||||||
def test_query_string_params_items(self, httpbin):
|
def test_query_string_params_items(self, httpbin):
|
||||||
r = http('--print=Hhb', 'GET', httpbin.url + '/get', 'a==1')
|
r = http('--print=Hhb', 'GET', httpbin.url + '/get', 'a==1')
|
||||||
path = '/get?a=1'
|
path = '/get?a=1'
|
||||||
url = httpbin.url + path
|
url = httpbin.url + path
|
||||||
assert HTTP_OK in r
|
assert HTTP_OK in r
|
||||||
assert 'GET %s HTTP/1.1' % path in r
|
assert f'GET {path} HTTP/1.1' in r
|
||||||
assert '"url": "%s"' % url in r
|
assert f'"url": "{url}"' in r
|
||||||
|
|
||||||
def test_query_string_params_in_url_and_items_with_duplicates(self,
|
def test_query_string_params_in_url_and_items_with_duplicates(self,
|
||||||
httpbin):
|
httpbin):
|
||||||
@ -166,8 +166,8 @@ class TestQuerystring:
|
|||||||
path = '/get?a=1&a=1&a=1&a=1'
|
path = '/get?a=1&a=1&a=1&a=1'
|
||||||
url = httpbin.url + path
|
url = httpbin.url + path
|
||||||
assert HTTP_OK in r
|
assert HTTP_OK in r
|
||||||
assert 'GET %s HTTP/1.1' % path in r
|
assert f'GET {path} HTTP/1.1' in r
|
||||||
assert '"url": "%s"' % url in r
|
assert f'"url": "{url}"' in r
|
||||||
|
|
||||||
|
|
||||||
class TestLocalhostShorthand:
|
class TestLocalhostShorthand:
|
||||||
@ -312,10 +312,11 @@ class TestNoOptions:
|
|||||||
class TestStdin:
|
class TestStdin:
|
||||||
|
|
||||||
def test_ignore_stdin(self, httpbin):
|
def test_ignore_stdin(self, httpbin):
|
||||||
with open(FILE_PATH) as f:
|
env = MockEnvironment(
|
||||||
env = MockEnvironment(stdin=f, stdin_isatty=False)
|
stdin=StdinBytesIO(FILE_PATH.read_bytes()),
|
||||||
r = http('--ignore-stdin', '--verbose', httpbin.url + '/get',
|
stdin_isatty=False,
|
||||||
env=env)
|
)
|
||||||
|
r = http('--ignore-stdin', '--verbose', httpbin.url + '/get', env=env)
|
||||||
assert HTTP_OK in r
|
assert HTTP_OK in r
|
||||||
assert 'GET /get HTTP' in r, "Don't default to POST."
|
assert 'GET /get HTTP' in r, "Don't default to POST."
|
||||||
assert FILE_CONTENT not in r, "Don't send stdin data."
|
assert FILE_CONTENT not in r, "Don't send stdin data."
|
||||||
@ -346,9 +347,9 @@ class TestSchemes:
|
|||||||
http('bah', '--default=scheme=foo+bar-BAZ.123')
|
http('bah', '--default=scheme=foo+bar-BAZ.123')
|
||||||
|
|
||||||
def test_default_scheme_option(self, httpbin_secure):
|
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')
|
assert HTTP_OK in http(url, '--default-scheme=https')
|
||||||
|
|
||||||
def test_scheme_when_invoked_as_https(self, httpbin_secure):
|
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')
|
assert HTTP_OK in http(url, program_name='https')
|
||||||
|
@ -11,8 +11,9 @@ our zlib-encoded request data.
|
|||||||
import base64
|
import base64
|
||||||
import zlib
|
import zlib
|
||||||
|
|
||||||
from fixtures import FILE_PATH, FILE_CONTENT
|
from .fixtures import FILE_PATH, FILE_CONTENT
|
||||||
from utils import http, HTTP_OK, MockEnvironment
|
from httpie.status import ExitStatus
|
||||||
|
from .utils import StdinBytesIO, http, HTTP_OK, MockEnvironment
|
||||||
|
|
||||||
|
|
||||||
def assert_decompressed_equal(base64_compressed_data, expected_str):
|
def assert_decompressed_equal(base64_compressed_data, expected_str):
|
||||||
@ -27,6 +28,20 @@ def assert_decompressed_equal(base64_compressed_data, expected_str):
|
|||||||
assert actual_str == expected_str
|
assert actual_str == expected_str
|
||||||
|
|
||||||
|
|
||||||
|
def test_cannot_combine_compress_with_chunked(httpbin):
|
||||||
|
r = http('--compress', '--chunked', httpbin.url + '/get',
|
||||||
|
tolerate_error_exit_status=True)
|
||||||
|
assert r.exit_status == ExitStatus.ERROR
|
||||||
|
assert 'cannot combine --compress and --chunked' in r.stderr
|
||||||
|
|
||||||
|
|
||||||
|
def test_cannot_combine_compress_with_multipart(httpbin):
|
||||||
|
r = http('--compress', '--multipart', httpbin.url + '/get',
|
||||||
|
tolerate_error_exit_status=True)
|
||||||
|
assert r.exit_status == ExitStatus.ERROR
|
||||||
|
assert 'cannot combine --compress and --multipart' in r.stderr
|
||||||
|
|
||||||
|
|
||||||
def test_compress_skip_negative_ratio(httpbin_both):
|
def test_compress_skip_negative_ratio(httpbin_both):
|
||||||
r = http(
|
r = http(
|
||||||
'--compress',
|
'--compress',
|
||||||
@ -77,16 +92,31 @@ def test_compress_form(httpbin_both):
|
|||||||
assert '"foo": "bar"' not in r
|
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):
|
def test_compress_stdin(httpbin_both):
|
||||||
with open(FILE_PATH) as f:
|
env = MockEnvironment(
|
||||||
env = MockEnvironment(stdin=f, stdin_isatty=False)
|
stdin=StdinBytesIO(FILE_PATH.read_bytes()),
|
||||||
r = http(
|
stdin_isatty=False,
|
||||||
'--compress',
|
)
|
||||||
'--compress',
|
r = http(
|
||||||
'PATCH',
|
'--compress',
|
||||||
httpbin_both + '/patch',
|
'--compress',
|
||||||
env=env,
|
'PATCH',
|
||||||
)
|
httpbin_both + '/patch',
|
||||||
|
env=env,
|
||||||
|
)
|
||||||
assert HTTP_OK in r
|
assert HTTP_OK in r
|
||||||
assert r.json['headers']['Content-Encoding'] == 'deflate'
|
assert r.json['headers']['Content-Encoding'] == 'deflate'
|
||||||
assert_decompressed_equal(r.json['data'], FILE_CONTENT.strip())
|
assert_decompressed_equal(r.json['data'], FILE_CONTENT.strip())
|
||||||
@ -100,7 +130,7 @@ def test_compress_file(httpbin_both):
|
|||||||
'--compress',
|
'--compress',
|
||||||
'PUT',
|
'PUT',
|
||||||
httpbin_both + '/put',
|
httpbin_both + '/put',
|
||||||
'file@' + FILE_PATH,
|
f'file@{FILE_PATH}',
|
||||||
)
|
)
|
||||||
assert HTTP_OK in r
|
assert HTTP_OK in r
|
||||||
assert r.json['headers']['Content-Encoding'] == 'deflate'
|
assert r.json['headers']['Content-Encoding'] == 'deflate'
|
||||||
|
@ -1,8 +1,16 @@
|
|||||||
|
from pathlib import Path
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
from _pytest.monkeypatch import MonkeyPatch
|
||||||
|
|
||||||
from httpie.compat import is_windows
|
from httpie.compat import is_windows
|
||||||
from httpie.config import Config
|
from httpie.constants import UTF8
|
||||||
from utils import HTTP_OK, MockEnvironment, http
|
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
|
||||||
|
|
||||||
|
|
||||||
def test_default_options(httpbin):
|
def test_default_options(httpbin):
|
||||||
@ -18,8 +26,7 @@ def test_default_options(httpbin):
|
|||||||
def test_config_file_not_valid(httpbin):
|
def test_config_file_not_valid(httpbin):
|
||||||
env = MockEnvironment()
|
env = MockEnvironment()
|
||||||
env.create_temp_config_dir()
|
env.create_temp_config_dir()
|
||||||
with (env.config_dir / Config.FILENAME).open('w') as f:
|
(env.config_dir / Config.FILENAME).write_text('{invalid json}', encoding=UTF8)
|
||||||
f.write('{invalid json}')
|
|
||||||
r = http(httpbin + '/get', env=env)
|
r = http(httpbin + '/get', env=env)
|
||||||
assert HTTP_OK in r
|
assert HTTP_OK in r
|
||||||
assert 'http: warning' in r.stderr
|
assert 'http: warning' in r.stderr
|
||||||
@ -48,3 +55,50 @@ def test_default_options_overwrite(httpbin):
|
|||||||
assert r.json['json'] == {
|
assert r.json['json'] == {
|
||||||
"foo": "bar"
|
"foo": "bar"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.skipif(is_windows, reason='XDG_CONFIG_HOME needs *nix')
|
||||||
|
def test_explicit_xdg_config_home(monkeypatch: MonkeyPatch, tmp_path: Path):
|
||||||
|
home_dir = tmp_path
|
||||||
|
monkeypatch.delenv(ENV_HTTPIE_CONFIG_DIR, raising=False)
|
||||||
|
monkeypatch.setenv('HOME', str(home_dir))
|
||||||
|
custom_xdg_config_home = home_dir / 'custom_xdg_config_home'
|
||||||
|
monkeypatch.setenv(ENV_XDG_CONFIG_HOME, str(custom_xdg_config_home))
|
||||||
|
expected_config_dir = custom_xdg_config_home / DEFAULT_CONFIG_DIRNAME
|
||||||
|
assert get_default_config_dir() == expected_config_dir
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.skipif(is_windows, reason='XDG_CONFIG_HOME needs *nix')
|
||||||
|
def test_default_xdg_config_home(monkeypatch: MonkeyPatch, tmp_path: Path):
|
||||||
|
home_dir = tmp_path
|
||||||
|
monkeypatch.delenv(ENV_HTTPIE_CONFIG_DIR, raising=False)
|
||||||
|
monkeypatch.delenv(ENV_XDG_CONFIG_HOME, raising=False)
|
||||||
|
monkeypatch.setenv('HOME', str(home_dir))
|
||||||
|
expected_config_dir = (
|
||||||
|
home_dir
|
||||||
|
/ DEFAULT_RELATIVE_XDG_CONFIG_HOME
|
||||||
|
/ DEFAULT_CONFIG_DIRNAME
|
||||||
|
)
|
||||||
|
assert get_default_config_dir() == expected_config_dir
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.skipif(is_windows, reason='legacy config dir needs *nix')
|
||||||
|
def test_legacy_config_dir(monkeypatch: MonkeyPatch, tmp_path: Path):
|
||||||
|
home_dir = tmp_path
|
||||||
|
monkeypatch.delenv(ENV_HTTPIE_CONFIG_DIR, raising=False)
|
||||||
|
monkeypatch.setenv('HOME', str(home_dir))
|
||||||
|
legacy_config_dir = home_dir / DEFAULT_RELATIVE_LEGACY_CONFIG_DIR
|
||||||
|
legacy_config_dir.mkdir()
|
||||||
|
assert get_default_config_dir() == legacy_config_dir
|
||||||
|
|
||||||
|
|
||||||
|
def test_custom_config_dir(monkeypatch: MonkeyPatch, tmp_path: Path):
|
||||||
|
httpie_config_dir = tmp_path / 'custom/directory'
|
||||||
|
monkeypatch.setenv(ENV_HTTPIE_CONFIG_DIR, str(httpie_config_dir))
|
||||||
|
assert get_default_config_dir() == httpie_config_dir
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.skipif(not is_windows, reason='windows-only')
|
||||||
|
def test_windows_config_dir(monkeypatch: MonkeyPatch):
|
||||||
|
monkeypatch.delenv(ENV_HTTPIE_CONFIG_DIR, raising=False)
|
||||||
|
assert get_default_config_dir() == DEFAULT_WINDOWS_CONFIG_DIR
|
||||||
|
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
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user