Skip to content

raise error when invalid hash is passed to timeout #752

Closed

Description

@stoivo

Hi, love httprb.

I would like to suggest to add some validation of the arguments to timeout. I can see that there are already some but we managed to pass {timeout: 5} as the argument

This is the related code.

http/lib/http/chainable.rb

Lines 93 to 112 in 462d711

def timeout(options)
klass, options = case options
when Numeric then [HTTP::Timeout::Global, {:global => options}]
when Hash then [HTTP::Timeout::PerOperation, options.dup]
when :null then [HTTP::Timeout::Null, {}]
else raise ArgumentError, "Use `.timeout(global_timeout_in_seconds)` or `.timeout(connect: x, write: y, read: z)`."
end
%i[global read write connect].each do |k|
next unless options.key? k
options["#{k}_timeout".to_sym] = options.delete k
end
branch default_options.merge(
:timeout_class => klass,
:timeout_options => options
)
end

I can open a PR of you would want that?

Activity

  1. tarcieri commented on May 31, 2023

    @tarcieri
    Member

    Yes, open a PR with what you're proposing

  2. sferik commented on Mar 10, 2026

    @sferik
    Contributor

    I believe this is resolved by 93da710. Please reopen this issue if it’s not resolved.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions