Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot specify body for PUT request via CLI #493

Closed
jsumners opened this issue Jul 18, 2023 · 2 comments
Closed

Cannot specify body for PUT request via CLI #493

jsumners opened this issue Jul 18, 2023 · 2 comments

Comments

@jsumners
Copy link
Contributor

Given the index.js:

'use strict'

const fastify = require('fastify')()

fastify.addContentTypeParser(
  'application/x-www-form-urlencoded',
  { parseAs: 'string' },
  fastify.defaultTextParser
)

fastify.route({
  method: 'put',
  path: '/put',
  handler (req, res) {
    res.send(req.body)
  }
})

fastify.listen({ port: 8000 })

Start the server and then run:

npx autocannon -d 10 -c 30 -w 3 -m PUT -H content-type="application/x-www-form-urlencoded" -b "1" 127.0.0.1:8000/put

The result will be:

Running 10s test @ http://127.0.0.1:8000/put
30 connections
3 workers

Worker error: Error: body must be either a string or a buffer
    at RequestIterator.buildRequest [as requestBuilder] (/Users/jsumners/.npm/_npx/0192e65d342ecc83/node_modules/autocannon/lib/httpRequestBuilder.js:83:13)
    at RequestIterator.rebuildRequest (/Users/jsumners/.npm/_npx/0192e65d342ecc83/node_modules/autocannon/lib/requestIterator.js:108:17)
    at /Users/jsumners/.npm/_npx/0192e65d342ecc83/node_modules/autocannon/lib/requestIterator.js:74:12
    at Array.forEach (<anonymous>)
    at RequestIterator.setRequests (/Users/jsumners/.npm/_npx/0192e65d342ecc83/node_modules/autocannon/lib/requestIterator.js:71:17)
    at new RequestIterator (/Users/jsumners/.npm/_npx/0192e65d342ecc83/node_modules/autocannon/lib/requestIterator.js:35:8)
    at new Client (/Users/jsumners/.npm/_npx/0192e65d342ecc83/node_modules/autocannon/lib/httpClient.js:36:26)
    at initialiseClients (/Users/jsumners/.npm/_npx/0192e65d342ecc83/node_modules/autocannon/lib/run.js:210:22)
    at run (/Users/jsumners/.npm/_npx/0192e65d342ecc83/node_modules/autocannon/lib/run.js:86:3)
    at runTracker (/Users/jsumners/.npm/_npx/0192e65d342ecc83/node_modules/autocannon/lib/worker.js:29:19)
body must be either a string or a buffer
Worker error: Error: body must be either a string or a buffer
    at RequestIterator.buildRequest [as requestBuilder] (/Users/jsumners/.npm/_npx/0192e65d342ecc83/node_modules/autocannon/lib/httpRequestBuilder.js:83:13)
    at RequestIterator.rebuildRequest (/Users/jsumners/.npm/_npx/0192e65d342ecc83/node_modules/autocannon/lib/requestIterator.js:108:17)
    at /Users/jsumners/.npm/_npx/0192e65d342ecc83/node_modules/autocannon/lib/requestIterator.js:74:12
    at Array.forEach (<anonymous>)
    at RequestIterator.setRequests (/Users/jsumners/.npm/_npx/0192e65d342ecc83/node_modules/autocannon/lib/requestIterator.js:71:17)
    at new RequestIterator (/Users/jsumners/.npm/_npx/0192e65d342ecc83/node_modules/autocannon/lib/requestIterator.js:35:8)
    at new Client (/Users/jsumners/.npm/_npx/0192e65d342ecc83/node_modules/autocannon/lib/httpClient.js:36:26)
    at initialiseClients (/Users/jsumners/.npm/_npx/0192e65d342ecc83/node_modules/autocannon/lib/run.js:210:22)
    at run (/Users/jsumners/.npm/_npx/0192e65d342ecc83/node_modules/autocannon/lib/run.js:86:3)
    at runTracker (/Users/jsumners/.npm/_npx/0192e65d342ecc83/node_modules/autocannon/lib/worker.js:29:19)
Worker error: Error: body must be either a string or a buffer
    at RequestIterator.buildRequest [as requestBuilder] (/Users/jsumners/.npm/_npx/0192e65d342ecc83/node_modules/autocannon/lib/httpRequestBuilder.js:83:13)
    at RequestIterator.rebuildRequest (/Users/jsumners/.npm/_npx/0192e65d342ecc83/node_modules/autocannon/lib/requestIterator.js:108:17)
    at /Users/jsumners/.npm/_npx/0192e65d342ecc83/node_modules/autocannon/lib/requestIterator.js:74:12
    at Array.forEach (<anonymous>)
    at RequestIterator.setRequests (/Users/jsumners/.npm/_npx/0192e65d342ecc83/node_modules/autocannon/lib/requestIterator.js:71:17)
    at new RequestIterator (/Users/jsumners/.npm/_npx/0192e65d342ecc83/node_modules/autocannon/lib/requestIterator.js:35:8)
    at new Client (/Users/jsumners/.npm/_npx/0192e65d342ecc83/node_modules/autocannon/lib/httpClient.js:36:26)
    at initialiseClients (/Users/jsumners/.npm/_npx/0192e65d342ecc83/node_modules/autocannon/lib/run.js:210:22)
    at run (/Users/jsumners/.npm/_npx/0192e65d342ecc83/node_modules/autocannon/lib/run.js:86:3)
    at runTracker (/Users/jsumners/.npm/_npx/0192e65d342ecc83/node_modules/autocannon/lib/worker.js:29:19)

If we alter the autocanon command to:

npx autocannon -d 10 -c 30 -m PUT -H content-type="application/x-www-form-urlencoded" -b "1" 127.0.0.1:8000/put
# Note the removal of "-w 3"

Then we get simply:

body must be either a string or a buffer
@mcollina
Copy link
Owner

A fix for this would be awesome ;).

jsumners added a commit to jsumners/autocannon that referenced this issue Aug 3, 2023
@jsumners
Copy link
Contributor Author

jsumners commented Aug 3, 2023

#494

mcollina pushed a commit that referenced this issue Aug 4, 2023
@mcollina mcollina closed this as completed Aug 4, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants