Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: pillarjs/finalhandler
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v2.0.0
Choose a base ref
...
head repository: pillarjs/finalhandler
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: v2.1.0
Choose a head ref
  • 18 commits
  • 8 files changed
  • 3 contributors

Commits on Sep 2, 2024

  1. 2.0.0

    wesleytodd committed Sep 2, 2024

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature.
    Copy the full SHA
    42a0a2a View commit details

Commits on Nov 25, 2024

  1. cleanup: remove unnecessary devDependency readable-stream

    Phillip9587 authored and wesleytodd committed Nov 25, 2024
    Copy the full SHA
    5703da0 View commit details
  2. fix: remove unpipe package and use native unpipe method (#66)

    Phillip9587 authored Nov 25, 2024
    Copy the full SHA
    d40ca85 View commit details
  3. cleanup: remove unnecessary devDependency safe-buffer (#68)

    Co-authored-by: Wes Todd <wes@wesleytodd.com>
    Phillip9587 and wesleytodd authored Nov 25, 2024
    Copy the full SHA
    401ec84 View commit details

Commits on Jan 10, 2025

  1. fix(refactor): remove ServerResponse.headersSent support check (#77)

    `http.ServerResponse.headersSent` was added in v0.9.3. `http2.Http2ServerResponse.headersSent` was added in v8.4.0
    Phillip9587 authored Jan 10, 2025
    Copy the full SHA
    c70bf84 View commit details
  2. fix(cleanup): remove setImmediate support check (#73)

    `setImmediate` is available since Node.js v0.9.1
    Phillip9587 authored Jan 10, 2025
    Copy the full SHA
    d0c2dc6 View commit details
  3. fix(devdeps): update test dependencies (#76)

    Phillip9587 authored Jan 10, 2025
    Copy the full SHA
    a3d312e View commit details

Commits on Jan 16, 2025

  1. chore: update HISTORY.md for v1.3.1 and v1.3.0 releases

    Phillip9587 authored and wesleytodd committed Jan 16, 2025
    Copy the full SHA
    85ee0ca View commit details

Commits on Jan 23, 2025

  1. fix(deps): encodeurl@^2.0.0

    Phillip9587 authored and wesleytodd committed Jan 23, 2025
    Copy the full SHA
    45806e3 View commit details
  2. refactor: remove http2 support check from tests

    Phillip9587 authored and wesleytodd committed Jan 23, 2025
    Copy the full SHA
    5996f03 View commit details

Commits on Feb 10, 2025

  1. fix: use object spread to copy error headers (#79)

    Phillip9587 authored Feb 10, 2025
    Copy the full SHA
    87ffb23 View commit details
  2. fix(deps): update debug to ^4.4.0 (#78)

    Phillip9587 authored Feb 10, 2025
    Copy the full SHA
    0e5ecb4 View commit details
  3. fix: use replaceAll instead of replace with a regex (#80)

    Phillip9587 authored Feb 10, 2025
    Copy the full SHA
    59a45ca View commit details
  4. fix: replace setHeaders function with optimized inline header setting (

    Phillip9587 authored Feb 10, 2025
    Copy the full SHA
    91e7957 View commit details
  5. fix(ci): updated github actions ci workflow (#70)

    Phillip9587 authored Feb 10, 2025
    Copy the full SHA
    f84baf2 View commit details

Commits on Feb 20, 2025

  1. fix(docs): remove security file (#83)

    bjohansebas authored Feb 20, 2025
    Copy the full SHA
    164ad77 View commit details
  2. feat(deps): use caret notation for dependency versions

    Phillip9587 authored and wesleytodd committed Feb 20, 2025
    Copy the full SHA
    3f0e4fa View commit details

Commits on Mar 5, 2025

  1. 2.1.0

    wesleytodd committed Mar 5, 2025
    Copy the full SHA
    c1832e0 View commit details
Showing with 110 additions and 197 deletions.
  1. +59 −72 .github/workflows/ci.yml
  2. +27 −1 HISTORY.md
  3. +0 −25 SECURITY.md
  4. +10 −58 index.js
  5. +10 −14 package.json
  6. +1 −1 test/support/sws.js
  7. +1 −8 test/support/utils.js
  8. +2 −18 test/test.js
131 changes: 59 additions & 72 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -10,90 +10,77 @@ on:
paths-ignore:
- '*.md'

permissions:
contents: read

jobs:
lint:
name: Lint
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: Install Node.js
uses: actions/setup-node@v4
with:
node-version: 'lts/*'

- name: Install Node.js dependencies
run: npm install --ignore-scripts --include=dev

- name: Lint code
run: npm run lint

test:
name: Test - Node.js ${{ matrix.node-version }}
runs-on: ubuntu-latest
strategy:
matrix:
name:
- Node.js 18.x
- Node.js 19.x
- Node.js 20.x
- Node.js 21.x
- Node.js 22.x

include:
- name: Node.js 18.x
node-version: "18"
node-version: [18, 19, 20, 21, 22, 23]

- name: Node.js 19.x
node-version: "19"
steps:
- uses: actions/checkout@v4

- name: Node.js 20.x
node-version: "20"
- uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
check-latest: true

- name: Node.js 21.x
node-version: "21"
- name: Install Node.js dependencies
run: npm install

- name: Node.js 22.x
node-version: "22"
- name: Run tests
run: npm run test-ci

steps:
- uses: actions/checkout@v4

- name: Install Node.js ${{ matrix.node-version }}
shell: bash -eo pipefail -l {0}
run: |
nvm install --default ${{ matrix.node-version }}
dirname "$(nvm which ${{ matrix.node-version }})" >> "$GITHUB_PATH"
- name: Configure npm
run: |
if [[ "$(npm config get package-lock)" == "true" ]]; then
npm config set package-lock false
else
npm config set shrinkwrap false
fi
- name: Install Node.js dependencies
run: npm install

- name: List environment
id: list_env
shell: bash
run: |
echo "node@$(node -v)"
echo "npm@$(npm -v)"
npm -s ls ||:
(npm -s ls --depth=0 ||:) | awk -F'[ @]' 'NR>1 && $2 { print "::set-output name=" $2 "::" $3 }'
- name: Run tests
shell: bash
run: |
if npm -ps ls nyc | grep -q nyc; then
npm run test-ci
else
npm test
fi
- name: Lint code
if: steps.list_env.outputs.eslint != ''
run: npm run lint

- name: Collect code coverage
uses: coverallsapp/github-action@master
if: steps.list_env.outputs.nyc != ''
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
flag-name: run-${{ matrix.test_number }}
parallel: true
- name: Upload code coverage
uses: actions/upload-artifact@v4
with:
name: coverage-node-${{ matrix.node-version }}
path: ./coverage/lcov.info
retention-days: 1

coverage:
needs: test
runs-on: ubuntu-latest
permissions:
contents: read
checks: write
steps:
- name: Upload code coverage
uses: coverallsapp/github-action@master
with:
github-token: ${{ secrets.github_token }}
parallel-finished: true
- uses: actions/checkout@v4

- name: Install lcov
run: sudo apt-get -y install lcov

- name: Collect coverage reports
uses: actions/download-artifact@v4
with:
path: ./coverage
pattern: coverage-node-*

- name: Merge coverage reports
run: find ./coverage -name lcov.info -exec printf '-a %q\n' {} \; | xargs lcov -o ./lcov.info

- name: Upload coverage report
uses: coverallsapp/github-action@v2
with:
file: ./lcov.info
28 changes: 27 additions & 1 deletion HISTORY.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,35 @@
unreleased
v2.1.0 / 2025-02-10
==================

* deps:
* encodeurl@^2.0.0
* debug@^4.4.0
* remove `ServerResponse.headersSent` support check
* remove setImmediate support check
* update test dependencies
* remove unnecessary devDependency `safe-buffer`
* remove `unpipe` package and use native `unpipe()` method
* remove unnecessary devDependency `readable-stream`
* refactor: use object spread to copy error headers
* refactor: use replaceAll instead of replace with a regex
* refactor: replace setHeaders function with optimized inline header setting

v2.0.0 / 2024-09-02
==================

* drop support for node <18
* ignore status message for HTTP/2 (#53)

v1.3.1 / 2024-09-11
==================

* deps: encodeurl@~2.0.0

v1.3.0 / 2024-09-03
==================

* ignore status message for HTTP/2 (#53)

v1.2.1 / 2024-09-02
==================

25 changes: 0 additions & 25 deletions SECURITY.md

This file was deleted.

68 changes: 10 additions & 58 deletions index.js
Original file line number Diff line number Diff line change
@@ -17,20 +17,12 @@ var escapeHtml = require('escape-html')
var onFinished = require('on-finished')
var parseUrl = require('parseurl')
var statuses = require('statuses')
var unpipe = require('unpipe')

/**
* Module variables.
* @private
*/

var DOUBLE_SPACE_REGEXP = /\x20{2}/g
var NEWLINE_REGEXP = /\n/g

/* istanbul ignore next */
var defer = typeof setImmediate === 'function'
? setImmediate
: function (fn) { process.nextTick(fn.bind.apply(fn, arguments)) }
var isFinished = onFinished.isFinished

/**
@@ -42,8 +34,8 @@ var isFinished = onFinished.isFinished

function createHtmlDocument (message) {
var body = escapeHtml(message)
.replace(NEWLINE_REGEXP, '<br>')
.replace(DOUBLE_SPACE_REGEXP, ' &nbsp;')
.replaceAll('\n', '<br>')
.replaceAll(' ', ' &nbsp;')

return '<!DOCTYPE html>\n' +
'<html lang="en">\n' +
@@ -89,7 +81,7 @@ function finalhandler (req, res, options) {
var status

// ignore 404 on in-flight response
if (!err && headersSent(res)) {
if (!err && res.headersSent) {
debug('cannot 404 after headers sent')
return
}
@@ -119,11 +111,11 @@ function finalhandler (req, res, options) {

// schedule onerror callback
if (err && onerror) {
defer(onerror, err, req, res)
setImmediate(onerror, err, req, res)
}

// cannot actually respond
if (headersSent(res)) {
if (res.headersSent) {
debug('cannot %d after headers sent', status)
if (req.socket) {
req.socket.destroy()
@@ -149,15 +141,7 @@ function getErrorHeaders (err) {
return undefined
}

var headers = Object.create(null)
var keys = Object.keys(err.headers)

for (var i = 0; i < keys.length; i++) {
var key = keys[i]
headers[key] = err.headers[key]
}

return headers
return { ...err.headers }
}

/**
@@ -246,20 +230,6 @@ function getResponseStatusCode (res) {
return status
}

/**
* Determine if the response headers have been sent.
*
* @param {object} res
* @returns {boolean}
* @private
*/

function headersSent (res) {
return typeof res.headersSent !== 'boolean'
? Boolean(res._header)
: res.headersSent
}

/**
* Send response.
*
@@ -289,7 +259,9 @@ function send (req, res, status, headers, message) {
res.removeHeader('Content-Range')

// response headers
setHeaders(res, headers)
for (const [key, value] of Object.entries(headers ?? {})) {
res.setHeader(key, value)
}

// security headers
res.setHeader('Content-Security-Policy', "default-src 'none'")
@@ -313,29 +285,9 @@ function send (req, res, status, headers, message) {
}

// unpipe everything from the request
unpipe(req)
req.unpipe()

// flush the request
onFinished(req, write)
req.resume()
}

/**
* Set response headers from an object.
*
* @param {OutgoingMessage} res
* @param {object} headers
* @private
*/

function setHeaders (res, headers) {
if (!headers) {
return
}

var keys = Object.keys(headers)
for (var i = 0; i < keys.length; i++) {
var key = keys[i]
res.setHeader(key, headers[key])
}
}
24 changes: 10 additions & 14 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
{
"name": "finalhandler",
"description": "Node.js final http responder",
"version": "1.2.1",
"version": "2.1.0",
"author": "Douglas Christopher Wilson <doug@somethingdoug.com>",
"license": "MIT",
"repository": "pillarjs/finalhandler",
"dependencies": {
"debug": "2.6.9",
"encodeurl": "~1.0.2",
"escape-html": "~1.0.3",
"on-finished": "2.4.1",
"parseurl": "~1.3.3",
"statuses": "2.0.1",
"unpipe": "~1.0.0"
"debug": "^4.4.0",
"encodeurl": "^2.0.0",
"escape-html": "^1.0.3",
"on-finished": "^2.4.1",
"parseurl": "^1.3.3",
"statuses": "^2.0.1"
},
"devDependencies": {
"eslint": "7.32.0",
@@ -22,16 +21,13 @@
"eslint-plugin-node": "11.1.0",
"eslint-plugin-promise": "5.2.0",
"eslint-plugin-standard": "4.1.0",
"mocha": "10.0.0",
"nyc": "15.1.0",
"readable-stream": "2.3.6",
"safe-buffer": "5.2.1",
"supertest": "6.2.4"
"mocha": "^11.0.1",
"nyc": "^17.1.0",
"supertest": "^7.0.0"
},
"files": [
"LICENSE",
"HISTORY.md",
"SECURITY.md",
"index.js"
],
"engines": {
2 changes: 1 addition & 1 deletion test/support/sws.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
var stream = require('readable-stream')
var stream = require('stream')
var util = require('util')

module.exports = SlowWriteStream
Loading