AirenSoft / OvenMediaEngine

OvenMediaEngine (OME) is a Sub-Second Latency Live Streaming Server with Large-Scale and High-Definition. #WebRTC #LLHLS
https://OvenMediaEngine.com/ome
GNU Affero General Public License v3.0
2.48k stars 1.05k forks source link

how to set http headers #431

Closed internetxs closed 3 years ago

internetxs commented 3 years ago

How can i set the caching and http headers?

getroot commented 3 years ago

I can't understand this question. Could you please explain in more detail?

basisbit commented 3 years ago

I'd suggest using Nginx or Apache as reverse HTTP proxy to handle TLS encryption and adding headers as desired. Alternatively, you could add the desired http headers here and then recompile OME: https://github.com/AirenSoft/OvenMediaEngine/blob/master/src/projects/publishers/segment/segment_stream/segment_stream_server.cpp#L240

I wonder what http headers for caching you want to set. I'd guess only disabling caching or limiting it to a very short time?

internetxs commented 3 years ago

ideally when using caching the manifest should be able to be cached for 2 seconds and then expire. For example when using HLS the caching on the TS files could be set to 300 seconds for example then if your able to use a cdn on front it allows you to serve cached content to your watchers

In the playlist.m3u8 Access-Control-Allow-Origin: * Cache-Control: no-cache, no-store, must-revalidate Content-Length: 151 Content-Type: application/vnd.apple.mpegurl Expires: 0 Pragma: no-cache Server: OvenMediaEngine

In the ts file: Access-Control-Allow-Origin: * Content-Length: 1211660 Content-Type: video/MP2T Server: OvenMediaEngine

and same applies for dash

basisbit commented 3 years ago

Caching ts files for more than maybe 15 seconds on CDN or client would either require a different .ts file naming scheme (so the same path + file name will not be reused for different content), or it would break stopping and then restarting live-streaming.

internetxs commented 3 years ago

Caching ts files for more than maybe 15 seconds on CDN or client would either require a different .ts file naming scheme (so the same path + file name will not be reused for different content), or it would break stopping and then restarting live-streaming.

In the meantime i found which files to edit. currently compiling to see the results

internetxs commented 3 years ago

issue can be closed found the issue and added the headers manually

basisbit commented 3 years ago

Could you maybe document your changes or maybe even do a pull request?

internetxs commented 3 years ago

Hi the changes that i made:

Under hls_stream_server.cpp from line 63

    // Set HTTP header
    response->SetHeader("Content-Type", "application/vnd.apple.mpegurl");

// response->SetHeader("Cache-Control", "no-cache, no-store, must-revalidate"); response->SetHeader("Cache-Control", "max-age=2"); // response->SetHeader("Pragma", "no-cache"); // response->SetHeader("Expires", "0");

From line 105

// Set HTTP header response->SetHeader("Cache-Control", "max-age=300"); response->SetHeader("Content-Type", "video/MP2T"); response->AppendData(segment->data); auto sent_bytes = response->Response();

getroot commented 3 years ago

@internetxs I will add a task to our backlog that allows the user to control this in the config file. Thanks for sharing the information.

internetxs commented 2 years ago

Caching ts files for more than maybe 15 seconds on CDN or client would either require a different .ts file naming scheme (so the same path + file name will not be reused for different content), or it would break stopping and then restarting live-streaming.

it would be an good idea to have the naming in epoch timeformat then it's always unique

bchah commented 4 months ago

I will add a task to our backlog that allows the user to control this in the config file. Thanks for sharing the information.

Hi @getroot did this ever become an option? I am troubleshooting for a customer whose endpoint cannot read the "application/vnd.apple.mpegurl" content-type.