File tree Expand file tree Collapse file tree 3 files changed +7
-49
lines changed Expand file tree Collapse file tree 3 files changed +7
-49
lines changed Original file line number Diff line number Diff line change @@ -45,34 +45,6 @@ describe('ctx.redirect(url)', () => {
45
45
} )
46
46
} )
47
47
48
- describe ( 'with "back"' , ( ) => {
49
- it ( 'should redirect to Referrer' , ( ) => {
50
- const ctx = context ( )
51
- ctx . req . headers . referrer = '/login'
52
- ctx . redirect ( 'back' )
53
- assert . strictEqual ( ctx . response . header . location , '/login' )
54
- } )
55
-
56
- it ( 'should redirect to Referer' , ( ) => {
57
- const ctx = context ( )
58
- ctx . req . headers . referer = '/login'
59
- ctx . redirect ( 'back' )
60
- assert . strictEqual ( ctx . response . header . location , '/login' )
61
- } )
62
-
63
- it ( 'should default to alt' , ( ) => {
64
- const ctx = context ( )
65
- ctx . redirect ( 'back' , '/index.html' )
66
- assert . strictEqual ( ctx . response . header . location , '/index.html' )
67
- } )
68
-
69
- it ( 'should default redirect to /' , ( ) => {
70
- const ctx = context ( )
71
- ctx . redirect ( 'back' )
72
- assert . strictEqual ( ctx . response . header . location , '/' )
73
- } )
74
- } )
75
-
76
48
describe ( 'when html is accepted' , ( ) => {
77
49
it ( 'should respond with html' , ( ) => {
78
50
const ctx = context ( )
Original file line number Diff line number Diff line change @@ -287,17 +287,11 @@ app.use(async (ctx, next) => {
287
287
});
288
288
```
289
289
290
- ### response.redirect(url, [ alt ] )
290
+ ### response.redirect(url)
291
291
292
292
Perform a [ 302] redirect to ` url ` .
293
293
294
- The string "back" is special-cased
295
- to provide Referrer support, when Referrer
296
- is not present ` alt ` or "/" is used.
297
-
298
294
``` js
299
- ctx .redirect (' back' );
300
- ctx .redirect (' back' , ' /index.html' );
301
295
ctx .redirect (' /login' );
302
296
ctx .redirect (' http://google.com' );
303
297
```
@@ -311,6 +305,11 @@ ctx.redirect('/cart');
311
305
ctx .body = ' Redirecting to shopping cart' ;
312
306
```
313
307
308
+ ### response.back(url)
309
+
310
+ Similar to ` .redirect(url) ` , but first checks the ` referer ` header to redirect.
311
+ This is new in v3 as ` .redirect(url, alt) ` removes the special case ` url = 'back' ` option.
312
+
314
313
### response.attachment([ filename] , [ options] )
315
314
316
315
Set ` Content-Disposition ` to "attachment" to signal the client
Original file line number Diff line number Diff line change @@ -273,29 +273,16 @@ module.exports = {
273
273
/**
274
274
* Perform a 302 redirect to `url`.
275
275
*
276
- * The string "back" is special-cased
277
- * to provide Referrer support, when Referrer
278
- * is not present `alt` or "/" is used.
279
- *
280
276
* Examples:
281
277
*
282
- * this.redirect('back');
283
- * this.redirect('back', '/index.html');
284
278
* this.redirect('/login');
285
279
* this.redirect('http://google.com');
286
280
*
287
281
* @param {String } url
288
- * @param {String } [alt]
289
282
* @api public
290
283
*/
291
284
292
- redirect ( url , alt ) {
293
- // location
294
- if ( url === 'back' ) {
295
- deprecate ( 'Special-cased string "back" through redirect will be removed in v3, ' +
296
- 'consider migrating usage to ctx.back() instead.' )
297
- url = this . ctx . get ( 'Referrer' ) || alt || '/'
298
- }
285
+ redirect ( url ) {
299
286
if ( / ^ h t t p s ? : \/ \/ / i. test ( url ) ) {
300
287
// formatting url again avoid security escapes
301
288
url = new URL ( url ) . toString ( )
You can’t perform that action at this time.
0 commit comments