Skip to content

Commit

Permalink
Added Agent#every_response (closes #15).
Browse files Browse the repository at this point in the history
  • Loading branch information
postmodern committed Jul 26, 2023
1 parent b97917c commit f5d2566
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
15 changes: 15 additions & 0 deletions lib/ronin/web/browser/agent.rb
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,21 @@ def every_request
end
end

#
# Passes every response to the given block.
#
# @yield [exchange]
# The given block will be passed the network exchange object
# containing both the request and the response objects.
#
#
# @yieldparam [Ferrum::Network::Exchange] exchange
# A network exchange containing both the request and response objects.
#
def every_response(&block)
on(:response,&block)
end

#
# Passes every requested URL to the given block.
#
Expand Down
17 changes: 17 additions & 0 deletions spec/agent_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,23 @@
after { subject.quit }
end

describe "#every_response" do
it "must yield each Ferrum::Network::Request" do
yielded_responses = []

subject.every_response do |exchange|
yielded_responses << exchange
end

subject.goto('https://example.com/')

expect(yielded_responses).to_not be_empty
expect(yielded_responses).to all(be_kind_of(Ferrum::Network::Exchange))
end

after { subject.quit }
end

describe "#every_url" do
it "must yield every requested URL" do
yielded_urls = []
Expand Down

0 comments on commit f5d2566

Please sign in to comment.