diff options
author | Edward Thomson <ethomson@edwardthomson.com> | 2018-02-10 08:00:36 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-02-10 08:00:36 +0000 |
commit | 408b16c1b06526f509fdb8997818d648d4d1ea1e (patch) | |
tree | ff3d5dfd22fd0850f246dcea1134396cf8b8d198 | |
parent | 05c24c44e67a09b88411aca5f12d31e907d1a35d (diff) | |
parent | ee6be190e69ae26cec589e99b48f901b18b8e873 (diff) | |
download | libgit2-408b16c1b06526f509fdb8997818d648d4d1ea1e.tar.gz |
Merge pull request #4508 from libgit2/ethomson/user_agent
http: standardize user-agent addition
-rw-r--r-- | src/transports/http.c | 15 | ||||
-rw-r--r-- | src/transports/http.h | 23 | ||||
-rw-r--r-- | src/transports/winhttp.c | 19 |
3 files changed, 30 insertions, 27 deletions
diff --git a/src/transports/http.c b/src/transports/http.c index 095cfdf2f..e051c8a35 100644 --- a/src/transports/http.c +++ b/src/transports/http.c @@ -17,6 +17,7 @@ #include "remote.h" #include "smart.h" #include "auth.h" +#include "http.h" #include "auth_negotiate.h" #include "streams/tls.h" #include "streams/socket.h" @@ -190,16 +191,6 @@ 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, @@ -211,7 +202,9 @@ static int gen_request( git_buf_printf(buf, "%s %s%s HTTP/1.1\r\n", s->verb, path, s->service_url); - git_buf_printf(buf, "User-Agent: git/2.0 (%s)\r\n", user_agent()); + git_buf_puts(buf, "User-Agent: "); + git_http__user_agent(buf); + git_buf_puts(buf, "\r\n"); git_buf_printf(buf, "Host: %s\r\n", t->connection_data.host); if (s->chunked || content_length > 0) { diff --git a/src/transports/http.h b/src/transports/http.h new file mode 100644 index 000000000..6c4ecc9a4 --- /dev/null +++ b/src/transports/http.h @@ -0,0 +1,23 @@ +/* + * Copyright (C) the libgit2 contributors. All rights reserved. + * + * This file is part of libgit2, distributed under the GNU GPL v2 with + * a Linking Exception. For full terms see the included COPYING file. + */ + +#ifndef INCLUDE_transports_http_h__ +#define INCLUDE_transports_http_h__ + +#include "buffer.h" + +GIT_INLINE(int) git_http__user_agent(git_buf *buf) +{ + const char *ua = git_libgit2__user_agent(); + + if (!ua) + ua = "libgit2 " LIBGIT2_VERSION; + + return git_buf_printf(buf, "git/2.0 (%s)", ua); +} + +#endif diff --git a/src/transports/winhttp.c b/src/transports/winhttp.c index 6dad1d38a..46a8fcddc 100644 --- a/src/transports/winhttp.c +++ b/src/transports/winhttp.c @@ -18,6 +18,7 @@ #include "remote.h" #include "repository.h" #include "global.h" +#include "http.h" #include <wincrypt.h> #include <winhttp.h> @@ -701,21 +702,6 @@ static int winhttp_close_connection(winhttp_subtransport *t) return ret; } -static int user_agent(git_buf *ua) -{ - const char *custom = git_libgit2__user_agent(); - - git_buf_clear(ua); - git_buf_PUTS(ua, "git/1.0 ("); - - if (custom) - git_buf_puts(ua, custom); - else - git_buf_PUTS(ua, "libgit2 " LIBGIT2_VERSION); - - return git_buf_putc(ua, ')'); -} - static void CALLBACK winhttp_status( HINTERNET connection, DWORD_PTR ctx, @@ -772,7 +758,8 @@ static int winhttp_connect( return -1; } - if ((error = user_agent(&ua)) < 0) { + + if ((error = git_http__user_agent(&ua)) < 0) { git__free(wide_host); return error; } |