Experimental HTTP/2 plugin for HTTPie.
See: https://lukasa.co.uk/2015/02/Hyper_State_Of_Union/
$ pip install -U httpie httpie-http2
$ http https://nghttp2.org/httpbin/get
- Python 2.7.9 or 3.4+
- hyper
(DEPRECATED) Experimental HTTP/2 plugin for HTTPie
Home Page: https://httpie.org
License: Other
Experimental HTTP/2 plugin for HTTPie.
See: https://lukasa.co.uk/2015/02/Hyper_State_Of_Union/
$ pip install -U httpie httpie-http2
$ http https://nghttp2.org/httpbin/get
😸
HTTPie 1.0.0-dev
Requests 2.9.1
Pygments 2.1.3
Python 2.7.11 (default, Jan 22 2016, 08:29:18)
[GCC 4.2.1 Compatible Apple LLVM 7.0.2 (clang-700.1.81)]
/usr/local/opt/python/bin/python2.7
Darwin 15.4.0
<Environment {
"colors": 256,
"config": {
"__meta__": {
"about": "u'HTTPie configuration file'",
"help": "u'https://github.com/jkbrzt/httpie#config'",
"httpie": "u'1.0.0-dev'"
},
"default_options": "[u'--style=bw']"
},
"config_dir": "/Users/nhooyr/.httpie",
"is_windows": false,
"stderr": "<open file '<stderr>', mode 'w' at 0x1018f41e0>",
"stderr_isatty": false,
"stdin": "<open file '<stdin>', mode 'r' at 0x1018f40c0>",
"stdin_encoding": "UTF-8",
"stdin_isatty": true,
"stdout": "<open file '<stdout>', mode 'w' at 0x1018f4150>",
"stdout_encoding": "utf8",
"stdout_isatty": false
}>
>>> requests.request(**{
"allow_redirects": false,
"auth": "None",
"cert": "None",
"data": {},
"files": {},
"headers": {
"User-Agent": "HTTPie/1.0.0-dev"
},
"method": "get",
"params": {},
"proxies": {},
"stream": true,
"timeout": 30,
"url": "u'https://localhost'",
"verify": false
})
http: error: SSLError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:590)
Traceback (most recent call last):
File "/usr/local/bin/http", line 9, in <module>
load_entry_point('httpie==1.0.0.dev0', 'console_scripts', 'http')()
File "/usr/local/lib/python2.7/site-packages/httpie/core.py", line 227, in main
log_error=log_error,
File "/usr/local/lib/python2.7/site-packages/httpie/core.py", line 99, in program
final_response = get_response(args, config_dir=env.config.directory)
File "/usr/local/lib/python2.7/site-packages/httpie/client.py", line 70, in get_response
response = requests_session.request(**kwargs)
File "/usr/local/lib/python2.7/site-packages/requests/sessions.py", line 468, in request
resp = self.send(prep, **send_kwargs)
File "/usr/local/lib/python2.7/site-packages/requests/sessions.py", line 576, in send
r = adapter.send(request, **kwargs)
File "/usr/local/lib/python2.7/site-packages/hyper/contrib.py", line 66, in send
request.headers
File "/usr/local/lib/python2.7/site-packages/hyper/common/connection.py", line 98, in request
method=method, url=url, body=body, headers=headers
File "/usr/local/lib/python2.7/site-packages/hyper/http11/connection.py", line 164, in request
self.connect()
File "/usr/local/lib/python2.7/site-packages/hyper/http11/connection.py", line 128, in connect
sock, proto = wrap_socket(sock, host, self.ssl_context)
File "/usr/local/lib/python2.7/site-packages/hyper/tls.py", line 42, in wrap_socket
ssl_sock = _ssl_context.wrap_socket(sock, server_hostname=server_hostname)
File "/usr/local/Cellar/python/2.7.11/Frameworks/Python.framework/Versions/2.7/lib/python2.7/ssl.py", line 352, in wrap_socket
_context=self)
File "/usr/local/Cellar/python/2.7.11/Frameworks/Python.framework/Versions/2.7/lib/python2.7/ssl.py", line 579, in __init__
self.do_handshake()
File "/usr/local/Cellar/python/2.7.11/Frameworks/Python.framework/Versions/2.7/lib/python2.7/ssl.py", line 808, in do_handshake
self._sslobj.do_handshake()
ssl.SSLError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:590)
I tried to connect to google, but I got AttributeError.
(httpie)$ http --debug https://www.google.com
HTTPie 1.0.0-dev
HTTPie data: /Users/t2y/.httpie
Requests 2.5.1
Pygments 2.0.2
Python 3.4.2 (default, Nov 23 2014, 23:10:23)
[GCC 4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.54)] darwin
>>> requests.request({'allow_redirects': False,
'auth': None,
'cert': None,
'data': OrderedDict(),
'files': DataDict(),
'headers': {'User-Agent': b'HTTPie/1.0.0-dev'},
'method': 'get',
'params': ParamsDict(),
'proxies': {},
'stream': True,
'timeout': 30,
'url': 'https://www.google.com',
'verify': True})
Traceback (most recent call last):
File "/Users/t2y/.virtualenvs/httpie/bin/http", line 9, in <module>
load_entry_point('httpie==1.0.0-dev', 'console_scripts', 'http')()
File "/Users/t2y/work/external-repo/python/httpie/httpie/core.py", line 142, in main
write(**write_kwargs)
File "/Users/t2y/work/external-repo/python/httpie/httpie/output/streams.py", line 35, in write
for chunk in stream:
File "/Users/t2y/work/external-repo/python/httpie/httpie/output/streams.py", line 152, in __iter__
yield self.get_headers()
File "/Users/t2y/work/external-repo/python/httpie/httpie/output/streams.py", line 235, in get_headers
self.msg.headers).encode(self.output_encoding)
File "/Users/t2y/work/external-repo/python/httpie/httpie/models.py", line 54, in headers
original = self._orig.raw._original_response
AttributeError: 'HTTP20Response' object has no attribute '_original_response'
I am using with requests and hyper,
i send request to https://graph.facebook.com, after init about one minutes send request and hyper error
hyper.http20.exceptions.StreamResetError
I have installed both httpie
and httpie-http2
However, when I tried to make an http2 request with redirects, httpie
does not follow the HTTP/2 301
redirect:
Input: https --verbose https://google.com --follow
Output:
GET / HTTP/1.1
Accept: */*
Accept-Encoding: gzip, deflate
Connection: keep-alive
Host: google.com
User-Agent: HTTPie/2.4.0
HTTP/2 301
<HTML><HEAD><meta http-equiv="content-type" content="text/html;charset=utf-8">
<TITLE>301 Moved</TITLE></HEAD><BODY>
<H1>301 Moved</H1>
The document has moved
<A HREF="https://www.google.com/">here</A>.
</BODY></HTML>
With Python 3.4.3, on Mac OS X:
$ http --print Hh https://nghttp2.org/httpbin/get
GET /httpbin/get HTTP/1.1
Accept: */*
Accept-Encoding: gzip, deflate
Connection: keep-alive
Host: nghttp2.org
User-Agent: HTTPie/0.9.2
HTTP/2 200
But the headers are shown using vanilla httpie
:
$ http --print Hh https://nghttp2.org/httpbin/get
GET /httpbin/get HTTP/1.1
Accept: */*
Accept-Encoding: gzip, deflate
Connection: keep-alive
Host: nghttp2.org
User-Agent: HTTPie/0.9.2
HTTP/1.1 200 OK
Access-Control-Allow-Credentials: true
Access-Control-Allow-Origin: *
Connection: close
Content-Length: 258
Content-Type: application/json
Date: Sun, 27 Sep 2015 12:04:37 GMT
Server: nghttpx nghttp2/1.3.5-DEV
Strict-Transport-Security: max-age=31536000
Via: 1.1 nghttpx
X-Backend-Header-Rtt: 0.002355
Should be HTTP/2 200 OK
// cc @Lukasa
Below is a class I use to send notifications to my iPhone 7. I'm running this under Debian on a Raspberry Pi 2 B. The first time I call the send_notification method, it works fine. The second time, I get the lines below in my log file, but it doesn't seem to return, since I don't hit either the logging after a successful call or the logging in the exception handler.
import jwt
import time
import json
from hyper import HTTPConnection
import logging
class Apns:
ALGORITHM = 'ES256'
APNS_KEY_ID = '4A66263KZ6'
APNS_AUTH_KEY = 'AuthKey_4A66263KZ6.p8'
TEAM_ID = 'JUPE6KNM4G'
f = open(APNS_AUTH_KEY)
secret = f.read()
token = jwt.encode(
{
'iss': TEAM_ID,
'iat': time.time()
},
secret,
algorithm= ALGORITHM,
headers={
'alg': ALGORITHM,
'kid': APNS_KEY_ID,
}
)
BUNDLE_ID = 'com.ccyl.alarm'
registration_id = ['fb15ba7e9546977c403229bbda9073f8b59e670f5ebfaf1cad41931aa24db290']
path = '/3/device/{0}'.format(registration_id[0])
request_headers = {
'apns-expiration': '0',
'apns-priority': '10',
'apns-topic': BUNDLE_ID,
'authorization': 'bearer {0}'.format(token.decode('ascii'))
}
def send_notification(self, message, sound_file_name='blah.mp3', log_level = logging.INFO):
try:
logging.basicConfig(filename='./logfile.log',level=log_level)
payload_data = {
'aps': { 'alert' : message,
'sound' : 'www/' + sound_file_name }
}
payload = json.dumps(payload_data).encode('utf-8')
conn = HTTPConnection('api.development.push.apple.com:443')
conn.request(
'POST',
Apns.path,
payload,
headers=Apns.request_headers
)
resp = conn.get_response()
conn.close()
logging.debug(resp.status)
logging.debug(resp.read())
except:
logging.debug("Unexpected error:", sys.exc_info()[0])
ERROR:
INFO:hyper.http20.connection:Received unhandled event <RemoteSettingsChanged changed_settings:{ChangedSetting(setting=SettingCodes.HEADER_TABLE_SIZE, original_value=4096, new_value=4096), ChangedSetting(setting=SettingCodes.MAX_CONCURRENT_STREAMS, original_value=None, new_value=1), ChangedSetting(setting=SettingCodes._max_frame_size, original_value=16384, new_value=16384), ChangedSetting(setting=SettingCodes._max_header_list_size, original_value=None, new_value=8000)}>
INFO:hyper.http20.connection:Received unhandled event <SettingsAcknowledged changed_settings:{ChangedSetting(setting=SettingCodes.ENABLE_PUSH, original_value=1, new_value=0)}>
INFO:hyper.http20.connection:Received unhandled event <SettingsAcknowledged changed_settings:{}>
INFO:hyper.http20.connection:Received unhandled event <RemoteSettingsChanged changed_settings:{ChangedSetting(setting=SettingCodes.HEADER_TABLE_SIZE, original_value=4096, new_value=4096), ChangedSetting(setting=SettingCodes.MAX_CONCURRENT_STREAMS, original_value=1, new_value=1000), ChangedSetting(setting=SettingCodes.INITIAL_WINDOW_SIZE, original_value=65535, new_value=65535), ChangedSetting(setting=SettingCodes._max_frame_size, original_value=16384, new_value=16384), ChangedSetting(setting=SettingCodes._max_header_list_size, original_value=8000, new_value=8000)}>
Just after installing httpie-http2 it's not possible to make any request with the following error:
http: error: AttributeError: 'module' object has no attribute 'OP_NO_COMPRESSION'
Here's the versions:
httpie-http2==0.0.1
httplib2==0.9.2
hyper==0.5.0```
It's hardcoded in HTTPie. Unclear how to obtain the actual version.
$ http -v https://nghttp2.org/httpbin/get
GET /httpbin/get HTTP/1.1
Accept: */*
Accept-Encoding: gzip, deflate
Connection: keep-alive
Host: nghttp2.org
User-Agent: HTTPie/0.9.1
HTTP/2 200
access-control-allow-credentials: true
access-control-allow-origin: *
content-length: 268
content-type: application/json
date: Sat, 07 Feb 2015 17:02:52 GMT
server: nghttpx nghttp2/0.7.4-DEV
strict-transport-security: max-age=31536000
via: 1.1 nghttpx
…even though it's not used by HTTP/2
$ http -v https://nghttp2.org/httpbin/get
GET /httpbin/get HTTP/1.1
Accept: */*
Accept-Encoding: gzip, deflate
Connection: keep-alive
Host: nghttp2.org
User-Agent: HTTPie/0.9.1
HTTP/2 200
access-control-allow-credentials: true
access-control-allow-origin: *
content-length: 268
content-type: application/json
date: Sat, 07 Feb 2015 17:02:52 GMT
server: nghttpx nghttp2/0.7.4-DEV
strict-transport-security: max-age=31536000
via: 1.1 nghttpx
This issue occurs both on the current stable HTTPie release, 0.9.9, and on the bleeding-edge development version de38f86
installed using pip3 install --upgrade https://github.com/jkbrzt/httpie/archive/master.tar.gz
.
After installing httpie-http2
with pip3 install httpie-http2
, every attempt to make an HTTP/2 request will fail, printing the error message http: error: ProtocolError: Connection-specific header field present: b'connection'.
The full --debug
output is:
$ http https://google.com --debug
HTTPie 0.9.9
Requests 2.13.0
Pygments 2.2.0
Python 3.6.0 (default, Dec 24 2016, 08:01:42)
[GCC 4.2.1 Compatible Apple LLVM 8.0.0 (clang-800.0.42.1)]
/usr/local/opt/python3/bin/python3.6
Darwin 16.5.0
<Environment {
"colors": 256,
"config": {
"__meta__": {
"about": "HTTPie configuration file",
"help": "https://github.com/jkbrzt/httpie#config",
"httpie": "1.0.0-dev"
},
"default_options": "[]"
},
"config_dir": "/Users/dani/.httpie",
"is_windows": false,
"stderr": "<_io.TextIOWrapper name='<stderr>' mode='w' encoding='UTF-8'>",
"stderr_isatty": true,
"stdin": "<_io.TextIOWrapper name='<stdin>' mode='r' encoding='UTF-8'>",
"stdin_encoding": "UTF-8",
"stdin_isatty": true,
"stdout": "<_io.TextIOWrapper name='<stdout>' mode='w' encoding='UTF-8'>",
"stdout_encoding": "UTF-8",
"stdout_isatty": true
}>
>>> requests.request(**{
"allow_redirects": false,
"auth": "None",
"cert": "None",
"data": {},
"files": {},
"headers": {
"User-Agent": "HTTPie/0.9.9"
},
"method": "get",
"params": {},
"proxies": {},
"stream": true,
"timeout": 30,
"url": "https://google.com",
"verify": true
})
http: error: ProtocolError: Connection-specific header field present: b'connection'.
Traceback (most recent call last):
File "/usr/local/lib/python3.6/site-packages/hyper/common/connection.py", line 103, in request
method=method, url=url, body=body, headers=headers
File "/usr/local/lib/python3.6/site-packages/hyper/http11/connection.py", line 169, in request
self.connect()
File "/usr/local/lib/python3.6/site-packages/hyper/http11/connection.py", line 130, in connect
raise TLSUpgrade(proto, sock)
hyper.common.exceptions.TLSUpgrade
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/usr/local/bin/http", line 11, in <module>
sys.exit(main())
File "/usr/local/lib/python3.6/site-packages/httpie/__main__.py", line 11, in main
sys.exit(main())
File "/usr/local/lib/python3.6/site-packages/httpie/core.py", line 227, in main
log_error=log_error,
File "/usr/local/lib/python3.6/site-packages/httpie/core.py", line 99, in program
final_response = get_response(args, config_dir=env.config.directory)
File "/usr/local/lib/python3.6/site-packages/httpie/client.py", line 70, in get_response
response = requests_session.request(**kwargs)
File "/usr/local/lib/python3.6/site-packages/requests/sessions.py", line 488, in request
resp = self.send(prep, **send_kwargs)
File "/usr/local/lib/python3.6/site-packages/requests/sessions.py", line 609, in send
r = adapter.send(request, **kwargs)
File "/usr/local/lib/python3.6/site-packages/hyper/contrib.py", line 78, in send
request.headers
File "/usr/local/lib/python3.6/site-packages/hyper/common/connection.py", line 121, in request
method=method, url=url, body=body, headers=headers
File "/usr/local/lib/python3.6/site-packages/hyper/http20/connection.py", line 281, in request
self.endheaders(message_body=body, final=True, stream_id=stream_id)
File "/usr/local/lib/python3.6/site-packages/hyper/http20/connection.py", line 555, in endheaders
stream.send_headers(headers_only)
File "/usr/local/lib/python3.6/site-packages/hyper/http20/stream.py", line 98, in send_headers
conn.send_headers(self.stream_id, headers, end_stream)
File "/usr/local/lib/python3.6/site-packages/h2/connection.py", line 813, in send_headers
headers, self.encoder, end_stream
File "/usr/local/lib/python3.6/site-packages/h2/stream.py", line 788, in send_headers
headers, encoder, hf, hdr_validation_flags
File "/usr/local/lib/python3.6/site-packages/h2/stream.py", line 1119, in _build_headers_frames
encoded_headers = encoder.encode(headers)
File "/usr/local/lib/python3.6/site-packages/hpack/hpack.py", line 229, in encode
for header in headers:
File "/usr/local/lib/python3.6/site-packages/h2/utilities.py", line 368, in _validate_host_authority_header
for header in headers:
File "/usr/local/lib/python3.6/site-packages/h2/utilities.py", line 302, in _reject_pseudo_header_fields
for header in headers:
File "/usr/local/lib/python3.6/site-packages/h2/utilities.py", line 274, in _reject_connection_header
"Connection-specific header field present: %s." % header[0]
h2.exceptions.ProtocolError: Connection-specific header field present: b'connection'.
HTTP/1.1 requests are unaffected even when httpie-http2
is installed, presumably because the plugin only does anything if you're actually trying to use HTTP/2, but all requests to HTTP/2 hosts become impossible.
this httpie-http2 is just broken, does not work at all for anything, have to uninstall:
$ httpie --verbose https://h2book.com
GET / HTTP/1.1
Accept-Encoding: gzip, deflate
Accept: */*
Connection: keep-alive
User-Agent: HTTPie/3.1.0
Host: h2book.com
__main__.py: error: TypeError: sequence item 0: expected str instance, bytes found
➸ python3 -V
Python 3.9.7
I'd like to use http
with HTTP/2 to test localhost served by Caddy and its localhost self-signed certificates. However, even with option --verify no
, http
(with httpie-http2
) still verifies the certificate:
$ http --verify no https://localhost
http: error: SSLError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:852)
Without httpie-http2
, http
works fine.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.