jnunemaker/httparty · error · ArgumentError
only get, post, patch, put, delete, head, and options method
Error message
only get, post, patch, put, delete, head, and options methods are supported
What it means
Request#validate raises ArgumentError 'only get, post, patch, put, delete, head, and options methods are supported' unless http_method is in SupportedHTTPMethods (the Net::HTTP classes Get, Post, Patch, Put, Delete, Head, Options). The public DSL only exposes those verbs, so this fires when a Request is constructed manually or via perform_request with another Net::HTTP class such as Net::HTTP::Trace or Net::HTTP::Connect. Note validate also checks the redirect limit first, so a exhausted limit raises RedirectionTooDeep instead.
Source
Thrown at lib/httparty/request.rb:416
cookies_hash.add_cookies(options[:headers].to_hash['Cookie']) if options[:headers] && options[:headers].to_hash['Cookie']
response.get_fields('Set-Cookie').each { |cookie| cookies_hash.add_cookies(cookie) }
options[:headers] ||= {}
options[:headers]['Cookie'] = cookies_hash.to_cookie_string
end
# Uses the HTTP Content-Type header to determine the format of the
# response It compares the MIME type returned to the types stored in the
# SupportedFormats hash
def format_from_mimetype(mimetype)
if mimetype && parser.respond_to?(:format_from_mimetype)
parser.format_from_mimetype(mimetype)
end
end
def validate
raise HTTParty::RedirectionTooDeep.new(last_response), 'HTTP redirects too deep' if options[:limit].to_i <= 0
raise ArgumentError, 'only get, post, patch, put, delete, head, and options methods are supported' unless SupportedHTTPMethods.include?(http_method)
raise ArgumentError, ':headers must be a hash' if options[:headers] && !options[:headers].respond_to?(:to_hash)
raise ArgumentError, 'only one authentication method, :basic_auth or :digest_auth may be used at a time' if options[:basic_auth] && options[:digest_auth]
raise ArgumentError, ':basic_auth must be a hash' if options[:basic_auth] && !options[:basic_auth].respond_to?(:to_hash)
raise ArgumentError, ':digest_auth must be a hash' if options[:digest_auth] && !options[:digest_auth].respond_to?(:to_hash)
raise ArgumentError, ':query must be hash if using HTTP Post' if post? && !options[:query].nil? && !options[:query].respond_to?(:to_hash)
end
def post?
Net::HTTP::Post == http_method
end
def set_basic_auth_from_uri
if path.userinfo
username, password = path.userinfo.split(':')
options[:basic_auth] = {username: username, password: password}
@credentials_sent = true
end
endView on GitHub (pinned to 8f4a09e343)
Solutions
- Restrict the facade to the supported verbs (get, post, patch, put, delete, head, options).
- For unsupported verbs, drop to Net::HTTP directly for those calls.
- If you truly need custom verbs through httparty, verify `HTTParty::Request::SupportedHTTPMethods.include?(klass)` before dispatch and branch accordingly.
Example fix
# before
def request(method, url)
klass = Net::HTTP.const_get(method.to_s.capitalize)
self.class.perform_request(klass, url, {}) # Trace -> ArgumentError
end
# after
SUPPORTED = %i[get post patch put delete head options].freeze
def request(method, url)
raise ArgumentError, "unsupported verb #{method}" unless SUPPORTED.include?(method.to_sym)
public_send(method, url)
end Defensive patterns
Strategy: validation
Validate before calling
klass = Net::HTTP.const_get(method.to_s.capitalize)
raise ArgumentError, "unsupported method #{method}" unless HTTParty::Request::SupportedHTTPMethods.include?(klass)
perform_request(klass, path, options) Type guard
supported_verb = ->(m) { %i[get post patch put delete head options].include?(m.to_sym) } Try / catch
begin
perform_request(klass, path, options)
rescue ArgumentError => e
raise unless e.message.include?('methods are supported')
raise NotImplementedError, "#{klass} not supported by httparty; use Net::HTTP directly"
end Prevention
- Whitelist verbs at your wrapper's boundary.
- Route WebDAV/TRACE-style calls to Net::HTTP from the start.
- Remember httparty's supported set is fixed per version; check SupportedHTTPMethods when upgrading.
When it happens
Trigger: `HTTParty::Request.new(Net::HTTP::Trace, 'http://x/').perform`, calling `YourClient.perform_request(Net::HTTP::Propfind, path, {})`, or library code that maps arbitrary symbols to Net::HTTP verb classes and passes one through to httparty.
Common situations: Needing TRACE/CONNECT/PROPFIND or custom verbs for WebDAV/debug endpoints, wrapping httparty behind a generic `request(method, url)` facade, and copying Net::HTTP examples into httparty code.
Related errors
- 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
- The URI adapter should respond to #parse
- #{ timeout_type } must be an integer or float
AI-assisted analysis of jnunemaker/httparty@8f4a09e343 (2026-08-21).
Data as JSON: /api/errors/ce85d26108b3e273.
Report an issue: GitHub.