File tree 1 file changed +34
-2
lines changed 1 file changed +34
-2
lines changed Original file line number Diff line number Diff line change 15
15
#include "smart.h"
16
16
#include "remote.h"
17
17
#include "repository.h"
18
+ #include "global.h"
18
19
19
20
#include <wincrypt.h>
20
21
#include <winhttp.h>
@@ -567,12 +568,28 @@ static int winhttp_close_connection(winhttp_subtransport *t)
567
568
return ret ;
568
569
}
569
570
571
+ static int user_agent (git_buf * ua )
572
+ {
573
+ const char * custom = git_libgit2__user_agent ();
574
+
575
+ git_buf_clear (ua );
576
+ git_buf_PUTS (ua , "git/1.0 (" );
577
+
578
+ if (custom )
579
+ git_buf_puts (ua , custom );
580
+ else
581
+ git_buf_PUTS (ua , "libgit2 " LIBGIT2_VERSION );
582
+
583
+ return git_buf_putc (ua , ')' );
584
+ }
585
+
570
586
static int winhttp_connect (
571
587
winhttp_subtransport * t )
572
588
{
573
- wchar_t * ua = L"git/1.0 (libgit2 " WIDEN (LIBGIT2_VERSION ) L")" ;
574
589
wchar_t * wide_host ;
575
590
int32_t port ;
591
+ wchar_t * wide_ua ;
592
+ git_buf ua = GIT_BUF_INIT ;
576
593
int error = -1 ;
577
594
int default_timeout = TIMEOUT_INFINITE ;
578
595
int default_connect_timeout = DEFAULT_CONNECT_TIMEOUT ;
@@ -590,9 +607,23 @@ static int winhttp_connect(
590
607
return -1 ;
591
608
}
592
609
610
+ if ((error = user_agent (& ua )) < 0 ) {
611
+ git__free (wide_host );
612
+ return error ;
613
+ }
614
+
615
+ if (git__utf8_to_16_alloc (& wide_ua , git_buf_cstr (& ua )) < 0 ) {
616
+ giterr_set (GITERR_OS , "Unable to convert host to wide characters" );
617
+ git__free (wide_host );
618
+ git_buf_free (& ua );
619
+ return -1 ;
620
+ }
621
+
622
+ git_buf_free (& ua );
623
+
593
624
/* Establish session */
594
625
t -> session = WinHttpOpen (
595
- ua ,
626
+ wide_ua ,
596
627
WINHTTP_ACCESS_TYPE_DEFAULT_PROXY ,
597
628
WINHTTP_NO_PROXY_NAME ,
598
629
WINHTTP_NO_PROXY_BYPASS ,
@@ -628,6 +659,7 @@ static int winhttp_connect(
628
659
winhttp_close_connection (t );
629
660
630
661
git__free (wide_host );
662
+ git__free (wide_ua );
631
663
632
664
return error ;
633
665
}
You can’t perform that action at this time.
0 commit comments