basic_auth_client.d 573 B

123456789101112131415161718192021
  1. /**
  2. Implements HTTP Basic Auth for client.
  3. License: Subject to the terms of the MIT license, as written in the included LICENSE.txt file.
  4. */
  5. module vibe.http.internal.basic_auth_client;
  6. import vibe.http.common;
  7. import std.base64;
  8. @safe:
  9. /**
  10. Augments the given HTTP request with an HTTP Basic Auth header.
  11. */
  12. void addBasicAuth(scope HTTPRequest req, string user, string password)
  13. {
  14. string pwstr = user ~ ":" ~ password;
  15. string authstr = () @trusted { return cast(string)Base64.encode(cast(ubyte[])pwstr); } ();
  16. req.headers["Authorization"] = "Basic " ~ authstr;
  17. }