mirror of
https://github.com/HoneyryderChuck/httpx.git
synced 2025-10-09 00:02:50 -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 HTTPX
|
||||||
module Plugins
|
module Plugins
|
||||||
module Compression
|
module Compression
|
||||||
ACCEPT_ENCODING = %w[gzip deflate].freeze
|
extend Registry
|
||||||
|
|
||||||
def self.configure(klass, *)
|
def self.configure(klass, *)
|
||||||
klass.plugin(:"compression/gzip")
|
klass.plugin(:"compression/gzip")
|
||||||
klass.plugin(:"compression/deflate")
|
klass.plugin(:"compression/deflate")
|
||||||
end
|
end
|
||||||
|
|
||||||
module RequestMethods
|
module InstanceMethods
|
||||||
def initialize(*)
|
def initialize(opts = {})
|
||||||
super
|
super(opts.merge(headers: {"accept-encoding" => Compression.registry.keys}))
|
||||||
ACCEPT_ENCODING.each do |enc|
|
|
||||||
@headers.add("accept-encoding", enc)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -78,10 +74,7 @@ module HTTPX
|
|||||||
# @buffer.close
|
# @buffer.close
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
register_plugin :compression, Compression
|
register_plugin :compression, Compression
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
end
|
end
|
||||||
|
@ -12,6 +12,7 @@ module HTTPX
|
|||||||
|
|
||||||
def self.configure(*)
|
def self.configure(*)
|
||||||
Transcoder.register "br", BrotliTranscoder
|
Transcoder.register "br", BrotliTranscoder
|
||||||
|
Compression.register "br", self
|
||||||
end
|
end
|
||||||
|
|
||||||
module ResponseBodyMethods
|
module ResponseBodyMethods
|
||||||
|
@ -4,7 +4,6 @@ module HTTPX
|
|||||||
module Plugins
|
module Plugins
|
||||||
module Compression
|
module Compression
|
||||||
module Deflate
|
module Deflate
|
||||||
|
|
||||||
def self.load_dependencies(*)
|
def self.load_dependencies(*)
|
||||||
require "stringio"
|
require "stringio"
|
||||||
require "zlib"
|
require "zlib"
|
||||||
@ -12,6 +11,7 @@ module HTTPX
|
|||||||
|
|
||||||
def self.configure(*)
|
def self.configure(*)
|
||||||
Transcoder.register "deflate", DeflateTranscoder
|
Transcoder.register "deflate", DeflateTranscoder
|
||||||
|
Compression.register "deflate", self
|
||||||
end
|
end
|
||||||
|
|
||||||
module DeflateTranscoder
|
module DeflateTranscoder
|
||||||
|
@ -4,13 +4,13 @@ module HTTPX
|
|||||||
module Plugins
|
module Plugins
|
||||||
module Compression
|
module Compression
|
||||||
module GZIP
|
module GZIP
|
||||||
|
|
||||||
def self.load_dependencies(*)
|
def self.load_dependencies(*)
|
||||||
require "zlib"
|
require "zlib"
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.configure(*)
|
def self.configure(*)
|
||||||
Transcoder.register "gzip", GZIPTranscoder
|
Transcoder.register "gzip", GZIPTranscoder
|
||||||
|
Compression.register "gzip", self
|
||||||
end
|
end
|
||||||
|
|
||||||
module GZIPTranscoder
|
module GZIPTranscoder
|
||||||
@ -57,7 +57,6 @@ module HTTPX
|
|||||||
Zlib::GzipReader.new(io, window_size: 32 + Zlib::MAX_WBITS)
|
Zlib::GzipReader.new(io, window_size: 32 + Zlib::MAX_WBITS)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
register_plugin :"compression/gzip", Compression::GZIP
|
register_plugin :"compression/gzip", Compression::GZIP
|
||||||
|
Loading…
x
Reference in New Issue
Block a user