Skip to content

Commit

Permalink
add vod_base_url param
Browse files Browse the repository at this point in the history
  • Loading branch information
erankor committed May 8, 2016
1 parent fac88bc commit 8db1352
Show file tree
Hide file tree
Showing 9 changed files with 163 additions and 82 deletions.
31 changes: 31 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,37 @@
Note: the list of changes below may not include all changes, it will include mostly "breaking" changes.
Usually, these are changes that require some update to nginx.conf in order to retain the existing behavior.

## 2016/05/08 - provide more control of the domain of returned URLs

The following configuration settings were removed:
* vod_https_header_name - use vod_base_url instead, e.g. if vod_https_header_name was set
to `my-https-header`, the updated config may look like:
```
http {
map $http_my_https_header $protocol {
default "http";
"ON" "https";
}
server {
if ($http_host != "") {
set $base_url "$protocol://$http_host";
}
if ($http_host = "") {
set $base_url ""; # no host header - use relative urls
}
vod_base_url $base_url;
```

The behavior of the following configurations were changed:
* vod_segments_base_url - when this variable is defined and evaluates to a non-empty string,
it is assumed to contain both the scheme and the host name. Before the change, when the
url did not contain a scheme, a defualt scheme was added.

## 2016/03/06 - ad stitching supporting features

The following configuration settings were removed:
Expand Down
28 changes: 14 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -564,7 +564,7 @@ nginx access rules etc.).

In addition, it is possible to configure nginx-vod-module to return the encryption key over HTTPS
while having the segments delivered over HTTP. The way to configure this is to set `vod_segments_base_url`
to `http://nginx-vod-host` and set `vod_https_header_name` to `host`.
to `http://nginx-vod-host` and set `vod_base_url` to `https://nginx-vod-host`.

#### DRM

Expand Down Expand Up @@ -776,26 +776,26 @@ See the list of nginx variables added by this module below.
The bitrate threshold for removing identical bitrates, streams whose bitrate differences are less than
this value will be considered identical.

#### vod_https_header_name
* **syntax**: `vod_https_header_name name`
* **default**: `empty`
#### vod_base_url
* **syntax**: `vod_base_url url`
* **default**: `see below`
* **context**: `http`, `server`, `location`

Sets the name of an HTTP header whose existence determines whether the request was issued over HTTPS.
If not set, the decision is made according to the protocol used to connect to the nginx server.
A common scenario for using this setting is a load-balancer placed before the nginx that performs SSL-offloading.
Sets the base URL (scheme + domain) that should be returned in manifest responses.
The parameter value can contain variables, if the parameter evaluates to an empty string, relative URLs will be used.
If not set, the base URL is determined as follows:
1. If the request did not contain a host header (HTTP/1.0) relative URLs will be returned
2. Otherwise, the base URL will be `$scheme://$host`
The setting currently affects only HLS and DASH. In MSS and HDS, relative URLs are always returned.

#### vod_segments_base_url
* **syntax**: `vod_segments_base_url url`
* **default**: `empty`
* **default**: `see below`
* **context**: `http`, `server`, `location`

Sets the base URL (usually domain only) that should be used for delivering video segments.
When empty, the host header sent on the request will be used as the domain.
The scheme (http/https) used in the returned URLs is determined by:
* the value of vod_segments_base_url, if it starts with http:// or https://
* the existence of a request header whose name matches the value of vod_https_header_name, if vod_https_header_name is not empty
* the type of connection used to connect to the nginx server
Sets the base URL (scheme + domain) that should be used for delivering video segments.
The parameter value can contain variables, if the parameter evaluates to an empty string, relative URLs will be used.
If not set, vod_base_url will be used.
The setting currently affects only HLS.

#### vod_open_file_thread_pool
Expand Down
22 changes: 13 additions & 9 deletions ngx_http_vod_conf.c
Original file line number Diff line number Diff line change
Expand Up @@ -201,12 +201,16 @@ ngx_http_vod_merge_loc_conf(ngx_conf_t *cf, void *parent, void *child)
{
conf->secret_key = prev->secret_key;
}
ngx_conf_merge_str_value(conf->https_header_name, prev->https_header_name, "");
ngx_conf_merge_str_value(conf->segments_base_url, prev->segments_base_url, "");
conf->segments_base_url_has_scheme =
(ngx_strncasecmp(conf->segments_base_url.data, (u_char *) "http://", 7) == 0 ||
ngx_strncasecmp(conf->segments_base_url.data, (u_char *) "https://", 8) == 0);

if (conf->base_url == NULL)
{
conf->base_url = prev->base_url;
}

if (conf->segments_base_url == NULL)
{
conf->segments_base_url = prev->segments_base_url;
}

if (conf->metadata_cache == NULL)
{
Expand Down Expand Up @@ -904,16 +908,16 @@ ngx_command_t ngx_http_vod_commands[] = {
offsetof(ngx_http_vod_loc_conf_t, secret_key),
NULL },

{ ngx_string("vod_https_header_name"),
{ ngx_string("vod_base_url"),
NGX_HTTP_MAIN_CONF | NGX_HTTP_SRV_CONF | NGX_HTTP_LOC_CONF | NGX_CONF_TAKE1,
ngx_conf_set_str_slot,
ngx_http_set_complex_value_slot,
NGX_HTTP_LOC_CONF_OFFSET,
offsetof(ngx_http_vod_loc_conf_t, https_header_name),
offsetof(ngx_http_vod_loc_conf_t, base_url),
NULL },

{ ngx_string("vod_segments_base_url"),
NGX_HTTP_MAIN_CONF | NGX_HTTP_SRV_CONF | NGX_HTTP_LOC_CONF | NGX_CONF_TAKE1,
ngx_conf_set_str_slot,
ngx_http_set_complex_value_slot,
NGX_HTTP_LOC_CONF_OFFSET,
offsetof(ngx_http_vod_loc_conf_t, segments_base_url),
NULL },
Expand Down
5 changes: 2 additions & 3 deletions ngx_http_vod_conf.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,8 @@ struct ngx_http_vod_loc_conf_s {
ngx_str_t multi_uri_suffix;
segmenter_conf_t segmenter;
ngx_http_complex_value_t *secret_key;
ngx_str_t https_header_name;
ngx_str_t segments_base_url;
ngx_flag_t segments_base_url_has_scheme;
ngx_http_complex_value_t *base_url;
ngx_http_complex_value_t *segments_base_url;
ngx_buffer_cache_t* metadata_cache;
ngx_buffer_cache_t* response_cache[CACHE_TYPE_COUNT];
size_t initial_read_size;
Expand Down
6 changes: 5 additions & 1 deletion ngx_http_vod_dash.c
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,11 @@ ngx_http_vod_dash_handle_manifest(
file_uri = submodule_context->r->uri;
}

ngx_http_vod_get_base_url(submodule_context->r, &conf->https_header_name, NULL, 0, &file_uri, &base_url);
rc = ngx_http_vod_get_base_url(submodule_context->r, conf->base_url, &file_uri, &base_url);
if (rc != NGX_OK)
{
return rc;
}
}

if (conf->drm_enabled)
Expand Down
43 changes: 32 additions & 11 deletions ngx_http_vod_hls.c
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,11 @@ ngx_http_vod_hls_handle_master_playlist(

if (submodule_context->conf->hls.absolute_master_urls)
{
ngx_http_vod_get_base_url(submodule_context->r, &submodule_context->conf->https_header_name, NULL, 0, &empty_string, &base_url);
rc = ngx_http_vod_get_base_url(submodule_context->r, submodule_context->conf->base_url, &empty_string, &base_url);
if (rc != NGX_OK)
{
return rc;
}
}

rc = m3u8_builder_build_master_playlist(
Expand Down Expand Up @@ -126,15 +130,28 @@ ngx_http_vod_hls_handle_index_playlist(

if (conf->hls.absolute_index_urls)
{
ngx_http_vod_get_base_url(submodule_context->r, &conf->https_header_name, NULL, 0, &submodule_context->r->uri, &base_url);

ngx_http_vod_get_base_url(
submodule_context->r,
&conf->https_header_name,
&conf->segments_base_url,
conf->segments_base_url_has_scheme,
&submodule_context->r->uri,
&segments_base_url);
rc = ngx_http_vod_get_base_url(submodule_context->r, conf->base_url, &submodule_context->r->uri, &base_url);
if (rc != NGX_OK)
{
return rc;
}

if (conf->segments_base_url != NULL)
{
rc = ngx_http_vod_get_base_url(
submodule_context->r,
conf->segments_base_url,
&submodule_context->r->uri,
&segments_base_url);
if (rc != NGX_OK)
{
return rc;
}
}
else
{
segments_base_url = base_url;
}
}

ngx_http_vod_hls_init_encryption_params(&encryption_params, submodule_context, iv);
Expand Down Expand Up @@ -207,7 +224,11 @@ ngx_http_vod_hls_handle_iframe_playlist(

if (conf->hls.absolute_iframe_urls)
{
ngx_http_vod_get_base_url(submodule_context->r, &conf->https_header_name, NULL, 0, &submodule_context->r->uri, &base_url);
rc = ngx_http_vod_get_base_url(submodule_context->r, conf->base_url, &submodule_context->r->uri, &base_url);
if (rc != NGX_OK)
{
return rc;
}
}

rc = m3u8_builder_build_iframe_playlist(
Expand Down
23 changes: 14 additions & 9 deletions ngx_http_vod_module.c
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,7 @@ ngx_module_t ngx_http_vod_module = {
};

static ngx_str_t options_content_type = ngx_string("text/plain");
static ngx_str_t empty_string = ngx_null_string;

static media_format_t* media_formats[] = {
&mp4_format,
Expand Down Expand Up @@ -4183,6 +4184,7 @@ ngx_http_vod_handler(ngx_http_request_t *r)
ngx_md5_t md5;
ngx_str_t content_type;
ngx_str_t response;
ngx_str_t base_url;
ngx_int_t rc;
int cache_type;

Expand Down Expand Up @@ -4274,24 +4276,27 @@ ngx_http_vod_handler(ngx_http_request_t *r)
// calc request key from host + uri
ngx_md5_init(&md5);

if (r->headers_in.host != NULL)
base_url.len = 0;
rc = ngx_http_vod_get_base_url(r, conf->base_url, &empty_string, &base_url);
if (rc != NGX_OK)
{
ngx_md5_update(&md5, r->headers_in.host->value.data, r->headers_in.host->value.len);
return rc;
}
ngx_md5_update(&md5, base_url.data, base_url.len);

if (conf->https_header_name.len)
if (conf->segments_base_url != NULL)
{
if (ngx_http_vod_header_exists(r, &conf->https_header_name))
{
ngx_md5_update(&md5, "1", sizeof("1") - 1);
}
else
base_url.len = 0;
rc = ngx_http_vod_get_base_url(r, conf->segments_base_url, &empty_string, &base_url);
if (rc != NGX_OK)
{
ngx_md5_update(&md5, "0", sizeof("0") - 1);
return rc;
}
ngx_md5_update(&md5, base_url.data, base_url.len);
}

ngx_md5_update(&md5, r->uri.data, r->uri.len);

ngx_md5_final(request_key, &md5);

// try to fetch from cache
Expand Down
Loading

0 comments on commit 8db1352

Please sign in to comment.