nghttp
A client for HTTP goodness. Inspired by python-requests and daily need.
Installation
Add this to your application's shard.yml:
dependencies:
nghttp:
github: bmmcginty/nghttp
Usage
require "nghttp"
# Create a session.
# It can persist cookies and connections.
s=NGHTTP::Session.new
# Override the user-agent header.
s.headers["User-Agent"]="New User-Agent"
# Enable the cache.
s.config.cache=true
s.config.cache_expires=1.hours
body = s.get"https://example.org/") do |resp|
resp.xml
end
Testing
The spec suite starts a local Python httpbin process by default.
Set NGHTTP_SPEC_HTTPBIN_URL to use an already-running httpbin server instead.
Set NGHTTP_SPEC_KEEP_ALIVE_URL to use an already-running keep-alive test server.
HTTP/2 specs use local h2c and TLS ALPN servers by default.
Set NGHTTP_SPEC_EXTERNAL_HTTP2_URL to run the opt-in external HTTP/2 interoperability spec.
See spec/nghttp_spec.cr, spec/nghttp_http2_protocol_spec.cr, and docs/http2-ci.md.
Development
Most code can be found in the handlers directory.
TODO
- Define replayable vs one-shot request bodies so automatic retries can avoid resending non-rewindable upload streams.
- Add specs for retry behavior with
String,IO::Memory,File, custom rewindable IO, and non-rewindable streaming IO request bodies. - Add a body factory API for large replayable uploads, such as reopening a file per attempt instead of keeping one mutable IO object.
- Make HTTP/2 upload streaming stop promptly when the stream receives an early error such as
REFUSED_STREAM.
Contributing
- Fork it ( https://github.com/bmmcginty/nghttp/fork )
- Create your feature branch (git checkout -b my-new-feature)
- Commit your changes (git commit -am 'Add some feature')
- Push to the branch (git push origin my-new-feature)
- Create a new Pull Request
Contributors
- bmmcginty Brandon McGinty - creator, maintainer