Browse Source

Parse application/x-www-form-urlencoded as URL-encoded form and expose as req.body

pull/20/head
Luke Childs 6 years ago
parent
commit
8000c5cfac
  1. 1
      src/index.js
  2. 16
      test/create-test-server.js

1
src/index.js

@ -26,6 +26,7 @@ const createTestServer = opts => createCert(opts && opts.certificate)
app.set('etag', false);
app.use(bodyParser.json({ type: 'application/json' }));
app.use(bodyParser.text({ type: 'text/plain' }));
app.use(bodyParser.urlencoded({ type: 'application/x-www-form-urlencoded' }));
app.caCert = keys.caCert;

16
test/create-test-server.js

@ -1,3 +1,4 @@
import querystring from 'querystring';
import test from 'ava';
import got from 'got';
import createTestServer from '../';
@ -108,6 +109,21 @@ test('server automatically parses text request body', async t => {
});
});
test('server automatically parses URL-encoded form request body', async t => {
const server = await createTestServer();
const object = { foo: 'bar' };
server.post('/echo', (req, res) => {
t.deepEqual(req.body, object);
res.end();
});
await got.post(server.url + '/echo', {
headers: { 'content-type': 'application/x-www-form-urlencoded' },
body: querystring.stringify(object)
});
});
test('opts.certificate is passed through to createCert()', async t => {
const server = await createTestServer({ certificate: 'foo.bar' });

Loading…
Cancel
Save