Skip to content

Commit

Permalink
Add trailing slashes (#14205)
Browse files Browse the repository at this point in the history
  • Loading branch information
DonJayamanne authored Aug 28, 2023
1 parent 5a7129c commit a797e4d
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ export class JupyterHubPasswordConnect {

// Otherwise request hub/api. This should return the json with the hub version
// if this is a hub url
const response = await this.makeRequest(new URL('hub/api', url).toString(), {
const response = await this.makeRequest(new URL('hub/api', addTrailingSlash(url)).toString(), {
method: 'get',
redirect: 'manual',
headers: { Connection: 'keep-alive' }
Expand Down
10 changes: 5 additions & 5 deletions src/standalone/userJupyterServer/jupyterPasswordConnect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -209,10 +209,10 @@ export class JupyterPasswordConnect {
private async getXSRFToken(url: string, sessionCookie: string): Promise<string | undefined> {
let xsrfCookie: string | undefined;
let headers;
let tokenUrl = new URL('login?', url).toString();
let tokenUrl = new URL('login?', addTrailingSlash(url)).toString();

if (sessionCookie != '') {
tokenUrl = new URL('tree', url).toString();
tokenUrl = new URL('tree', addTrailingSlash(url)).toString();
headers = {
Connection: 'keep-alive',
Cookie: sessionCookie
Expand Down Expand Up @@ -241,7 +241,7 @@ export class JupyterPasswordConnect {

private async needPassword(url: string): Promise<boolean> {
// A jupyter server will redirect if you ask for the tree when a login is required
const response = await this.makeRequest(new URL('tree?', url).toString(), {
const response = await this.makeRequest(new URL('tree?', addTrailingSlash(url)).toString(), {
method: 'get',
redirect: 'manual',
headers: { Connection: 'keep-alive' }
Expand Down Expand Up @@ -305,7 +305,7 @@ export class JupyterPasswordConnect {
postParams.append('_xsrf', xsrfCookie);
postParams.append('password', password);

const response = await this.makeRequest(new URL('login?', url).toString(), {
const response = await this.makeRequest(new URL('login?', addTrailingSlash(url)).toString(), {
method: 'post',
headers: {
Cookie: `_xsrf=${xsrfCookie}`,
Expand Down Expand Up @@ -361,7 +361,7 @@ export class JupyterPasswordConnect {
}
}

function addTrailingSlash(url: string): string {
export function addTrailingSlash(url: string): string {
let newUrl = url;
if (newUrl[newUrl.length - 1] !== '/') {
newUrl = `${newUrl}/`;
Expand Down

0 comments on commit a797e4d

Please sign in to comment.