Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
git2
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
lvzhengyang
git2
Commits
408b16c1
Unverified
Commit
408b16c1
authored
Feb 10, 2018
by
Edward Thomson
Committed by
GitHub
Feb 10, 2018
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #4508 from libgit2/ethomson/user_agent
http: standardize user-agent addition
parents
05c24c44
ee6be190
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
30 additions
and
27 deletions
+30
-27
src/transports/http.c
+4
-11
src/transports/http.h
+23
-0
src/transports/winhttp.c
+3
-16
No files found.
src/transports/http.c
View file @
408b16c1
...
@@ -17,6 +17,7 @@
...
@@ -17,6 +17,7 @@
#include "remote.h"
#include "remote.h"
#include "smart.h"
#include "smart.h"
#include "auth.h"
#include "auth.h"
#include "http.h"
#include "auth_negotiate.h"
#include "auth_negotiate.h"
#include "streams/tls.h"
#include "streams/tls.h"
#include "streams/socket.h"
#include "streams/socket.h"
...
@@ -190,16 +191,6 @@ static int apply_credentials(git_buf *buf, http_subtransport *t)
...
@@ -190,16 +191,6 @@ static int apply_credentials(git_buf *buf, http_subtransport *t)
return
context
->
next_token
(
buf
,
context
,
cred
);
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
(
static
int
gen_request
(
git_buf
*
buf
,
git_buf
*
buf
,
http_stream
*
s
,
http_stream
*
s
,
...
@@ -211,7 +202,9 @@ static int gen_request(
...
@@ -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
,
"%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
);
git_buf_printf
(
buf
,
"Host: %s
\r\n
"
,
t
->
connection_data
.
host
);
if
(
s
->
chunked
||
content_length
>
0
)
{
if
(
s
->
chunked
||
content_length
>
0
)
{
...
...
src/transports/http.h
0 → 100644
View file @
408b16c1
/*
* 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
src/transports/winhttp.c
View file @
408b16c1
...
@@ -18,6 +18,7 @@
...
@@ -18,6 +18,7 @@
#include "remote.h"
#include "remote.h"
#include "repository.h"
#include "repository.h"
#include "global.h"
#include "global.h"
#include "http.h"
#include <wincrypt.h>
#include <wincrypt.h>
#include <winhttp.h>
#include <winhttp.h>
...
@@ -701,21 +702,6 @@ static int winhttp_close_connection(winhttp_subtransport *t)
...
@@ -701,21 +702,6 @@ static int winhttp_close_connection(winhttp_subtransport *t)
return
ret
;
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
(
static
void
CALLBACK
winhttp_status
(
HINTERNET
connection
,
HINTERNET
connection
,
DWORD_PTR
ctx
,
DWORD_PTR
ctx
,
...
@@ -772,7 +758,8 @@ static int winhttp_connect(
...
@@ -772,7 +758,8 @@ static int winhttp_connect(
return
-
1
;
return
-
1
;
}
}
if
((
error
=
user_agent
(
&
ua
))
<
0
)
{
if
((
error
=
git_http__user_agent
(
&
ua
))
<
0
)
{
git__free
(
wide_host
);
git__free
(
wide_host
);
return
error
;
return
error
;
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment