Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Callback early exit #27

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open

Callback early exit #27

wants to merge 3 commits into from

Conversation

technoweenie
Copy link
Member

This does two things. First: it allows before callbacks to skip any remaining callbacks, AND the connection by returning a Hurley::Response object. Second: callbacks can optionally receive the Hurley connection as the second argument. This test shows it in action:

c = Client.new "https://example.com"

c.before_call do |req|
  req.body = req.url.path
end

c.before_call do |req, connection|
  # block is optional
  req.response(200) do |res|
    res.header["Hello"] = "World"
    res.body = "ok"
  end
end

EDIT: Added a Hurley::Request#response helper so you don't have to worry about calling Hurley::Request#prepare!.

The after callbacks are still called with that returned Hurley::Response.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant