Skip to content

Commit e4e275d

Browse files
authored
feat: Supplement request headers with Network.requestWillBeSentExtraInfo (#506)
1 parent 885d5d4 commit e4e275d

File tree

5 files changed

+22
-3
lines changed

5 files changed

+22
-3
lines changed

.github/workflows/tests.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,11 @@ jobs:
3131
with:
3232
chrome-version: stable
3333

34+
- name: Fix GA Chrome Permissions
35+
run: |
36+
sudo chown root:root /opt/hostedtoolcache/setup-chrome/chromium/stable/x64/chrome-sandbox
37+
sudo chmod 4755 /opt/hostedtoolcache/setup-chrome/chromium/stable/x64/chrome-sandbox
38+
3439
- name: Run tests
3540
run: |
3641
mkdir -p /tmp/ferrum

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
### Added
44

5+
`Ferrum::Network::Request#headers` are enhanced and supplemented with `Network.requestWillBeSentExtraInfo` [#506]
6+
57
### Changed
68

79
### Fixed

lib/ferrum/network.rb

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -380,16 +380,24 @@ def subscribe_request_will_be_sent
380380

381381
# We can build exchange in two places, here on the event or when request
382382
# is interrupted. So we have to be careful when to create new one. We
383-
# create new exchange only if there's no with such id or there's but
383+
# create new exchange only if there's no with such id or there's, but
384384
# it's filled with request which means this one is new but has response
385385
# for a redirect. So we assign response from the params to previous
386386
# exchange and build new exchange to assign this request to it.
387387
exchange = select(request.id).last
388-
exchange = build_exchange(request.id) unless exchange&.blank?
388+
exchange = build_exchange(request.id) if exchange.nil? || !exchange.blank?
389+
request.headers.merge!(Hash(exchange.request_extra_info&.dig("headers")))
389390
exchange.request = request
390391

391392
@exchange = exchange if exchange.navigation_request?(@page.main_frame.id)
392393
end
394+
395+
@page.on("Network.requestWillBeSentExtraInfo") do |params|
396+
exchange = select(params["requestId"]).last
397+
exchange ||= build_exchange(params["requestId"])
398+
exchange.request_extra_info = params
399+
exchange.request&.headers&.merge!(params["headers"])
400+
end
393401
end
394402

395403
def subscribe_response_received

lib/ferrum/network/exchange.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@ class Exchange
2828
# @return [Error, nil]
2929
attr_accessor :error
3030

31+
# @api private
32+
attr_accessor :request_extra_info
33+
3134
#
3235
# Initializes the network exchange.
3336
#
@@ -40,6 +43,7 @@ def initialize(page, id)
4043
@page = page
4144
@intercepted_request = nil
4245
@request = @response = @error = nil
46+
@request_extra_info = nil
4347
end
4448

4549
#

spec/spec_helper.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646
end
4747

4848
config.after(:all) do
49-
@browser.quit
49+
@browser&.quit
5050
end
5151

5252
config.before(:each) do

0 commit comments

Comments
 (0)