question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Add support for matching multipart form values

See original GitHub issue

I’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:closed
  • Created 9 years ago
  • Reactions:8
  • Comments:12 (5 by maintainers)

github_iconTop GitHub Comments

3reactions
lakenencommented, Jun 9, 2014

@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:

nock('...')
    .matchForm('myField', 'some value') // value matching
    .matchForm('myOtherField', /\d+/) // or as a regexp
    .matchForm('myBinaryField', /* something to denote that a field should be binary data? */)
    .post('/some/path');

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!

2reactions
nfriedlycommented, May 24, 2016

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 🎩

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found