summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorbapt <bapt@FreeBSD.org>2014-06-05 22:16:26 +0000
committerbapt <bapt@FreeBSD.org>2014-06-05 22:16:26 +0000
commit1b8c8ebb57773b1f91693a2c415eb211531a4f8e (patch)
treef36cb2d2a75d718f0c539d3f94b0530b1c076bc8 /lib
parentc84894dbf33070c6eacb47348c5302f859f53265 (diff)
downloadFreeBSD-src-1b8c8ebb57773b1f91693a2c415eb211531a4f8e.zip
FreeBSD-src-1b8c8ebb57773b1f91693a2c415eb211531a4f8e.tar.gz
Add support for arbitrary http requests
Submitted by: Alex Hornung <alex@alexhornung.com> Reviewed by: des Obtained from: Dragonfly MFC after: 3 week
Diffstat (limited to 'lib')
-rw-r--r--lib/libfetch/common.h3
-rw-r--r--lib/libfetch/fetch.h2
-rw-r--r--lib/libfetch/http.c34
3 files changed, 37 insertions, 2 deletions
diff --git a/lib/libfetch/common.h b/lib/libfetch/common.h
index 875eef1..41c10d2 100644
--- a/lib/libfetch/common.h
+++ b/lib/libfetch/common.h
@@ -117,6 +117,9 @@ int fetch_no_proxy_match(const char *);
*/
FILE *http_request(struct url *, const char *,
struct url_stat *, struct url *, const char *);
+FILE *http_request_body(struct url *, const char *,
+ struct url_stat *, struct url *, const char *,
+ const char *, const char *);
FILE *ftp_request(struct url *, const char *,
struct url_stat *, struct url *, const char *);
diff --git a/lib/libfetch/fetch.h b/lib/libfetch/fetch.h
index be49482..d56a103 100644
--- a/lib/libfetch/fetch.h
+++ b/lib/libfetch/fetch.h
@@ -102,6 +102,8 @@ FILE *fetchGetHTTP(struct url *, const char *);
FILE *fetchPutHTTP(struct url *, const char *);
int fetchStatHTTP(struct url *, struct url_stat *, const char *);
struct url_ent *fetchListHTTP(struct url *, const char *);
+FILE *fetchReqHTTP(struct url *, const char *, const char *,
+ const char *, const char *);
/* FTP-specific functions */
FILE *fetchXGetFTP(struct url *, struct url_stat *, const char *);
diff --git a/lib/libfetch/http.c b/lib/libfetch/http.c
index fe34605..ad4a419 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));
+}
OpenPOWER on IntegriCloud