Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(update auth 401 -> 407): #777

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
4 changes: 2 additions & 2 deletions biz/webui/lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ function getLoginKey (req, res, auth) {
function requireLogin(res, msg) {
res.setHeader('WWW-Authenticate', ' Basic realm=User Login');
res.setHeader('Content-Type', 'text/html; charset=utf8');
res.status(401).end(msg || 'Access denied, please <a href="javascript:;" onclick="location.reload()">try again</a>.');
res.status(407).end(msg || 'Access denied, please <a href="javascript:;" onclick="location.reload()">try again</a>.');
}

function verifyLogin(req, res, auth) {
Expand Down Expand Up @@ -184,7 +184,7 @@ app.use(function(req, res, next) {
if (!msg && !authUrl) {
return res.redirect(status);
}
if (status === 401) {
if (status === 407) {
return requireLogin(res, msg);
}
res.set('Content-Type', 'text/html; charset=utf8');
Expand Down
4 changes: 2 additions & 2 deletions lib/plugins/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -862,7 +862,7 @@ pluginMgr.loadAuthPlugins = function (req, callback) {
if (req._redirectUrl || req._authHtmlUrl) {
return callback(req._redirectUrl, null, req._authHtmlUrl);
}
var status = req._authStatus ? (req._showLoginBox ? 401 : 403) : 502;
var status = req._authStatus ? (req._showLoginBox ? 407 : 403) : 502;
return callback(status, forbidden);
}
return callback();
Expand Down Expand Up @@ -1004,7 +1004,7 @@ function getRulesFromPlugins(type, req, res, callback) {
} else if (noTunnel && req._redirectUrl) {
mgr.parse('* ignore://!redirect redirect://' + req._redirectUrl);
} else {
var status = req._authStatus ? (req._showLoginBox ? 401 : 403) : 502;
var status = req._authStatus ? (req._showLoginBox ? 407 : 403) : 502;
mgr.parse(
'* ignore://!statusCode|!resBody|!resType|!resCharset status://' +
status +
Expand Down
4 changes: 2 additions & 2 deletions lib/util/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -285,8 +285,8 @@ function changePort(url, port) {
exports.changePort = changePort;

function handleStatusCode(statusCode, headers) {
if (statusCode == 401) {
headers['www-authenticate'] = 'Basic realm=User Login';
if (statusCode == 407) {
headers['Proxy-Authenticate'] = 'Basic realm=""';
}
return headers;
}
Expand Down