aboutsummaryrefslogtreecommitdiff
path: root/lib/libfetch/http.c
diff options
context:
space:
mode:
authorBaptiste Daroussin <bapt@FreeBSD.org>2014-06-05 22:16:26 +0000
committerBaptiste Daroussin <bapt@FreeBSD.org>2014-06-05 22:16:26 +0000
commitc41991303c3700f36ab27b62d563b5228c2442d6 (patch)
treef36cb2d2a75d718f0c539d3f94b0530b1c076bc8 /lib/libfetch/http.c
parent4bd8c06c3a296d62c6ce6e0cce5d1f83c1af1e9a (diff)
downloadsrc-c41991303c3700f36ab27b62d563b5228c2442d6.tar.gz
src-c41991303c3700f36ab27b62d563b5228c2442d6.zip
Add support for arbitrary http requests
Submitted by: Alex Hornung <alex@alexhornung.com> Reviewed by: des Obtained from: Dragonfly MFC after: 3 week
Notes
Notes: svn path=/head/; revision=267133
Diffstat (limited to 'lib/libfetch/http.c')
-rw-r--r--lib/libfetch/http.c34
1 files changed, 32 insertions, 2 deletions
diff --git a/lib/libfetch/http.c b/lib/libfetch/http.c
index fe346050a209..ad4a41952151 100644
--- a/lib/libfetch/http.c
+++ b/lib/libfetch/http.c
@@ -1494,6 +1494,14 @@ http_print_html(FILE *out, FILE *in)
* Core
*/
+FILE *
+http_request(struct url *URL, const char *op, struct url_stat *us,
+ struct url *purl, const char *flags)
+{
+
+ return (http_request_body(URL, op, us, purl, flags, NULL, NULL));
+}
+
/*
* Send a request and process the reply
*
@@ -1501,8 +1509,9 @@ http_print_html(FILE *out, FILE *in)
* XXX off into a separate function.
*/
FILE *
-http_request(struct url *URL, const char *op, struct url_stat *us,
- struct url *purl, const char *flags)
+http_request_body(struct url *URL, const char *op, struct url_stat *us,
+ struct url *purl, const char *flags, const char *content_type,
+ const char *body)
{
char timebuf[80];
char hbuf[MAXHOSTNAMELEN + 7], *host;
@@ -1519,6 +1528,7 @@ http_request(struct url *URL, const char *op, struct url_stat *us,
http_headerbuf_t headerbuf;
http_auth_challenges_t server_challenges;
http_auth_challenges_t proxy_challenges;
+ size_t body_len;
/* The following calls don't allocate anything */
init_http_headerbuf(&headerbuf);
@@ -1695,8 +1705,19 @@ http_request(struct url *URL, const char *op, struct url_stat *us,
if (url->offset > 0)
http_cmd(conn, "Range: bytes=%lld-", (long long)url->offset);
http_cmd(conn, "Connection: close");
+
+ if (body) {
+ body_len = strlen(body);
+ http_cmd(conn, "Content-Length: %zu", body_len);
+ if (content_type != NULL)
+ http_cmd(conn, "Content-Type: %s", content_type);
+ }
+
http_cmd(conn, "");
+ if (body)
+ fetch_write(conn, body, body_len);
+
/*
* Force the queued request to be dispatched. Normally, one
* would do this with shutdown(2) but squid proxies can be
@@ -2047,3 +2068,12 @@ fetchListHTTP(struct url *url __unused, const char *flags __unused)
warnx("fetchListHTTP(): not implemented");
return (NULL);
}
+
+FILE *
+fetchReqHTTP(struct url *URL, const char *method, const char *flags,
+ const char *content_type, const char *body)
+{
+
+ return (http_request_body(URL, method, NULL, http_get_proxy(URL, flags),
+ flags, content_type, body));
+}