}
/*
- * HTTP URL construction
+ * HTTP URL manipulation
*/
-static void http_url_add_target(string_t *urlstr, const struct http_url *url)
+void http_url_copy_authority(pool_t pool, struct http_url *dest,
+ const struct http_url *src)
{
- if (url->path == NULL || *url->path == '\0') {
- /* Older syntax of RFC 2616 requires this slash at all times for an
- absolute URL
- */
- str_append_c(urlstr, '/');
- } else {
- uri_append_path_data(urlstr, "", url->path);
+ dest->host_name = p_strdup(pool, src->host_name);
+ if (src->have_host_ip) {
+ dest->host_ip = src->host_ip;
+ dest->have_host_ip = TRUE;
}
-
- /* query (pre-encoded) */
- if (url->enc_query != NULL) {
- str_append_c(urlstr, '?');
- str_append(urlstr, url->enc_query);
+ if (src->have_port) {
+ dest->port = src->port;
+ dest->have_port = TRUE;
}
+ dest->have_ssl = src->have_ssl;
}
-const char *http_url_create(const struct http_url *url)
+void http_url_copy(pool_t pool, struct http_url *dest,
+ const struct http_url *src)
{
- string_t *urlstr = t_str_new(512);
+ http_url_copy_authority(pool, dest, src);
+ dest->path = p_strdup(pool, src->path);
+ dest->enc_query = p_strdup(pool, src->enc_query);
+ dest->enc_fragment = p_strdup(pool, src->enc_fragment);
+}
+struct http_url *http_url_clone(pool_t pool,const struct http_url *src)
+{
+ struct http_url *new_url;
+
+ new_url = p_new(pool, struct http_url, 1);
+ http_url_copy(pool, new_url, src);
+
+ return new_url;
+}
+
+/*
+ * HTTP URL construction
+ */
+
+static void
+http_url_add_scheme(string_t *urlstr, const struct http_url *url)
+{
/* scheme */
- uri_append_scheme(urlstr, "http");
+ if (!url->have_ssl)
+ uri_append_scheme(urlstr, "http");
+ else
+ uri_append_scheme(urlstr, "https");
str_append(urlstr, "//");
+}
+static void
+http_url_add_authority(string_t *urlstr, const struct http_url *url)
+{
/* host:port */
if (url->host_name != NULL) {
/* assume IPv6 literal if starts with '['; avoid encoding */
i_unreached();
if (url->have_port)
uri_append_port(urlstr, url->port);
+}
+
+static void
+http_url_add_target(string_t *urlstr, const struct http_url *url)
+{
+ if (url->path == NULL || *url->path == '\0') {
+ /* Older syntax of RFC 2616 requires this slash at all times for an
+ absolute URL
+ */
+ str_append_c(urlstr, '/');
+ } else {
+ uri_append_path_data(urlstr, "", url->path);
+ }
+
+ /* query (pre-encoded) */
+ if (url->enc_query != NULL) {
+ str_append_c(urlstr, '?');
+ str_append(urlstr, url->enc_query);
+ }
+}
+
+const char *http_url_create(const struct http_url *url)
+{
+ string_t *urlstr = t_str_new(512);
+ http_url_add_scheme(urlstr, url);
+ http_url_add_authority(urlstr, url);
http_url_add_target(urlstr, url);
/* fragment */
return str_c(urlstr);
}
+const char *http_url_create_host(const struct http_url *url)
+{
+ string_t *urlstr = t_str_new(512);
+
+ http_url_add_scheme(urlstr, url);
+ http_url_add_authority(urlstr, url);
+
+ return str_c(urlstr);
+}
+
+const char *http_url_create_authority(const struct http_url *url)
+{
+ string_t *urlstr = t_str_new(256);
+
+ http_url_add_authority(urlstr, url);
+
+ return str_c(urlstr);
+}
+
const char *http_url_create_target(const struct http_url *url)
{
string_t *urlstr = t_str_new(256);
const char *host_header, pool_t pool,
struct http_request_target *target, const char **error_r);
+/*
+ * HTTP URL manipulation
+ */
+
+void http_url_copy_authority(pool_t pool, struct http_url *dest,
+ const struct http_url *src);
+void http_url_copy(pool_t pool, struct http_url *dest,
+ const struct http_url *src);
+struct http_url *http_url_clone(pool_t pool,const struct http_url *src);
+
/*
* HTTP URL construction
*/
const char *http_url_create(const struct http_url *url);
+const char *http_url_create_host(const struct http_url *url);
+const char *http_url_create_authority(const struct http_url *url);
const char *http_url_create_target(const struct http_url *url);
void http_url_escape_param(string_t *out, const char *data);