dommy-rack 0.16.0 → 0.17.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +10 -0
- data/lib/dommy/rack/navigation.rb +14 -6
- data/lib/dommy/rack/response.rb +6 -4
- data/lib/dommy/rack/session.rb +7 -5
- data/lib/dommy/rack/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: f8af313f77527147bc933b85aabef1ee539c86cc1ba8e9c49827b44bb0544bed
|
|
4
|
+
data.tar.gz: b8d89f41f1191a71c9d3869f04b2ce6fd871fbc70ccca180cd3b4571f6d06d8c
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 8885edb04121bfa10030fd45ca29fef75708d38a06836e4b7b7a84a198c9ed2eea155cf9d590355e97e6a6f7fca567e982c1586e4d5f29b7f44d687f074f124c
|
|
7
|
+
data.tar.gz: d3bf3386a970af499c6a83ef663d7bc1cf3c8001f483e9f2bede6b23b679bb8c928ccf23ba5e70dae98dbd103e7f0403de33efbe6057307f9150bbda6546f257
|
data/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,15 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.17.0 — 2026-10-20
|
|
4
|
+
|
|
5
|
+
### Added
|
|
6
|
+
|
|
7
|
+
- `Session#navigate`, `Navigation#navigate` and `Navigation#run` take `method_override:` (false by default), saying the method is a form's `_method` field's, so a 301 or 302 is followed with a GET.
|
|
8
|
+
|
|
9
|
+
### Fixed
|
|
10
|
+
|
|
11
|
+
- A form whose `_method` field overrides its method (Rails' `PUT`, `PATCH`, `DELETE`) follows a 301 or 302 with a GET, as the POST a browser sends is; the redirect target got the overridden method and answered 404. A 307 or 308 keeps the method and the params.
|
|
12
|
+
|
|
3
13
|
## 0.16.0 — 2026-10-10
|
|
4
14
|
|
|
5
15
|
### Breaking changes
|
|
@@ -48,7 +48,9 @@ module Dommy
|
|
|
48
48
|
|
|
49
49
|
# Perform a navigation, following redirects per session policy, then
|
|
50
50
|
# apply the final response to the session (updating document + history).
|
|
51
|
-
|
|
51
|
+
# `method_override:` marks a method a form's `_method` field gave, which a
|
|
52
|
+
# redirect treats as the POST a browser sends (see #run).
|
|
53
|
+
def navigate(method:, url:, params: nil, body: nil, enctype: nil, headers: {}, replace: false, method_override: false)
|
|
52
54
|
return navigate_about(url.to_s) if url.to_s.start_with?("about:")
|
|
53
55
|
|
|
54
56
|
verb = method.to_s.upcase
|
|
@@ -64,7 +66,8 @@ module Dommy
|
|
|
64
66
|
end
|
|
65
67
|
check_same_origin!(target)
|
|
66
68
|
|
|
67
|
-
response, final_url = run(method: verb, url: target, params: params, body: body, enctype: enctype, headers: headers
|
|
69
|
+
response, final_url = run(method: verb, url: target, params: params, body: body, enctype: enctype, headers: headers,
|
|
70
|
+
method_override: method_override)
|
|
68
71
|
# replace: a location.replace() / reload() / redirect updates the current
|
|
69
72
|
# history entry in place rather than pushing a new one.
|
|
70
73
|
@session.apply_navigation_response(response, final_url, replace: replace)
|
|
@@ -100,7 +103,12 @@ module Dommy
|
|
|
100
103
|
|
|
101
104
|
# Run the request/redirect loop. Returns [response, final_url].
|
|
102
105
|
# Public so Session#fetch can reuse it without applying navigation state.
|
|
103
|
-
|
|
106
|
+
#
|
|
107
|
+
# A `method_override` request carries the method a form's `_method` field
|
|
108
|
+
# gave (the session resolves it for the app), but what a browser sends is
|
|
109
|
+
# a POST, which a 301/302 turns into a GET; a real PUT keeps its method
|
|
110
|
+
# (Fetch), and a 307/308 keeps either one, with its params.
|
|
111
|
+
def run(method:, url:, params: nil, body: nil, enctype: nil, headers: {}, follow: true, exchange: nil, method_override: false)
|
|
104
112
|
verb = method
|
|
105
113
|
target = url
|
|
106
114
|
# Carry the fragment across redirects: a redirect Location without its
|
|
@@ -139,7 +147,7 @@ module Dommy
|
|
|
139
147
|
params = nil
|
|
140
148
|
body = nil
|
|
141
149
|
end
|
|
142
|
-
verb = redirect_method(response.status, verb)
|
|
150
|
+
verb = redirect_method(response.status, verb, method_override)
|
|
143
151
|
end
|
|
144
152
|
end
|
|
145
153
|
|
|
@@ -218,10 +226,10 @@ module Dommy
|
|
|
218
226
|
!response.location_header.to_s.empty?
|
|
219
227
|
end
|
|
220
228
|
|
|
221
|
-
def redirect_method(status, original)
|
|
229
|
+
def redirect_method(status, original, method_override)
|
|
222
230
|
case status
|
|
223
231
|
when 303 then "GET"
|
|
224
|
-
when 301, 302 then original == "POST" ? "GET" : original
|
|
232
|
+
when 301, 302 then original == "POST" || method_override ? "GET" : original
|
|
225
233
|
else original # 307, 308 keep the method
|
|
226
234
|
end
|
|
227
235
|
end
|
data/lib/dommy/rack/response.rb
CHANGED
|
@@ -142,10 +142,12 @@ module Dommy
|
|
|
142
142
|
@document_parsed = true
|
|
143
143
|
return unless document?
|
|
144
144
|
|
|
145
|
-
# Decoded as the response declares (a byte-order mark,
|
|
146
|
-
# Content-Type's charset, else
|
|
147
|
-
|
|
148
|
-
|
|
145
|
+
# Decoded as the response declares (a byte-order mark, the
|
|
146
|
+
# Content-Type's charset, an HTML page's `<meta charset>`, else
|
|
147
|
+
# UTF-8), and the document told which encoding that was.
|
|
148
|
+
text, encoding = ::Dommy::Encodings.decode_document(@body, header("content-type"), html: html?)
|
|
149
|
+
@window = html? ? Dommy.parse(text, encoding: encoding) : ::Dommy::Internal::ChildNavigable.text_window(text, content_type)
|
|
150
|
+
@window.document.__internal_character_encoding__ = encoding
|
|
149
151
|
# Establish the document's URL (not a navigation: nothing is asked of
|
|
150
152
|
# the navigation delegate, and the first session history entry is this
|
|
151
153
|
# URL).
|
data/lib/dommy/rack/session.rb
CHANGED
|
@@ -475,9 +475,9 @@ module Dommy
|
|
|
475
475
|
result
|
|
476
476
|
end
|
|
477
477
|
|
|
478
|
-
def navigate(method: "GET", url:, params: nil, body: nil, enctype: nil, headers: {}, replace: false)
|
|
478
|
+
def navigate(method: "GET", url:, params: nil, body: nil, enctype: nil, headers: {}, replace: false, method_override: false)
|
|
479
479
|
@navigation.navigate(method: method, url: url, params: params, body: body, enctype: enctype,
|
|
480
|
-
headers: headers, replace: replace)
|
|
480
|
+
headers: headers, replace: replace, method_override: method_override)
|
|
481
481
|
end
|
|
482
482
|
|
|
483
483
|
def reload
|
|
@@ -868,7 +868,8 @@ module Dommy
|
|
|
868
868
|
result = FormSubmission.new(form, submitter, @config).submit!
|
|
869
869
|
@trace&.__internal_record_form(method: result[:method], url: result[:url], params: result[:params])
|
|
870
870
|
navigate(method: result[:method], url: resolve_document_url(result[:url]),
|
|
871
|
-
params: result[:params], enctype: result[:enctype], headers: referer_headers
|
|
871
|
+
params: result[:params], enctype: result[:enctype], headers: referer_headers,
|
|
872
|
+
method_override: result[:method_override])
|
|
872
873
|
end
|
|
873
874
|
|
|
874
875
|
alias submit submit_form
|
|
@@ -1223,13 +1224,14 @@ module Dommy
|
|
|
1223
1224
|
return unless %w[http https].include?(uri_scheme(target))
|
|
1224
1225
|
return if nav[:params].nil? && same_page_fragment?(target)
|
|
1225
1226
|
|
|
1226
|
-
|
|
1227
|
+
requested = (nav[:method] || "GET").to_s.upcase
|
|
1228
|
+
method = requested
|
|
1227
1229
|
params = nav[:params]
|
|
1228
1230
|
method, params = apply_delegate_method_override(method, params) if params
|
|
1229
1231
|
# A form the page submitted is traced as #submit_form's are.
|
|
1230
1232
|
@trace&.__internal_record_form(method: method, url: target, params: params) if nav[:source] == :form
|
|
1231
1233
|
navigate(method: method, url: target, params: params, body: nav[:body], enctype: nav[:enctype],
|
|
1232
|
-
headers: referer_headers, replace: nav[:replace])
|
|
1234
|
+
headers: referer_headers, replace: nav[:replace], method_override: method != requested)
|
|
1233
1235
|
end
|
|
1234
1236
|
|
|
1235
1237
|
# The delegate path serializes forms through core FormSubmission, which
|
data/lib/dommy/rack/version.rb
CHANGED
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: dommy-rack
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.17.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- takahashim
|
|
@@ -15,14 +15,14 @@ dependencies:
|
|
|
15
15
|
requirements:
|
|
16
16
|
- - "~>"
|
|
17
17
|
- !ruby/object:Gem::Version
|
|
18
|
-
version: 0.
|
|
18
|
+
version: 0.17.0
|
|
19
19
|
type: :runtime
|
|
20
20
|
prerelease: false
|
|
21
21
|
version_requirements: !ruby/object:Gem::Requirement
|
|
22
22
|
requirements:
|
|
23
23
|
- - "~>"
|
|
24
24
|
- !ruby/object:Gem::Version
|
|
25
|
-
version: 0.
|
|
25
|
+
version: 0.17.0
|
|
26
26
|
- !ruby/object:Gem::Dependency
|
|
27
27
|
name: rack
|
|
28
28
|
requirement: !ruby/object:Gem::Requirement
|