Add support for matching multipart form values
See original GitHub issueI’m not sure if this is already supported, but I can’t find any docs. I’d like to be able to match some form values from a multipart POST.
Currently, it seems that multipart POSTs are not really supported at all, unless I’m just doing something wrong.
I keep getting the error
Error: Nock: No match for request POST https://my.domain.com/some/path <hex dump of multipart data>
My code:
nock('https://my.domain.com')
.post('/some/path')
.reply(200, 'some content');
var form = request.post('https://my.domain.com/some/path').form();
form.append('somedata', 'foo');
form.append('file', fs.createReadSteam('somefile.txt'));
I’ve even tried using the filteringRequestBody
trick to return '*'
, but that did not seem to help at all.
update: ignore the above stuff
I had a bug 😃. But I’d still like to be able to match on specific values in the multipart data. Is this possible?
Issue Analytics
- State:
- Created 9 years ago
- Reactions:8
- Comments:12 (5 by maintainers)
Top Results From Across the Web
Nock + multipart form data = No match for request
I have a problem with testing my node application using using Nock. I record all requests via nock.recorder.rec , but among them there...
Read more >RFC 7578: Returning Values from Forms: multipart/form-data
In forms that work with multipart/form-data, field names could be arbitrary Unicode strings; however, restricting field names to ASCII will help avoid some ......
Read more >Returning Values from Forms: multipart/form-data RFC 7578
Returning Values from Forms: multipart/form-data (RFC 7578, July 2015)
Read more >Solved: How to extract multipart/form-data from POST reque...
Solved: I have a request made to server like curl -H 'Host: test.apigee.net' -H 'Content-Type: multipart/form-data; boundary=beachbodyboundarystring'
Read more >Using the HTTP Client Connector with Multipart/Form-Data
Multipart /form-data is typically used for uploading/sending files. Building the request with the message shape means only text related data can ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@pgte I think my original question was misleading, because I was confused by the error (which was caused by a bug in my code), but I believe the issue is still valid. Here’s some clarification:
I’d like to be able to specify a matcher for form values (multipart or urlencoded). Perhaps something like:
Does that sound possible? I don’t know how the other matchers work, so I really don’t know if this is feasible, but I do think it would be very useful!
BTW, you can sort of fake it right now - the body is passed in as a string… but sometimes it’s utf-8 and other times it’s hex, depending on if there’s anything binary in the contents.
However, this was good enough for me - run the regex on the body as a string, and if that fails to match, try converting it from hex, and then re-run the regexp.
That said, I too would appreciate better support here. (Ideally with content-type & filename checking for files.) Not sure I’ll be able to add it, but my hat’s off to anyone who does 🎩