Skip to content
Closed
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
3 changes: 2 additions & 1 deletion History.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@

- Fixed HTTP header conflict between Content-Length and Transfer-Encoding in res.send - by [@YuryShkoda](https://github.com/YuryShkoda) in [#4893](https://github.com/expressjs/express/pull/4893)


Fixed the behavior of `res.send()` to prevent conflicts between `Content-Length` and `Transfer-Encoding` HTTP headers in responses. The `Content-Length` header in `res.send()` is now only added when a `Transfer-Encoding` header is not present, complying with the HTTP specification that states both headers should not coexist in the same response

- Fixed `req.subdomains` handling for fully qualified domain names with a trailing dot, so the root label is ignored when applying the subdomain offset.

## 🚀 Improvements

* Improve HTML structure in `res.redirect()` responses when HTML format is accepted by adding `<!DOCTYPE html>`, `<title>`, and `<body>` tags for better browser compatibility - by [@Bernice55231](https://github.com/Bernice55231) in [#5167](https://github.com/expressjs/express/pull/5167)
Expand Down
2 changes: 2 additions & 0 deletions lib/request.js
Original file line number Diff line number Diff line change
Expand Up @@ -385,6 +385,8 @@ defineGetter(req, 'subdomains', function subdomains() {

if (!hostname) return [];

hostname = hostname.replace(/\.$/, '');

var offset = this.app.get('subdomain offset');
var subdomains = !isIP(hostname)
? hostname.split('.').reverse()
Expand Down
13 changes: 13 additions & 0 deletions test/req.subdomains.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,19 @@ describe('req', function(){
.expect(200, ['ferrets', 'tobi'], done);
})

it('should ignore trailing dot on fully qualified domain names', function(done){
var app = express();

app.use(function(req, res){
res.send(req.subdomains);
});

request(app)
.get('/')
.set('Host', 'tobi.ferrets.example.com.')
.expect(200, ['ferrets', 'tobi'], done);
})

it('should work with IPv4 address', function(done){
var app = express();

Expand Down