Don't send empty Authorization header for HTTP requests
If there's no username and/or password
Tested-by: Build Bot
@@ -406,6 +406,10 @@ Request::get_api_node(lcb_error_t &rc)
return lcbvb_get_resturl(vbc, ix, svc, mode);
}
+static bool is_nonempty(const char *s) {
+ return s != NULL && *s != '\0';
+}
+
lcb_error_t
Request::setup_inputs(const lcb_CMDHTTP *cmd)
{
@@ -473,7 +477,7 @@ Request::setup_inputs(const lcb_CMDHTTP *cmd)
}
add_header("Accept", "application/json");
- if (password && username) {
+ if (is_nonempty(password) && is_nonempty(username)) {
char auth[256];
std::string upassbuf;
upassbuf.append(username).append(":").append(password);
