diff --git a/README.md b/README.md index fbaac80..56f0702 100644 --- a/README.md +++ b/README.md @@ -1199,6 +1199,25 @@ requests.minifyhtml("

Hello

World

") +## gen_auth_header() +
+ +**Description:** +Helper for HTTP Authentication headers. + +Returns 1 string kinda like "Basic base64(username):base64(username)", +so it can be used like `[ ("Authorization": gen_auth_header("username", "password") ) ]`. +See https://github.com/juancarlospaco/faster-than-requests/issues/168#issuecomment-858999317 + +**Arguments:** +- `username` Username string, must not be empty string, required. +- `password` Password string, must not be empty string, required. + +**Returns:** string. + +
+ + ## debugs
**Description:** diff --git a/faster_than_requests/faster_than_requests.nim b/faster_than_requests/faster_than_requests.nim index 4f025fe..17db9cf 100644 --- a/faster_than_requests/faster_than_requests.nim +++ b/faster_than_requests/faster_than_requests.nim @@ -1,5 +1,5 @@ import - asyncdispatch, db_sqlite, htmlparser, httpclient, json, nimpy, os, sequtils, + asyncdispatch, db_sqlite, htmlparser, httpclient, json, nimpy, os, sequtils, base64, pegs, re, strtabs, strutils, tables, threadpool, uri, ws, sequtils, xmltree, std/tasks @@ -171,6 +171,10 @@ proc datauri*(data: string; mime: string; encoding: string = "utf-8"): string {. result = uri.getDataUri(data, mime, encoding) +proc gen_auth_header*(username: string; password: string): string {.exportpy.} = + "Basic " & base64.encode(username & ':' & password) + + proc debugs*() {.discardable, exportpy.} = ## Get the Config and print it to the terminal, for debug purposes only, human friendly. echo static(pretty(%*{