Skip to content

Parameters "ssl" and "authtype" do not work #2

@jonpfote

Description

@jonpfote

Hello,
I noticed that the parameters "ssl" and "authtype" currently do not work.

The current code (which has the bug) can be found here: https://github.com/vscode-lcode/webdav/blob/main/lib/webdav.js#L180-L236

Please change the implementation of getClient in lib/webdav.js to the following code:

  getClient(uri) {
    const searchParams = new URLSearchParams(uri.query)


    // ssl
    let protocol = "http://"
    if (["", "true", "1"].indexOf(searchParams.get("ssl")) > -1) {
      protocol = "https://";
    }

    // connection already established
    const key = protocol + uri.authority;
    if (this.clients[key]) {
      return this.clients[key];
    }

    /**@type {webdav.WebDAVClientOptions} */
    const opt = {};

    // auth
    if (
      uri.authority.indexOf("@") >= 0
      && uri.authority.indexOf(":") >= 0
      && uri.authority.indexOf(":") < uri.authority.indexOf("@")
      && searchParams.has("authtype")
    ) {
      const authtype = searchParams.get("authtype");
      const [username, password] = (uri.authority.split("@")[0]).split(":")
      switch (authtype) {
        case "":
        case "b":
        case "basic":
          opt.authType = webdav.AuthType.Password;
          opt.username = username;
          opt.password = password;
          break;

        case "d":
        case "digest":
          opt.authType = webdav.AuthType.Digest;
          opt.username = username;
          opt.password = password;
          break;

        default:
          throw new Error(
            `Authentication type '${authtype}' is not supported!`
          );
      }
    }

    let client = webdav.createClient(key, opt);
    this.clients[key] = client;
    return client;
  }
}

This means that getOriginWithAuth can be removed as my implementation does not use it.
https://github.com/vscode-lcode/webdav/blob/main/lib/webdav.js#L180-L236

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions