File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -45,34 +45,6 @@ describe('ctx.redirect(url)', () => {
4545 } )
4646 } )
4747
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-
7648 describe ( 'when html is accepted' , ( ) => {
7749 it ( 'should respond with html' , ( ) => {
7850 const ctx = context ( )
Original file line number Diff line number Diff line change @@ -287,17 +287,11 @@ app.use(async (ctx, next) => {
287287});
288288```
289289
290- ### response.redirect(url, [ alt ] )
290+ ### response.redirect(url)
291291
292292 Perform a [ 302] redirect to ` url ` .
293293
294- The string "back" is special-cased
295- to provide Referrer support, when Referrer
296- is not present ` alt ` or "/" is used.
297-
298294``` js
299- ctx .redirect (' back' );
300- ctx .redirect (' back' , ' /index.html' );
301295ctx .redirect (' /login' );
302296ctx .redirect (' http://google.com' );
303297```
@@ -311,6 +305,11 @@ ctx.redirect('/cart');
311305ctx .body = ' Redirecting to shopping cart' ;
312306```
313307
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+
314313### response.attachment([ filename] , [ options] )
315314
316315 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 = {
273273 /**
274274 * Perform a 302 redirect to `url`.
275275 *
276- * The string "back" is special-cased
277- * to provide Referrer support, when Referrer
278- * is not present `alt` or "/" is used.
279- *
280276 * Examples:
281277 *
282- * this.redirect('back');
283- * this.redirect('back', '/index.html');
284278 * this.redirect('/login');
285279 * this.redirect('http://google.com');
286280 *
287281 * @param {String } url
288- * @param {String } [alt]
289282 * @api public
290283 */
291284
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 ) {
299286 if ( / ^ h t t p s ? : \/ \/ / i. test ( url ) ) {
300287 // formatting url again avoid security escapes
301288 url = new URL ( url ) . toString ( )
You can’t perform that action at this time.
0 commit comments