summaryrefslogtreecommitdiff
path: root/src/libwaitress
diff options
context:
space:
mode:
Diffstat (limited to 'src/libwaitress')
-rw-r--r--src/libwaitress/waitress.c31
1 files changed, 31 insertions, 0 deletions
diff --git a/src/libwaitress/waitress.c b/src/libwaitress/waitress.c
index 3c48616..8bef2f6 100644
--- a/src/libwaitress/waitress.c
+++ b/src/libwaitress/waitress.c
@@ -466,6 +466,27 @@ static WaitressReturn_t WaitressPollRead (int sockfd, char *buf, size_t count,
CLOSE_RET (wRet); \
}
+/* send basic http authorization
+ * @param waitress handle
+ * @param url containing user/password
+ * @param header name prefix
+ */
+static bool WaitressFormatAuthorization (WaitressHandle_t *waith,
+ WaitressUrl_t *url, const char *prefix, char *writeBuf,
+ const size_t writeBufSize) {
+ if (url->user != NULL) {
+ char userPass[1024], *encodedUserPass;
+ snprintf (userPass, sizeof (userPass), "%s:%s", url->user,
+ (url->password != NULL) ? url->password : "");
+ encodedUserPass = WaitressBase64Encode (userPass);
+ snprintf (writeBuf, writeBufSize, "%sAuthorization: Basic %s\r\n",
+ prefix, encodedUserPass);
+ free (encodedUserPass);
+ return true;
+ }
+ return false;
+}
+
/* get default http port if none was given
*/
static const char *WaitressDefaultPort (WaitressUrl_t *url) {
@@ -576,6 +597,16 @@ WaitressReturn_t WaitressFetchCall (WaitressHandle_t *waith) {
strlen (waith->postData));
WRITE_RET (writeBuf, strlen (writeBuf));
}
+
+ /* write authorization headers */
+ if (WaitressFormatAuthorization (waith, &waith->url, "", writeBuf,
+ sizeof (writeBuf))) {
+ WRITE_RET (writeBuf, strlen (writeBuf));
+ }
+ if (WaitressFormatAuthorization (waith, &waith->proxy, "Proxy-",
+ writeBuf, sizeof (writeBuf))) {
+ WRITE_RET (writeBuf, strlen (writeBuf));
+ }
if (waith->extraHeaders != NULL) {
WRITE_RET (waith->extraHeaders, strlen (waith->extraHeaders));