Skip to content

Commit

Permalink
lib-http: url: Add functions that obtain the effective port for the URL.
Browse files Browse the repository at this point in the history
When no port is set for the URL, it is set to 0. These functions substitute the
applicable default.
  • Loading branch information
stephanbosch authored and sirainen committed Feb 26, 2018
1 parent fab1c26 commit 777776d
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions src/lib-http/http-url.h
Expand Up @@ -4,6 +4,8 @@
#include "net.h"
#include "uri-util.h"

#include "http-common.h"

struct http_request_target;

struct http_url {
Expand Down Expand Up @@ -51,6 +53,22 @@ int http_url_request_target_parse(const char *request_target,
const char *host_header, pool_t pool,
struct http_request_target *target, const char **error_r);

/*
* HTTP URL evaluation
*/

static inline in_port_t http_url_get_port_default(const struct http_url *url,
in_port_t default_port)
{
return (url->port != 0 ? url->port : default_port);
}

static inline in_port_t http_url_get_port(const struct http_url *url)
{
return http_url_get_port_default(url,
(url->have_ssl ? HTTPS_DEFAULT_PORT : HTTP_DEFAULT_PORT));
}

/*
* HTTP URL manipulation
*/
Expand Down

0 comments on commit 777776d

Please sign in to comment.