jnunemaker/httparty · error · NotImplementedError
#{self.class.name} has not implemented a decompression metho
Error message
#{self.class.name} has not implemented a decompression method for #{encoding.inspect} encoding. What it means
The Decompressor raises NotImplementedError (from decompress_supported_encoding) when the response's Content-Encoding maps to a method the decompressor class does not define. SupportedEncodings maps 'none'/'identity' to :none, 'br' to :brotli, 'compress' to :lzw and 'zstd' to :zstd; a subclass of HTTParty::Decompressor that omits one of those instance methods will blow up when a server sends that encoding. Note the base class itself deliberately returns nil (not an error) when the optional Brotli gem is missing, so this raise is specifically about a missing method on a custom subclass.
Source
Thrown at lib/httparty/decompressor.rb:64
if supports_encoding?
decompress_supported_encoding
else
nil
end
end
protected
def supports_encoding?
SupportedEncodings.keys.include?(encoding)
end
def decompress_supported_encoding
method = SupportedEncodings[encoding]
if respond_to?(method, true)
send(method)
else
raise NotImplementedError, "#{self.class.name} has not implemented a decompression method for #{encoding.inspect} encoding."
end
end
def none
body
end
def brotli
return nil unless defined?(::Brotli)
begin
::Brotli.inflate(body)
rescue StandardError
nil
end
end
def lzw
beginView on GitHub (pinned to 8f4a09e343)
Solutions
- Define the missing method on the subclass (`def zstd; ...; end`) or remove the override so it inherits.
- For brotli/zstd support, add the requisite gem (`brotli`, `zstd-ruby`) to the Gemfile and let the built-in methods work.
- Strip the Accept-Encoding request header so the server does not negotiate the unsupported encoding.
Example fix
# before
class LoggedDecompressor < HTTParty::Decompressor
def brotli
Rails.logger.info('brotli') && super
end
# no zstd method -> NotImplementedError on Content-Encoding: zstd
end
# after
class LoggedDecompressor < HTTParty::Decompressor
def brotli
Rails.logger.info('brotli'); super
end
def zstd
Rails.logger.info('zstd'); super
end
end Defensive patterns
Strategy: validation
Validate before calling
method = HTTParty::Decompressor::SupportedEncodings[content_encoding]
raise NotImplementedError, "decompressor cannot handle #{content_encoding}" unless method && decompressor.respond_to?(method) Type guard
handles_encoding = ->(enc, dec = MyDecompressor) do m = HTTParty::Decompressor::SupportedEncodings[enc] !m.nil? && dec.method_defined?(m) end
Try / catch
begin
Foo.get(url)
rescue NotImplementedError => e
raise unless e.message.include?('decompression method')
Foo.get(url, headers: { 'Accept-Encoding' => 'gzip, deflate' }) # avoid unsupported encodings
end Prevention
- Prefer subclassing HTTParty::Decompressor and only adding behavior, so all encodings stay inherited.
- Add optional compression gems (brotli, zstd) when servers may negotiate them.
- Pin Accept-Encoding to what you can decode when calling unknown servers.
When it happens
Trigger: A custom `class MyDecompressor < HTTParty::Decompressor` that overrides or trims methods, then a server responds with `Content-Encoding: zstd` (or 'compress'/'br') and the decompressor tries to `send(:zstd)` which does not exist.
Common situations: Subclassing Decompressor to add logging or custom decompression and forgetting to keep all SupportedEncodings methods, new encodings (zstd) arriving from upgraded servers/CDNs, and copy-pasted decompressor subclasses from older httparty versions that predate a new encoding entry.
Related errors
- #{self.class.name} has not implemented a parsing method for
- #{response}
- Default params must be an object which responds to #to_hash
- Headers must be an object which responds to #to_hash
- Cookies must be an object which responds to #to_hash
AI-assisted analysis of jnunemaker/httparty@8f4a09e343 (2026-08-21).
Data as JSON: /api/errors/d94ea4a70e629cca.
Report an issue: GitHub.