summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorSean Young <sean@mess.org>2016-01-31 11:31:00 +0000
committerAzat Khuzhin <azat@libevent.org>2021-08-10 23:22:10 +0300
commitf446229b2206691eae7ec892e68b2a0d6ef61306 (patch)
treebbf3a0befb4d9f9affdbe2281d15c278195c9716 /include
parent6f139b871100aa2322598dfd37c4145e033d2602 (diff)
downloadlibevent-f446229b2206691eae7ec892e68b2a0d6ef61306.tar.gz
http: support unix domain sockets
There are no standard for encoding a unix socket in an url. nginx uses: http://unix:/path/to/unix/socket:/httppath The second colon is needed to delimit where the unix path ends and where the rest of the url continues. Signed-off-by: Sean Young <sean@mess.org>
Diffstat (limited to 'include')
-rw-r--r--include/event2/http.h34
1 files changed, 33 insertions, 1 deletions
diff --git a/include/event2/http.h b/include/event2/http.h
index 22e6122e..89175fb7 100644
--- a/include/event2/http.h
+++ b/include/event2/http.h
@@ -652,7 +652,7 @@ enum evhttp_request_kind { EVHTTP_REQUEST, EVHTTP_RESPONSE };
* @param dnsbase the dns_base to use for resolving host names; if not
* specified host name resolution will block.
* @param bev a bufferevent to use for connecting to the server; if NULL, a
- * socket-based bufferevent will be created. This buffrevent will be freed
+ * socket-based bufferevent will be created. This bufferevent will be freed
* when the connection closes. It must have no fd set on it.
* @param address the address to which to connect
* @param port the port to connect to
@@ -664,6 +664,21 @@ struct evhttp_connection *evhttp_connection_base_bufferevent_new(
struct event_base *base, struct evdns_base *dnsbase, struct bufferevent* bev, const char *address, ev_uint16_t port);
/**
+ * Create and return a connection object that can be used to for making HTTP
+ * requests over an unix domain socket.
+ *
+ * @param base the event_base to use for handling the connection
+ * @param bev a bufferevent to use for connecting to the server; if NULL, a
+ * socket-based bufferevent will be created. This bufferevent will be freed
+ * when the connection closes. It must have no fd set on it.
+ * @param path path of unix domain socket
+ * @return an evhttp_connection object that can be used for making requests
+ */
+EVENT2_EXPORT_SYMBOL
+struct evhttp_connection *evhttp_connection_base_bufferevent_unix_new(
+ struct event_base *base, struct bufferevent* bev, const char *path);
+
+/**
* Return the bufferevent that an evhttp_connection is using.
*/
EVENT2_EXPORT_SYMBOL
@@ -1285,6 +1300,10 @@ const char *evhttp_uri_get_userinfo(const struct evhttp_uri *uri);
*/
EVENT2_EXPORT_SYMBOL
const char *evhttp_uri_get_host(const struct evhttp_uri *uri);
+/** Return the unix socket part of an evhttp_uri, or NULL if there is no unix
+ * socket set */
+EVENT2_EXPORT_SYMBOL
+const char *evhttp_uri_get_unixsocket(const struct evhttp_uri *uri);
/** Return the port part of an evhttp_uri, or -1 if there is no port set. */
EVENT2_EXPORT_SYMBOL
int evhttp_uri_get_port(const struct evhttp_uri *uri);
@@ -1312,6 +1331,11 @@ int evhttp_uri_set_userinfo(struct evhttp_uri *uri, const char *userinfo);
* Returns 0 on success, -1 if host is not well-formed. */
EVENT2_EXPORT_SYMBOL
int evhttp_uri_set_host(struct evhttp_uri *uri, const char *host);
+/** Set the unix socket of an evhttp_uri, or clear the unix socket if unixsocket==NULL.
+ * Returns 0 on success, -1 if unixsocket is not well-formed */
+EVENT2_EXPORT_SYMBOL
+int evhttp_uri_set_unixsocket(struct evhttp_uri *uri, const char *unixsocket);
+
/** Set the port of an evhttp_uri, or clear the port if port==-1.
* Returns 0 on success, -1 if port is not well-formed. */
EVENT2_EXPORT_SYMBOL
@@ -1382,6 +1406,7 @@ struct evhttp_uri *evhttp_uri_parse_with_flags(const char *source_uri,
* </ul>
*/
#define EVHTTP_URI_NONCONFORMANT 0x01
+
/**
* Strip brackets from the IPv6 address and only for evhttp_uri_get_host(),
* evhttp_uri_join() returns the host with brackets.
@@ -1392,6 +1417,13 @@ struct evhttp_uri *evhttp_uri_parse_with_flags(const char *source_uri,
*/
#define EVHTTP_URI_HOST_STRIP_BRACKETS 0x04
+/**
+ * Parse unix domain socket URIs, for example:
+ *
+ * http://unix:/run/control.sock:/controller
+ */
+#define EVHTTP_URI_UNIX_SOCKET 0x08
+
/** Alias for evhttp_uri_parse_with_flags(source_uri, 0) */
EVENT2_EXPORT_SYMBOL
struct evhttp_uri *evhttp_uri_parse(const char *source_uri);