{"record":{"id":"d94ea4a70e629cca","repo":"jnunemaker/httparty","slug":"self-class-name-has-not-implemented-a-decompres","errorCode":null,"errorMessage":"#{self.class.name} has not implemented a decompression method for #{encoding.inspect} encoding.","messagePattern":"#(.+?) has not implemented a decompression method for #(.+?) encoding\\.","errorType":"exception","errorClass":"NotImplementedError","httpStatus":null,"severity":"error","filePath":"lib/httparty/decompressor.rb","lineNumber":64,"sourceCode":"      if supports_encoding?\n        decompress_supported_encoding\n      else\n        nil\n      end\n    end\n\n    protected\n\n    def supports_encoding?\n      SupportedEncodings.keys.include?(encoding)\n    end\n\n    def decompress_supported_encoding\n      method = SupportedEncodings[encoding]\n      if respond_to?(method, true)\n        send(method)\n      else\n        raise NotImplementedError, \"#{self.class.name} has not implemented a decompression method for #{encoding.inspect} encoding.\"\n      end\n    end\n\n    def none\n      body\n    end\n\n    def brotli\n      return nil unless defined?(::Brotli)\n      begin\n        ::Brotli.inflate(body)\n      rescue StandardError\n        nil\n      end\n    end\n\n    def lzw\n      begin","sourceCodeStart":46,"sourceCodeEnd":82,"githubUrl":"https://github.com/jnunemaker/httparty/blob/8f4a09e343b94de9f934f388028ca97620c9b378/lib/httparty/decompressor.rb#L46-L82","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"# before\nclass LoggedDecompressor < HTTParty::Decompressor\n  def brotli\n    Rails.logger.info('brotli') && super\n  end\n  # no zstd method -> NotImplementedError on Content-Encoding: zstd\nend\n\n# after\nclass LoggedDecompressor < HTTParty::Decompressor\n  def brotli\n    Rails.logger.info('brotli'); super\n  end\n\n  def zstd\n    Rails.logger.info('zstd'); super\n  end\nend","handlingStrategy":"validation","validationCode":"method = HTTParty::Decompressor::SupportedEncodings[content_encoding]\nraise NotImplementedError, \"decompressor cannot handle #{content_encoding}\" unless method && decompressor.respond_to?(method)","typeGuard":"handles_encoding = ->(enc, dec = MyDecompressor) do\n  m = HTTParty::Decompressor::SupportedEncodings[enc]\n  !m.nil? && dec.method_defined?(m)\nend","tryCatchPattern":"begin\n  Foo.get(url)\nrescue NotImplementedError => e\n  raise unless e.message.include?('decompression method')\n  Foo.get(url, headers: { 'Accept-Encoding' => 'gzip, deflate' })  # avoid unsupported encodings\nend","preventionTips":["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."],"tags":["ruby","httparty","decompression","content-encoding","not-implemented","response-body"],"backgroundTag":"unsupported-content-encoding","analyzedSha":"8f4a09e343b94de9f934f388028ca97620c9b378","analyzedAt":"2026-08-21T19:30:42.003Z","schemaVersion":2},"datasetVersion":"2026-08-21T23:17:16.201Z"}