Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
SeleniumHQ
GitHub Repository: SeleniumHQ/Selenium
Path: blob/trunk/rb/lib/selenium/webdriver/bidi/network/intercepted_response.rb
4101 views
1
# frozen_string_literal: true
2
3
# Licensed to the Software Freedom Conservancy (SFC) under one
4
# or more contributor license agreements. See the NOTICE file
5
# distributed with this work for additional information
6
# regarding copyright ownership. The SFC licenses this file
7
# to you under the Apache License, Version 2.0 (the
8
# "License"); you may not use this file except in compliance
9
# with the License. You may obtain a copy of the License at
10
#
11
# http://www.apache.org/licenses/LICENSE-2.0
12
#
13
# Unless required by applicable law or agreed to in writing,
14
# software distributed under the License is distributed on an
15
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16
# KIND, either express or implied. See the License for the
17
# specific language governing permissions and limitations
18
# under the License.
19
20
require_relative 'credentials'
21
require_relative 'headers'
22
require_relative 'cookies'
23
24
module Selenium
25
module WebDriver
26
class BiDi
27
#
28
# @api private
29
#
30
31
class InterceptedResponse < InterceptedItem
32
attr_accessor :reason, :status
33
attr_reader :body
34
35
def initialize(network, request)
36
super
37
@reason = nil
38
@status = nil
39
@body = nil
40
@headers = nil
41
@cookies = nil
42
end
43
44
def continue
45
cookies = @cookies&.as_json
46
headers = @headers&.as_json
47
network.continue_response(
48
id: id,
49
cookies: cookies,
50
headers: headers,
51
credentials: credentials.as_json,
52
reason: reason,
53
status: status
54
)
55
end
56
57
def provide_response
58
cookies = @cookies&.as_json
59
headers = @headers&.as_json
60
network.provide_response(
61
id: id,
62
cookies: cookies,
63
headers: headers,
64
body: body,
65
reason: reason,
66
status: status
67
)
68
end
69
70
def credentials(username: nil, password: nil)
71
@credentials ||= Credentials.new(username: username, password: password)
72
end
73
74
def headers(headers = {})
75
@headers ||= Headers.new(headers)
76
end
77
78
def headers=(*headers)
79
@headers = Headers.new(headers)
80
end
81
82
def cookies(cookies = {})
83
@cookies ||= Cookies.new(cookies)
84
end
85
86
def cookies=(cookies = {})
87
@cookies ||= Cookies.new(cookies)
88
end
89
90
def body=(value)
91
@body = {
92
type: 'string',
93
value: value.to_json
94
}
95
end
96
end
97
end # BiDi
98
end # WebDriver
99
end # Selenium
100
101