Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 5 Jun 2014 22:16:27 +0000 (UTC)
From:      Baptiste Daroussin <bapt@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r267133 - head/lib/libfetch
Message-ID:  <201406052216.s55MGRiK017091@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: bapt
Date: Thu Jun  5 22:16:26 2014
New Revision: 267133
URL: http://svnweb.freebsd.org/changeset/base/267133

Log:
  Add support for arbitrary http requests
  
  Submitted by:	Alex Hornung <alex@alexhornung.com>
  Reviewed by:	des
  Obtained from:	Dragonfly
  MFC after:	3 week

Modified:
  head/lib/libfetch/common.h
  head/lib/libfetch/fetch.h
  head/lib/libfetch/http.c

Modified: head/lib/libfetch/common.h
==============================================================================
--- head/lib/libfetch/common.h	Thu Jun  5 22:13:30 2014	(r267132)
+++ head/lib/libfetch/common.h	Thu Jun  5 22:16:26 2014	(r267133)
@@ -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 *);
 

Modified: head/lib/libfetch/fetch.h
==============================================================================
--- head/lib/libfetch/fetch.h	Thu Jun  5 22:13:30 2014	(r267132)
+++ head/lib/libfetch/fetch.h	Thu Jun  5 22:16:26 2014	(r267133)
@@ -102,6 +102,8 @@ FILE		*fetchGetHTTP(struct url *, const 
 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 *);

Modified: head/lib/libfetch/http.c
==============================================================================
--- head/lib/libfetch/http.c	Thu Jun  5 22:13:30 2014	(r267132)
+++ head/lib/libfetch/http.c	Thu Jun  5 22:16:26 2014	(r267133)
@@ -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
 	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
 		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, 
 	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));
+}



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201406052216.s55MGRiK017091>