fastify 3.29.1 → 3.29.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/fastify.js CHANGED
@@ -1,6 +1,6 @@
1
1
  'use strict'
2
2
 
3
- const VERSION = '3.29.1'
3
+ const VERSION = '3.29.2'
4
4
 
5
5
  const Avvio = require('avvio')
6
6
  const http = require('http')
@@ -584,7 +584,7 @@ function fastify (options) {
584
584
  // https://github.com/nodejs/node/blob/6ca23d7846cb47e84fd344543e394e50938540be/lib/_http_server.js#L666
585
585
 
586
586
  // If the socket is not writable, there is no reason to try to send data.
587
- if (socket.writable && socket.bytesWritten === 0) {
587
+ if (socket.writable) {
588
588
  socket.write(`HTTP/1.1 400 Bad Request\r\nContent-Length: ${body.length}\r\nContent-Type: application/json\r\n\r\n${body}`)
589
589
  }
590
590
  socket.destroy(err)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "fastify",
3
- "version": "3.29.1",
3
+ "version": "3.29.2",
4
4
  "description": "Fast and low overhead web framework, for Node.js",
5
5
  "main": "fastify.js",
6
6
  "type": "commonjs",
@@ -2,6 +2,7 @@
2
2
 
3
3
  const { connect } = require('net')
4
4
  const t = require('tap')
5
+ const semver = require('semver')
5
6
  const test = t.test
6
7
  const Fastify = require('..')
7
8
  const { kRequest } = require('../lib/symbols.js')
@@ -153,7 +154,7 @@ test('default clientError handler ignores sockets in destroyed state', t => {
153
154
  })
154
155
 
155
156
  test('default clientError handler destroys sockets in writable state', t => {
156
- t.plan(1)
157
+ t.plan(2)
157
158
 
158
159
  const fastify = Fastify({
159
160
  bodyLimit: 1,
@@ -169,6 +170,9 @@ test('default clientError handler destroys sockets in writable state', t => {
169
170
  },
170
171
  destroy () {
171
172
  t.pass('destroy should be called')
173
+ },
174
+ write (response) {
175
+ t.match(response, /^HTTP\/1.1 400 Bad Request/)
172
176
  }
173
177
  })
174
178
  })
@@ -189,6 +193,9 @@ test('default clientError handler destroys http sockets in non-writable state',
189
193
  },
190
194
  destroy () {
191
195
  t.pass('destroy should be called')
196
+ },
197
+ write (response) {
198
+ t.fail('write should not be called')
192
199
  }
193
200
  })
194
201
  })
@@ -273,3 +280,42 @@ test('encapsulated error handler binding', t => {
273
280
  t.equal(fastify.hello, undefined)
274
281
  })
275
282
  })
283
+
284
+ const skip = semver.lt(process.versions.node, '11.0.0')
285
+
286
+ test('default clientError replies with bad request on reused keep-alive connection', { skip }, t => {
287
+ t.plan(2)
288
+
289
+ let response = ''
290
+
291
+ const fastify = Fastify({
292
+ bodyLimit: 1,
293
+ keepAliveTimeout: 100
294
+ })
295
+
296
+ fastify.get('/', (request, reply) => {
297
+ reply.send('OK\n')
298
+ })
299
+
300
+ fastify.listen({ port: 0 }, function (err) {
301
+ t.error(err)
302
+ fastify.server.unref()
303
+
304
+ const client = connect(fastify.server.address().port)
305
+
306
+ client.on('data', chunk => {
307
+ response += chunk.toString('utf-8')
308
+ })
309
+
310
+ client.on('end', () => {
311
+ t.match(response, /^HTTP\/1.1 200 OK.*HTTP\/1.1 400 Bad Request/s)
312
+ })
313
+
314
+ client.resume()
315
+ client.write('GET / HTTP/1.1\r\n')
316
+ client.write('\r\n\r\n')
317
+ client.write('GET /?a b HTTP/1.1\r\n')
318
+ client.write('Connection: close\r\n')
319
+ client.write('\r\n\r\n')
320
+ })
321
+ })