https://github.com/StyleShare/HLSCachingReverseProxyServer
A simple local reverse proxy server for HLS segment cache
https://github.com/StyleShare/HLSCachingReverseProxyServer
cache hls ios reverse-proxy-server segment
Last synced: 12 months ago
JSON representation
A simple local reverse proxy server for HLS segment cache
- Host: GitHub
- URL: https://github.com/StyleShare/HLSCachingReverseProxyServer
- Owner: StyleShare
- License: mit
- Created: 2019-11-18T18:22:36.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2021-03-29T09:40:37.000Z (almost 5 years ago)
- Last Synced: 2024-11-05T14:52:23.552Z (over 1 year ago)
- Topics: cache, hls, ios, reverse-proxy-server, segment
- Language: Swift
- Homepage:
- Size: 12.7 KB
- Stars: 150
- Watchers: 9
- Forks: 29
- Open Issues: 9
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-video - StyleShare/HLSCachingReverseProxyServer - A simple local reverse proxy server for HLS segment cache - StyleShare/HLSCachingReverseProxyServer (Video Streaming & Distribution Solutions / Edge Computing & Caching Solutions)
README
# HLSCachingReverseProxyServer

[](https://cocoapods.org/pods/HLSCachingReverseProxyServer)
[](https://github.com/StyleShare/HLSCachingReverseProxyServer/actions)
[](https://codecov.io/gh/StyleShare/HLSCachingReverseProxyServer)
A simple local reverse proxy server for HLS segment cache.
## How it works

1. **User** sets a reverse proxy url to the `AVPlayer` instead of the origin url.
```diff
- https://example.com/vod.m3u8
+ http://127.0.0.1:8080/vod.m3u8?__hls_origin_url=https://example.com/vod.m3u8
```
2. **AVPlayer** requests a playlist(`.m3u8`) to the local reverse proxy server.
3. **Reverse proxy server** fetches the origin playlist and replaces all URIs to point the localhost.
```diff
#EXTM3U
#EXTINF:12.000,
- vod_00001.ts
+ http://127.0.0.1:8080/vod.m3u8?__hls_origin_url=https://example.com/vod_00001.ts
#EXTINF:12.000,
- vod_00002.ts
+ http://127.0.0.1:8080/vod.m3u8?__hls_origin_url=https://example.com/vod_00002.ts
#EXTINF:12.000,
- vod_00003.ts
+ http://127.0.0.1:8080/vod.m3u8?__hls_origin_url=https://example.com/vod_00003.ts
```
4. **AVPlayer** requests segments(`.ts`) to the local reverse proxy server.
5. **Reverse proxy server** fetches the origin segment and caches it. Next time the server will return the cached data for the same segment.
## Usage
```swift
let server = HLSCachingReverseProxyServer()
server.start(port: 8080)
let playlistURL = URL(string: "http://devstreaming.apple.com/videos/wwdc/2016/102w0bsn0ge83qfv7za/102/0640/0640.m3u8")!
let reverseProxyURL = server.reverseProxyURL(from: playlistURL)!
let playerItem = AVPlayerItem(url: reverseProxyURL)
self.player.replaceCurrentItem(with: playerItem)
```
## Dependencies
* [GCDWebServer](https://github.com/swisspol/GCDWebServer)
* [PINCache](https://github.com/pinterest/PINCache)
## Installation
Use CocoaPods with **Podfile**:
```ruby
pod 'HLSCachingReverseProxyServer'
```
## Development
```console
$ make project
$ open HLSCachingReverseProxyServer.xcworkspace
```
## License
HLSCachingReverseProxyServer is under MIT license. See the [LICENSE](LICENSE) for more info.