@metreeca/http - v0.1.1
    Preparing search index...

    Function basic

    • Creates a middleware authenticating requests with the Basic scheme.

      Decorates a Fetch implementation with one adding an Authorization header carrying the given credentials to every request, alongside the headers supplied by the caller; credentials already carried by the request are replaced, so the middleware is best applied to a client dedicated to a single origin.

      Requests are normalised as Request objects before the header is attached, preserving the headers and the options carried by a Request input alongside the overrides supplied through init.

      Credentials are joined as usr:pwd, normalised to Unicode NFC, and encoded as UTF-8 base64 once when the middleware is created, leaving nothing to compute on the request path.

      Warning

      Base64 is not encryption: Basic credentials travel in a form any observer of the exchange may decode. Confine them to https exchanges, as RFC 7617 § 4 requires.

      Parameters

      • usr: string

        The user id to authenticate as; must contain no colon, which delimits the two credentials

      • pwd: string

        The password to authenticate with

      Returns Middleware

      A Middleware wrapping a Fetch implementation with one authenticating every request as usr

      If usr contains a colon