proxies(http): fix parsing error and 401 status code
This commit is contained in:
parent
85cd9d44f7
commit
993eb2687d
@ -11,7 +11,7 @@ before_install:
|
||||
- curl --version
|
||||
|
||||
before_deploy:
|
||||
- export NEXT_VERSION=3.3.6
|
||||
- export NEXT_VERSION=3.4.0
|
||||
- export COMMIT_HASH=$(git log --format=%h -1)
|
||||
- export DIST_PATH=build
|
||||
- export PUBLISH_REPO=blinksocks/blinksocks-nightly-releases
|
||||
|
@ -28,7 +28,14 @@ export function createServer({ secure, https_key, https_cert, username, password
|
||||
|
||||
// Simple HTTP Proxy
|
||||
server.on('request', (req, res) => {
|
||||
const { hostname, port, pathname } = new URL(req.url);
|
||||
let parseResult;
|
||||
try {
|
||||
parseResult = new URL(req.url);
|
||||
} catch (err) {
|
||||
res.writeHead(400);
|
||||
return res.end();
|
||||
}
|
||||
const { hostname, port, pathname } = parseResult;
|
||||
const { socket, method, httpVersion, headers } = req;
|
||||
const appAddress = `${socket.remoteAddress}:${socket.remotePort}`;
|
||||
|
||||
@ -46,7 +53,8 @@ export function createServer({ secure, https_key, https_cert, username, password
|
||||
const [type, credentials] = proxyAuth.split(' ');
|
||||
if (type !== 'Basic' || !checkBasicAuthorization(credentials, { username, password })) {
|
||||
logger.error(`[${name}] [${appAddress}] authorization failed, type=${type} credentials=${credentials}`);
|
||||
return res.end('HTTP/1.1 401 Unauthorized\r\n\r\n');
|
||||
res.writeHead(401);
|
||||
return res.end();
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user