Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add custom HTTP header field to AVPlayer requests for HLS

We are using AVPlayer to play an HLS stream, but we have a new requirement that we need to supply a custom HTTP header field to identify the client from the backend team. Is it possible to add custom HTTP header field to AVPlayer requests without resorting to hacking HLS playlist file to use a custom protocol?

like image 810
Frank Avatar asked Aug 01 '14 19:08

Frank


People also ask

How do you add a custom header in HTTP request?

In the Home pane, double-click HTTP Response Headers. In the HTTP Response Headers pane, click Add... in the Actions pane. In the Add Custom HTTP Response Header dialog box, set the name and value for your custom header, and then click OK.

Can I create my own HTTP header?

Yes, you can. But, why would you want to? The HTTP protocol allows you to set your own custom headers. However, it would also mean that your server would need o understand your custom headers.

How do I set up HTTP headers?

In the web site pane, double-click HTTP Response Headers in the IIS section. In the actions pane, select Add. In the Name box, type the custom HTTP header name. In the Value box, type the custom HTTP header value.

What is HTTP request custom header?

Custom HTTP headers can be used to filter requests or specify a value for the Accept header. Some endpoints employ custom HTTP headers to filter data returned by a GET or POST request.


1 Answers

I found this answer somewhere from the web. I am using it in my test app, but since this is an undocumented feature, there is a risk that apple may reject. But technically, this is an option.

NSMutableDictionary* headers = [NSMutableDictionary dictionary];
[headers setObject:@"SOF" forKey:@"X-REQ-HEADER-TEST"];

AVURLAsset* asset = [AVURLAsset URLAssetWithURL:myUrl options:@{@"AVURLAssetHTTPHeaderFieldsKey": headers}];
AVPlayerItem* item = [AVPlayerItem playerItemWithAsset:asset]; 
[avPlayerObj replaceCurrentItemWithPlayerItem:item];

Usage of AVURLAssetHTTPHeaderFieldsKey is the one in question.

like image 128
Dvyz Avatar answered Nov 15 '22 07:11

Dvyz