mirror of
https://github.com/HoneyryderChuck/httpx.git
synced 2025-07-29 00:01:31 -04:00
Compare commits
8 Commits
5feba82ffb
...
b1fc1907ab
Author | SHA1 | Date | |
---|---|---|---|
|
b1fc1907ab | ||
|
c1a25d34d3 | ||
|
5a9113e445 | ||
|
cc4b8d4c9e | ||
|
890d4b8d50 | ||
|
76737b3b99 | ||
|
31ec7a2ecf | ||
|
2e32aa6707 |
4
Gemfile
4
Gemfile
@ -55,9 +55,9 @@ group :test do
|
||||
end
|
||||
|
||||
group :lint do
|
||||
gem "rubocop"
|
||||
gem "rubocop", "~> 1.59.0"
|
||||
gem "rubocop-md"
|
||||
gem "rubocop-performance"
|
||||
gem "rubocop-performance", "~> 1.19.0"
|
||||
end
|
||||
|
||||
group :coverage do
|
||||
|
@ -3,6 +3,14 @@
|
||||
require "forwardable"
|
||||
|
||||
module HTTPX
|
||||
# Internal class to abstract a string buffer, by wrapping a string and providing the
|
||||
# minimum possible API and functionality required.
|
||||
#
|
||||
# buffer = Buffer.new(640)
|
||||
# buffer.full? #=> false
|
||||
# buffer << "aa"
|
||||
# buffer.capacity #=> 638
|
||||
#
|
||||
class Buffer
|
||||
extend Forwardable
|
||||
|
||||
|
@ -1,6 +1,8 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
module HTTPX
|
||||
# Session mixin, implements most of the APIs that the users call.
|
||||
# delegates to a default session when extended.
|
||||
module Chainable
|
||||
%w[head get post put delete trace options connect patch].each do |meth|
|
||||
class_eval(<<-MOD, __FILE__, __LINE__ + 1)
|
||||
@ -10,6 +12,7 @@ module HTTPX
|
||||
MOD
|
||||
end
|
||||
|
||||
# delegates to the default session (see HTTPX::Session#request).
|
||||
def request(*args, **options)
|
||||
branch(default_options).request(*args, **options)
|
||||
end
|
||||
@ -18,10 +21,12 @@ module HTTPX
|
||||
with(headers: { "accept" => String(type) })
|
||||
end
|
||||
|
||||
# delegates to the default session (see HTTPX::Session#wrap).
|
||||
def wrap(&blk)
|
||||
branch(default_options).wrap(&blk)
|
||||
end
|
||||
|
||||
# returns a new instance loaded with the +pl+ plugin and +options+.
|
||||
def plugin(pl, options = nil, &blk)
|
||||
klass = is_a?(S) ? self.class : Session
|
||||
klass = Class.new(klass)
|
||||
@ -29,16 +34,19 @@ module HTTPX
|
||||
klass.plugin(pl, options, &blk).new
|
||||
end
|
||||
|
||||
# returns a new instance loaded with +options+.
|
||||
def with(options, &blk)
|
||||
branch(default_options.merge(options), &blk)
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
# returns default instance of HTTPX::Options.
|
||||
def default_options
|
||||
@options || Session.default_options
|
||||
end
|
||||
|
||||
# returns a default instance of HTTPX::Session.
|
||||
def branch(options, &blk)
|
||||
return self.class.new(options, &blk) if is_a?(S)
|
||||
|
||||
|
@ -700,7 +700,7 @@ module HTTPX
|
||||
interval = @timers.after(timeout, callback)
|
||||
|
||||
Array(finish_events).each do |event|
|
||||
# clean up reques timeouts if the connection errors out
|
||||
# clean up request timeouts if the connection errors out
|
||||
request.once(event) do
|
||||
if @intervals.include?(interval)
|
||||
interval.delete(callback)
|
||||
|
@ -99,7 +99,7 @@ module HTTPX
|
||||
# :compress_request_body :: whether to auto-decompress response body (defaults to <tt>true</tt>)
|
||||
# :timeout :: hash of timeout configurations (supports <tt>:connect_timeout</tt>, <tt>:settings_timeout</tt>,
|
||||
# <tt>:operation_timeout</tt>, <tt>:keep_alive_timeout</tt>, <tt>:read_timeout</tt>, <tt>:write_timeout</tt>
|
||||
# and <tt>:request_timeout</tt>
|
||||
# and <tt>:request_timeout</tt>
|
||||
# :headers :: hash of HTTP headers (ex: <tt>{ "x-custom-foo" => "bar" }</tt>)
|
||||
# :window_size :: number of bytes to read from a socket
|
||||
# :buffer_size :: internal read and write buffer size in bytes
|
||||
|
@ -138,9 +138,14 @@ module HTTPX
|
||||
# Indicates no such domain was found.
|
||||
|
||||
host = @requests.delete(request)
|
||||
connection = reset_hostname(host)
|
||||
connection = reset_hostname(host, reset_candidates: false)
|
||||
|
||||
emit_resolve_error(connection)
|
||||
unless @queries.value?(connection)
|
||||
emit_resolve_error(connection)
|
||||
return
|
||||
end
|
||||
|
||||
resolve
|
||||
when :dns_error
|
||||
host = @requests.delete(request)
|
||||
connection = reset_hostname(host)
|
||||
|
@ -70,9 +70,10 @@ module HTTPX
|
||||
@body.write(data)
|
||||
end
|
||||
|
||||
# returns the response mime type, as per what's declared in the content-type header.
|
||||
# returns the HTTPX::ContentType for the response, as per what's declared in the content-type header.
|
||||
#
|
||||
# response.content_type #=> "text/plain"
|
||||
# response.content_type #=> #<HTTPX::ContentType:xxx @header_value="text/plain">
|
||||
# response.content_type.mime_type #=> "text/plain"
|
||||
def content_type
|
||||
@content_type ||= ContentType.new(@headers["content-type"])
|
||||
end
|
||||
|
@ -166,6 +166,7 @@ module HTTPX
|
||||
|
||||
private
|
||||
|
||||
# prepares inflaters for the advertised encodings in "content-encoding" header.
|
||||
def initialize_inflaters
|
||||
@inflaters = nil
|
||||
|
||||
@ -187,6 +188,7 @@ module HTTPX
|
||||
end
|
||||
end
|
||||
|
||||
# passes the +chunk+ through all inflaters to decode it.
|
||||
def decode_chunk(chunk)
|
||||
@inflaters.reverse_each do |inflater|
|
||||
chunk = inflater.call(chunk)
|
||||
@ -195,6 +197,7 @@ module HTTPX
|
||||
chunk
|
||||
end
|
||||
|
||||
# tries transitioning the body STM to the +nextstate+.
|
||||
def transition(nextstate)
|
||||
case nextstate
|
||||
when :open
|
||||
|
@ -39,7 +39,7 @@ class HTTP1ParserTest < Minitest::Test
|
||||
JSON.parse(File.read(File.expand_path("support/responses.json", __dir__))).each do |res_json|
|
||||
res_json["headers"] ||= {}
|
||||
|
||||
define_method "test_parse_response_#{res_json["name"]}" do
|
||||
define_method :"test_parse_response_#{res_json["name"]}" do
|
||||
observer = RequestObserver.new
|
||||
parser = observer.parser
|
||||
begin
|
||||
|
@ -45,7 +45,7 @@ module Requests
|
||||
end
|
||||
|
||||
%w[SHA1 SHA2 SHA256 SHA384 SHA512 RMD160].each do |alg|
|
||||
define_method "test_plugin_digest_auth_#{alg}" do
|
||||
define_method :"test_plugin_digest_auth_#{alg}" do
|
||||
session = HTTPX.plugin(:digest_auth).with_headers("cookie" => "fake=fake_value")
|
||||
response = session.digest_auth(user, pass).get("#{digest_auth_uri}/#{alg}")
|
||||
verify_status(response, 200)
|
||||
@ -56,7 +56,7 @@ module Requests
|
||||
end
|
||||
|
||||
%w[MD5 SHA1].each do |alg|
|
||||
define_method "test_plugin_digest_auth_#{alg}_sess" do
|
||||
define_method :"test_plugin_digest_auth_#{alg}_sess" do
|
||||
start_test_servlet(DigestServer, algorithm: "#{alg}-sess") do |server|
|
||||
uri = "#{server.origin}/"
|
||||
session = HTTPX.plugin(:digest_auth).with_headers("cookie" => "fake=fake_value")
|
||||
|
Loading…
x
Reference in New Issue
Block a user