Skip to content
Myr

Added relative redirect support. Closes #920

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Tj Holowaychuk · committed by Tj Holowaychuk · parent a1e325a · Browse files · 2 files+71 added−20 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

2 files+71 added−20 removed

  • tests:+59 added−13 removed
  • other:+12 added−7 removed

2 files+71 added−20 removed

modified:lib/response.js+12 added-7 removed
478 unmodified lines
479 status = url;480 url = arguments[1];481 }482483 // Setup redirect map483 // setup redirect map484 var map = {485 back: req.header('Referrer', root)486 , home: root487 };488489 // Support custom redirect map489 // support custom redirect map490 map.__proto__ = app.redirects;491492 // Attempt mapped redirect492 // attempt mapped redirect493 var mapped = 'function' == typeof map[url]494 ? map[url](req, this)495 : map[url];496497 // Perform redirect497 // perform redirect498 url = mapped || url;499500 // Relative500 // relative501 if (!~url.indexOf('://')) {502 var path = app.path() || root;503504 // Respect mount-point505 if (0 != url.indexOf(path)) url = path + url;504 // relative to host505 if ('/' == url[0]) {506507 // relative to mount-point508 } else if (1 != url.indexOf(path)) {509 url = path + '/' + url;510 }511512 // Absolute513 var host = req.header('Host')514 , tls = false // TODO: req.secure;515
88 unmodified lines
modified:test/res.redirect.js+59 added-13 removed