Browse Source

Parse text/plain as string and expose as req.body

pull/20/head
Luke Childs 6 years ago
parent
commit
129bd8c1a8
  1. 1
      src/index.js
  2. 15
      test/create-test-server.js

1
src/index.js

@ -25,6 +25,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.caCert = keys.caCert;

15
test/create-test-server.js

@ -93,6 +93,21 @@ test('server automatically parses JSON request body', async t => {
});
});
test('server automatically parses text request body', async t => {
const server = await createTestServer();
const text = 'foo';
server.post('/echo', (req, res) => {
t.deepEqual(req.body, text);
res.end();
});
await got.post(server.url + '/echo', {
headers: { 'content-type': 'text/plain' },
body: text
});
});
test('opts.certificate is passed through to createCert()', async t => {
const server = await createTestServer({ certificate: 'foo.bar' });

Loading…
Cancel
Save