mirror of
https://github.com/HoneyryderChuck/httpx.git
synced 2025-08-10 00:01:27 -04:00
adding the accept-encoding header with the registered compression methods
This commit is contained in:
parent
402a8ad2d4
commit
8b45c626ce
@ -3,19 +3,15 @@
|
||||
module HTTPX
|
||||
module Plugins
|
||||
module Compression
|
||||
ACCEPT_ENCODING = %w[gzip deflate].freeze
|
||||
|
||||
extend Registry
|
||||
def self.configure(klass, *)
|
||||
klass.plugin(:"compression/gzip")
|
||||
klass.plugin(:"compression/deflate")
|
||||
end
|
||||
|
||||
module RequestMethods
|
||||
def initialize(*)
|
||||
super
|
||||
ACCEPT_ENCODING.each do |enc|
|
||||
@headers.add("accept-encoding", enc)
|
||||
end
|
||||
module InstanceMethods
|
||||
def initialize(opts = {})
|
||||
super(opts.merge(headers: {"accept-encoding" => Compression.registry.keys}))
|
||||
end
|
||||
end
|
||||
|
||||
@ -78,10 +74,7 @@ module HTTPX
|
||||
# @buffer.close
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
register_plugin :compression, Compression
|
||||
end
|
||||
|
||||
|
||||
end
|
||||
|
@ -12,6 +12,7 @@ module HTTPX
|
||||
|
||||
def self.configure(*)
|
||||
Transcoder.register "br", BrotliTranscoder
|
||||
Compression.register "br", self
|
||||
end
|
||||
|
||||
module ResponseBodyMethods
|
||||
|
@ -4,7 +4,6 @@ module HTTPX
|
||||
module Plugins
|
||||
module Compression
|
||||
module Deflate
|
||||
|
||||
def self.load_dependencies(*)
|
||||
require "stringio"
|
||||
require "zlib"
|
||||
@ -12,6 +11,7 @@ module HTTPX
|
||||
|
||||
def self.configure(*)
|
||||
Transcoder.register "deflate", DeflateTranscoder
|
||||
Compression.register "deflate", self
|
||||
end
|
||||
|
||||
module DeflateTranscoder
|
||||
|
@ -4,13 +4,13 @@ module HTTPX
|
||||
module Plugins
|
||||
module Compression
|
||||
module GZIP
|
||||
|
||||
def self.load_dependencies(*)
|
||||
require "zlib"
|
||||
end
|
||||
|
||||
def self.configure(*)
|
||||
Transcoder.register "gzip", GZIPTranscoder
|
||||
Compression.register "gzip", self
|
||||
end
|
||||
|
||||
module GZIPTranscoder
|
||||
@ -57,7 +57,6 @@ module HTTPX
|
||||
Zlib::GzipReader.new(io, window_size: 32 + Zlib::MAX_WBITS)
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
register_plugin :"compression/gzip", Compression::GZIP
|
||||
|
Loading…
x
Reference in New Issue
Block a user