adding the accept-encoding header with the registered compression methods

This commit is contained in:
HoneyryderChuck 2018-01-14 20:37:47 +00:00
parent 402a8ad2d4
commit 8b45c626ce
4 changed files with 7 additions and 14 deletions

View File

@ -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

View File

@ -12,6 +12,7 @@ module HTTPX
def self.configure(*)
Transcoder.register "br", BrotliTranscoder
Compression.register "br", self
end
module ResponseBodyMethods

View File

@ -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

View File

@ -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