diff options
author | Edward Thomson <ethomson@edwardthomson.com> | 2018-11-18 22:56:28 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-11-18 22:56:28 +0000 |
commit | 4ef2b889a45496f2afc8df1c5570ffc90e650bfa (patch) | |
tree | 98247ba5fc129b6928a2d87022a0ff6b117bb336 | |
parent | 7321cff05df927c8d00755ef21289ec00d125c9c (diff) | |
parent | 83b351812f3edee077ab9327375994dd2044dd09 (diff) | |
download | libgit2-4ef2b889a45496f2afc8df1c5570ffc90e650bfa.tar.gz |
Merge pull request #4882 from kc8apf/include_port_in_host_header
transport/http: Include non-default ports in Host header
-rw-r--r-- | src/netops.c | 15 | ||||
-rw-r--r-- | src/netops.h | 2 | ||||
-rw-r--r-- | src/transports/http.c | 6 |
3 files changed, 19 insertions, 4 deletions
diff --git a/src/netops.c b/src/netops.c index efcc6c5a7..272d0ccd8 100644 --- a/src/netops.c +++ b/src/netops.c @@ -119,6 +119,15 @@ int gitno__match_host(const char *pattern, const char *host) return -1; } +static const char *default_port_http = "80"; +static const char *default_port_https = "443"; + +const char *gitno__default_port( + gitno_connection_data *data) +{ + return data->use_ssl ? default_port_https : default_port_http; +} + static const char *prefix_http = "http://"; static const char *prefix_https = "https://"; @@ -141,7 +150,7 @@ int gitno_connection_data_from_url( if (!git__prefixcmp(url, prefix_http)) { path_search_start = url + strlen(prefix_http); - default_port = "80"; + default_port = default_port_http; if (data->use_ssl) { giterr_set(GITERR_NET, "redirect from HTTPS to HTTP is not allowed"); @@ -149,10 +158,10 @@ int gitno_connection_data_from_url( } } else if (!git__prefixcmp(url, prefix_https)) { path_search_start = url + strlen(prefix_https); - default_port = "443"; + default_port = default_port_https; data->use_ssl = true; } else if (url[0] == '/') - default_port = data->use_ssl ? "443" : "80"; + default_port = gitno__default_port(data); if (!default_port) { giterr_set(GITERR_NET, "unrecognized URL prefix"); diff --git a/src/netops.h b/src/netops.h index 75fd9a512..f376bd911 100644 --- a/src/netops.h +++ b/src/netops.h @@ -96,4 +96,6 @@ int gitno_extract_url_parts( const char *url, const char *default_port); +const char *gitno__default_port(gitno_connection_data *data); + #endif diff --git a/src/transports/http.c b/src/transports/http.c index 0942daf3e..51219963c 100644 --- a/src/transports/http.c +++ b/src/transports/http.c @@ -208,7 +208,11 @@ static int gen_request( 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", t->connection_data.host); + if (strcmp(t->connection_data.port, gitno__default_port(&t->connection_data)) != 0) { + git_buf_printf(buf, ":%s", t->connection_data.port); + } + git_buf_puts(buf, "\r\n"); if (s->chunked || content_length > 0) { git_buf_printf(buf, "Accept: application/x-git-%s-result\r\n", s->service); |