summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorCarlos Martín Nieto <cmn@dwim.me>2015-10-02 03:46:34 +0200
committerCarlos Martín Nieto <cmn@dwim.me>2015-11-12 17:18:42 +0100
commit94bac76c3f701647b71e3f6dd6f8c434524a4b61 (patch)
tree63db2dacb9fe73acc13aeea105b9066286292807 /src
parentde870533e02505f3868403dabd7699da01e4ceda (diff)
downloadlibgit2-94bac76c3f701647b71e3f6dd6f8c434524a4b61.tar.gz
http: use a custom user-agent if the user has set it
We still prefix it with "git/1.0" since that's required in many situations, but we replace the area which mentions libgit2.
Diffstat (limited to 'src')
-rw-r--r--src/transports/http.c13
1 files changed, 12 insertions, 1 deletions
diff --git a/src/transports/http.c b/src/transports/http.c
index e5f2b9f28..88b124bf7 100644
--- a/src/transports/http.c
+++ b/src/transports/http.c
@@ -10,6 +10,7 @@
#include "http_parser.h"
#include "buffer.h"
#include "netops.h"
+#include "global.h"
#include "remote.h"
#include "smart.h"
#include "auth.h"
@@ -186,6 +187,16 @@ static int apply_credentials(git_buf *buf, http_subtransport *t)
return context->next_token(buf, context, cred);
}
+static const char *user_agent(void)
+{
+ const char *custom = git_libgit2__user_agent();
+
+ if (custom)
+ return custom;
+
+ return "libgit2 " LIBGIT2_VERSION;
+}
+
static int gen_request(
git_buf *buf,
http_stream *s,
@@ -197,7 +208,7 @@ static int gen_request(
git_buf_printf(buf, "%s %s%s HTTP/1.1\r\n", s->verb, path, s->service_url);
- git_buf_puts(buf, "User-Agent: git/1.0 (libgit2 " LIBGIT2_VERSION ")\r\n");
+ git_buf_printf(buf, "User-Agent: git/1.0 (%s)\r\n", user_agent());
git_buf_printf(buf, "Host: %s\r\n", t->connection_data.host);
if (s->chunked || content_length > 0) {