Skip to content

Commit 050ce59

Browse files
committed
Always call http.Request.ParseForm method
1 parent c4bdf46 commit 050ce59

4 files changed

Lines changed: 28 additions & 17 deletions

File tree

examples/testdata/go-dev.yaml

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ interactions:
88
proto_minor: 1
99
content_length: 0
1010
host: go.dev
11+
form:
12+
m:
13+
- text
1114
url: https://go.dev/VERSION?m=text
1215
method: GET
1316
response:
@@ -17,23 +20,23 @@ interactions:
1720
content_length: -1
1821
uncompressed: true
1922
body: |
20-
go1.24.1
21-
time 2025-02-27T17:57:18Z
23+
go1.24.4
24+
time 2025-05-29T19:37:36Z
2225
headers:
2326
Content-Security-Policy:
2427
- 'connect-src ''self'' www.google-analytics.com stats.g.doubleclick.net ; default-src ''self'' ; font-src ''self'' fonts.googleapis.com fonts.gstatic.com data: ; frame-ancestors ''self'' ; frame-src ''self'' www.google.com feedback.googleusercontent.com www.googletagmanager.com scone-pa.clients6.google.com www.youtube.com player.vimeo.com ; img-src ''self'' www.google.com www.google-analytics.com ssl.gstatic.com www.gstatic.com gstatic.com data: * ; object-src ''none'' ; script-src ''self'' ''sha256-n6OdwTrm52KqKm6aHYgD0TFUdMgww4a0GQlIAVrMzck='' ''sha256-4ryYrf7Y5daLOBv0CpYtyBIcJPZkRD2eBPdfqsN3r1M='' ''sha256-sVKX08+SqOmnWhiySYk3xC7RDUgKyAkmbXV2GWts4fo='' www.google.com apis.google.com www.gstatic.com gstatic.com support.google.com www.googletagmanager.com www.google-analytics.com ssl.google-analytics.com tagmanager.google.com ; style-src ''self'' ''unsafe-inline'' fonts.googleapis.com feedback.googleusercontent.com www.gstatic.com gstatic.com tagmanager.google.com ;'
2528
Content-Type:
2629
- text/plain; charset=utf-8
2730
Date:
28-
- Fri, 21 Mar 2025 19:00:24 GMT
31+
- Fri, 27 Jun 2025 08:29:27 GMT
2932
Server:
3033
- Google Frontend
3134
Strict-Transport-Security:
3235
- max-age=31536000; includeSubDomains; preload
3336
Vary:
3437
- Accept-Encoding
3538
X-Cloud-Trace-Context:
36-
- c5713298a89696e8e768726811889751
39+
- bf9a2144badb1172ba7aa1a1424e58e2
3740
status: 200 OK
3841
code: 200
39-
duration: 122.635855ms
42+
duration: 229.432625ms

pkg/cassette/cassette.go

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -342,13 +342,10 @@ func (m *defaultMatcher) matcher(r *http.Request, i Request) bool {
342342
return false
343343
}
344344

345-
// Only ParseForm for non-GET requests since that would use query params
346-
if r.Method == http.MethodPost || r.Method == http.MethodPut || r.Method == http.MethodPatch {
347-
err := r.ParseForm()
348-
if err != nil {
349-
return false
350-
}
345+
if err := r.ParseForm(); err != nil {
346+
return false
351347
}
348+
352349
if !m.deepEqualContents(r.Form, i.Form) {
353350
return false
354351
}
@@ -474,7 +471,7 @@ func (c *Cassette) getInteraction(r *http.Request) (*Interaction, error) {
474471
return i, nil
475472
}
476473
}
477-
return nil, fmt.Errorf("%w for after %d playbacks", ErrInteractionNotFound, replayed)
474+
return nil, ErrInteractionNotFound
478475
}
479476

480477
// Save writes the cassette data on disk for future re-use

pkg/recorder/recorder_test.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,14 @@ func TestRecordOnceMode(t *testing.T) {
148148
wantContentLength: 15,
149149
path: "/api/v1/qux",
150150
},
151+
{
152+
method: http.MethodPut,
153+
body: "foobar",
154+
wantBody: "PUT go-vcr\nfoobar",
155+
wantStatus: http.StatusOK,
156+
wantContentLength: 17,
157+
path: "/api/v1/foobar?foo=bar&baz=qux",
158+
},
151159
}
152160

153161
server := newEchoHttpServer()

pkg/recorder/testdata/hello-world.yaml

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ interactions:
88
proto_minor: 1
99
content_length: 0
1010
host: go.dev
11+
form:
12+
m:
13+
- text
1114
url: https://go.dev/VERSION?m=text
1215
method: GET
1316
response:
@@ -17,23 +20,23 @@ interactions:
1720
content_length: -1
1821
uncompressed: true
1922
body: |
20-
go1.24.1
21-
time 2025-02-27T17:57:18Z
23+
go1.24.4
24+
time 2025-05-29T19:37:36Z
2225
headers:
2326
Content-Security-Policy:
2427
- 'connect-src ''self'' www.google-analytics.com stats.g.doubleclick.net ; default-src ''self'' ; font-src ''self'' fonts.googleapis.com fonts.gstatic.com data: ; frame-ancestors ''self'' ; frame-src ''self'' www.google.com feedback.googleusercontent.com www.googletagmanager.com scone-pa.clients6.google.com www.youtube.com player.vimeo.com ; img-src ''self'' www.google.com www.google-analytics.com ssl.gstatic.com www.gstatic.com gstatic.com data: * ; object-src ''none'' ; script-src ''self'' ''sha256-n6OdwTrm52KqKm6aHYgD0TFUdMgww4a0GQlIAVrMzck='' ''sha256-4ryYrf7Y5daLOBv0CpYtyBIcJPZkRD2eBPdfqsN3r1M='' ''sha256-sVKX08+SqOmnWhiySYk3xC7RDUgKyAkmbXV2GWts4fo='' www.google.com apis.google.com www.gstatic.com gstatic.com support.google.com www.googletagmanager.com www.google-analytics.com ssl.google-analytics.com tagmanager.google.com ; style-src ''self'' ''unsafe-inline'' fonts.googleapis.com feedback.googleusercontent.com www.gstatic.com gstatic.com tagmanager.google.com ;'
2528
Content-Type:
2629
- text/plain; charset=utf-8
2730
Date:
28-
- Fri, 21 Mar 2025 18:54:09 GMT
31+
- Fri, 27 Jun 2025 08:28:38 GMT
2932
Server:
3033
- Google Frontend
3134
Strict-Transport-Security:
3235
- max-age=31536000; includeSubDomains; preload
3336
Vary:
3437
- Accept-Encoding
3538
X-Cloud-Trace-Context:
36-
- 456239e0753b67424048ab478ab7e78f
39+
- dc4758d24bd970f245e301e0d9092399
3740
status: 200 OK
3841
code: 200
39-
duration: 125.432436ms
42+
duration: 415.835458ms

0 commit comments

Comments
 (0)