Skip to content

Commit

Permalink
Use status code 301 for redirects
Browse files Browse the repository at this point in the history
closes #59
  • Loading branch information
thestinger authored and dougwilson committed Jun 8, 2016
1 parent b36f161 commit 54a46b2
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 13 deletions.
1 change: 1 addition & 0 deletions HISTORY.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
unreleased
==========

* Use status code 301 for redirects
* deps: [email protected]
- Add `acceptRanges` option
- Add `cacheControl` option
Expand Down
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ function createRedirectDirectoryListener () {
var res = this.res

// send redirect response
res.statusCode = 303
res.statusCode = 301
res.setHeader('Content-Type', 'text/html; charset=UTF-8')
res.setHeader('Content-Length', Buffer.byteLength(msg))
res.setHeader('X-Content-Type-Options', 'nosniff')
Expand Down
24 changes: 12 additions & 12 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ describe('serveStatic()', function () {
it('should redirect when directory without slash', function (done) {
request(this.server)
.get('/pets')
.expect(303, /Redirecting/, done)
.expect(301, /Redirecting/, done)
})
})

Expand Down Expand Up @@ -359,7 +359,7 @@ describe('serveStatic()', function () {
it('should redirect when directory without slash', function (done) {
request(this.server)
.get('/pets')
.expect(303, /Redirecting/, done)
.expect(301, /Redirecting/, done)
})
})

Expand Down Expand Up @@ -442,28 +442,28 @@ describe('serveStatic()', function () {
request(server)
.get('/users')
.expect('Location', '/users/')
.expect(303, done)
.expect(301, done)
})

it('should include HTML link', function (done) {
request(server)
.get('/users')
.expect('Location', '/users/')
.expect(303, /<a href="\/users\/">/, done)
.expect(301, /<a href="\/users\/">/, done)
})

it('should redirect directories with query string', function (done) {
request(server)
.get('/users?name=john')
.expect('Location', '/users/?name=john')
.expect(303, done)
.expect(301, done)
})

it('should not redirect to protocol-relative locations', function (done) {
request(server)
.get('//users')
.expect('Location', '/users/')
.expect(303, done)
.expect(301, done)
})

it('should not redirect incorrectly', function (done) {
Expand Down Expand Up @@ -521,7 +521,7 @@ describe('serveStatic()', function () {
request(server)
.get('/users')
.expect(shouldNotHaveHeader('x-custom'))
.expect(303, done)
.expect(301, done)
})
})

Expand Down Expand Up @@ -656,7 +656,7 @@ describe('serveStatic()', function () {
request(server)
.get('/users')
.expect('Location', '/users/')
.expect(303, done)
.expect(301, done)
})
})

Expand All @@ -673,14 +673,14 @@ describe('serveStatic()', function () {
request(server)
.get('/static/users')
.expect('Location', '/static/users/')
.expect(303, done)
.expect(301, done)
})

it('should not choke on auth-looking URL', function (done) {
request(server)
.get('//todo@txt')
.expect('Location', '/todo@txt/')
.expect(303, done)
.expect(301, done)
})
})

Expand Down Expand Up @@ -727,7 +727,7 @@ describe('serveStatic()', function () {
request(server)
.get('/static/users')
.expect('Location', '/static/users/')
.expect(303, done)
.expect(301, done)
})

it('should next() on mount point', function (done) {
Expand All @@ -740,7 +740,7 @@ describe('serveStatic()', function () {
request(server)
.get('/static')
.expect('Location', '/static/')
.expect(303, done)
.expect(301, done)
})
})
})
Expand Down

0 comments on commit 54a46b2

Please sign in to comment.