summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEdward Thomson <ethomson@edwardthomson.com>2019-12-14 11:04:58 +0800
committerEdward Thomson <ethomson@edwardthomson.com>2020-01-24 10:16:36 -0600
commit0b8358c8d17b984efe3fb2700c0bab563e7e5477 (patch)
treeeb687580971c44c96920d28f78e216b6ec30233d
parent1152f3618c578740caa51891e9d005e0b3c476d8 (diff)
downloadlibgit2-0b8358c8d17b984efe3fb2700c0bab563e7e5477.tar.gz
net: introduce path formatting function
Introduce a function to format the path and query string for a URL, suitable for creating an HTTP request.
-rw-r--r--src/net.c12
-rw-r--r--src/net.h3
2 files changed, 15 insertions, 0 deletions
diff --git a/src/net.c b/src/net.c
index c70774306..2e466b6aa 100644
--- a/src/net.c
+++ b/src/net.c
@@ -381,6 +381,18 @@ int git_net_url_fmt(git_buf *buf, git_net_url *url)
return git_buf_oom(buf) ? -1 : 0;
}
+int git_net_url_fmt_path(git_buf *buf, git_net_url *url)
+{
+ git_buf_puts(buf, url->path ? url->path : "/");
+
+ if (url->query) {
+ git_buf_putc(buf, '?');
+ git_buf_puts(buf, url->query);
+ }
+
+ return git_buf_oom(buf) ? -1 : 0;
+}
+
void git_net_url_dispose(git_net_url *url)
{
if (url->username)
diff --git a/src/net.h b/src/net.h
index c140f9559..7e72db13f 100644
--- a/src/net.h
+++ b/src/net.h
@@ -48,6 +48,9 @@ extern void git_net_url_swap(git_net_url *a, git_net_url *b);
/** Places the URL into the given buffer. */
extern int git_net_url_fmt(git_buf *out, git_net_url *url);
+/** Place the path and query string into the given buffer. */
+extern int git_net_url_fmt_path(git_buf *buf, git_net_url *url);
+
/** Disposes the contents of the structure. */
extern void git_net_url_dispose(git_net_url *url);