@@ -7,12 +7,13 @@ import * as net from "net"
77import * as path from "path"
88import { WebsocketRequest } from "../../../typings/pluginapi"
99import { logError } from "../../common/util"
10- import { CodeArgs , toCodeArgs } from "../cli"
10+ import { AuthType , CodeArgs , toCodeArgs } from "../cli"
1111import { isDevMode , vsRootPath } from "../constants"
1212import { authenticated , ensureAuthenticated , ensureOrigin , redirect , replaceTemplates , self } from "../http"
1313import { SocketProxyProvider } from "../socket"
1414import { isFile } from "../util"
1515import { Router as WsRouter } from "../wsRouter"
16+ import { HttpCode , HttpError } from "../../common/http"
1617
1718export const router = express . Router ( )
1819
@@ -118,6 +119,11 @@ router.get("/", ensureVSCodeLoaded, async (req, res, next) => {
118119 const FOLDER_OR_WORKSPACE_WAS_CLOSED = req . query . ew
119120
120121 if ( ! isAuthenticated ) {
122+ // If auth is HttpBasic, return a 401.
123+ if ( req . args . auth === AuthType . HttpBasic ) {
124+ res . setHeader ( 'WWW-Authenticate' , 'Basic realm="Access to the site"' )
125+ throw new HttpError ( "Unauthorized" , HttpCode . Unauthorized )
126+ } ;
121127 const to = self ( req )
122128 return redirect ( req , res , "login" , {
123129 to : to !== "/" ? to : undefined ,
0 commit comments