Skip to content

feat: add deprecation notice for header overwriting in redirects #199

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions HISTORY.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
===================

* Changes from 1.16.0
* In the next major version, headers will no longer be overwritten when redirecting a directory.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

v2.1.0 was already released. Please add a unreleased section or just add it in the Release PR


2.0.0 / 2024-08-23
==================
Expand Down
7 changes: 5 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

var encodeUrl = require('encodeurl')
var escapeHtml = require('escape-html')
const deprecate = require('depd')('serve-static')
var parseUrl = require('parseurl')
var resolve = require('path').resolve
var send = require('send')
Expand Down Expand Up @@ -213,7 +214,9 @@ function createRedirectDirectoryListener () {
*/

function setHeaderIfNotSet (res, name, value) {
if (!res.hasHeader(name)) {
res.setHeader(name, value)
if (res.hasHeader(name)) {
deprecate('The headers will not be overwritten in the next version')
}

res.setHeader(name, value)
}
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"encodeurl": "^2.0.0",
"escape-html": "^1.0.3",
"parseurl": "^1.3.3",
"depd": "^2.0.0",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should go in the HISTORY.md too

"send": "^1.0.0"
},
"devDependencies": {
Expand Down