PHP Proxy: Pass Thru HTTP Response Headers from HLS Streaming Server - php

I'm trying to proxy calls to an HTTP Live Streaming Server (lighttpd) through a PHP proxy. However, it does not appear that the headers being returned from the streaming server are being passed back to the client. Because of this, the video content isn't actually being streamed back to the client when going through my proxy (it's as if the client is still waiting for the entire file to be sent).
Anyone have any ideas on how to do this? Are there any open source PHP Proxies that can handle proxying streaming content?
Thanks!

Related

PHP proxy for videos - not working on some Apple devices

The problem i'm facing is this:
I have a video on remote server that is loaded on my website
some users cannot access video because remote server URL is blocked
I create a proxy in PHP that is loading data from remote server with file_get_contents(), I'm getting headers from remote server and returning for the user response with same headers and content as a remote server.
Everything is working well on all devices except some Apple devices. It shows empty player with message Failed to Load Resource, Plugin Handled Load.
I spend a lot of time on looking for solution, was trying to handle even HTTP range requests with no success. I mange to reproduce error with postman using Safari headers and I manage to handle HTTP range request and video was working on Postman, but not in Safari. The only thing that may solve the issue is downloading file to my server and use the path to file to let nginx serve the file, but it means that I should have some cronjob that will remove file after usage.
So I hope that someone can give me ideas how to "fake" nginx response using PHP, just using headers and regular or streamed response is not enough.

How would I pass data from a POST request?

I have been building an HTTP Server (in the C programming language), and I'm wondering what would handle a POST request sent by a client. That is, if a client sends me a POST request to a PHP page, then how would I pass the data sent by the client to the PHP page?
Feel free to ask for clarification.
Something needs to parse, compile and execute the PHP page. You're not about to write your own, so your server will need to act as a proxy for the request.
Solution 1: Setup a FastCGI PHP daemon. Your web server can then forward the request to PHP using the FastCGI protocol.
Solution 2: Setup a web server capable of handling PHP requests. Your web server can then (indirectly) forward the request to PHP using HTTP or HTTPS. This is less work for you, but it begs the question why you're not just using that web server throughout.

Downloading a file from resource server to browser (OAuth2)

I'm implementing OAuth2 (100% spec compliant) in a project that I've been assigned to.
Let's say I have a file named 'file.txt' on the resource server.
The client wants to download the file. Suppose file downloads are done through another server, dl.example.com , because there may be multiple resource servers, and a common access point for downloads will be a neater approach. (?)
So if the client wants to download a file, and output it to the browser, what should be the preferred process?
If I take the following approach :
1) Client makes request to dl.example.com?access_token=123123&fpath=file.txt
2) dl.example.com makes request to the respective resource server
3) The resource server sends the file to dl.example.com
4) dl.example.com sends the file to the client
5) client outputs the file to the browser for download
there will be additional network I/O overhead.
Is this approach not the right way to go? How to 'big players' like Dropbox do it? I have checked Dropbox's url : dl-web.dropbox.com/*whatever* . Is Dropbox's approach totally different than the above one?
I would not proxy the passing of the file resource via the dl.example.com server.
The access_token is the key here. If the resource servers support OAuth2 themselves and have access to the store for the access_tokens you could respond with a status 303 redirect from the original request to the actual resource address in need:
Original Request: https://dl.example.com?access_token=123123&fpath=file.txt
Response: 303 https://resource.server.com/path/file.txt?access_token=123123
You can flag Curl to follow redirects. If you're developing an Client SDK to wrap access, this could all be invisible.

Passthru Soap Request (i.e.. act as proxy for Soap Request)

I am working on a project for a client, that they have several applications that communicate with a soap server, however they require all requests to go thru a proxy, and want to be able to answer several of the soap requests locally, then if it requires the outside server send the request from the inside php server basically like a proxy. So the only communication the Software has is with the rerouted internal php server.
The setup is as follows:
1. Application makes call to 255.255.255.255
2. Internal Routing redirects request to 192.168.1.2 (Internal Web Server)
3. Internal Web server serves requests for the requested page
3a. If the Method requested can be answered local it needs to answer it,
3b. Or it needs to forward the whole original request to the outside server, wait for response then return the answer back to the Software as if it was serving the answer.
Does that make sense, and does anyone have any suggestions for how to accomplish this in a php page? The network routing is already done, and the Software is being answered by the internal php page, however I cannot get it to forward the request.
The determination of 3a is outside the scope, but an important part in deciding what implementation to use; for each transport protocol you need to implement a request rewrite. If there's only the HTTP transport, you can either use fopen with URL wrappers, which isn't very flexible in terms of specifying headers or use the cURL extension. Once you've got the response from the external server, simply write out the data.

HTTP request safe?

I am sending http request to my server using ASIHTTPRequest library but I don't know if it obfuscates the request data. Also on the sever side, I am creating an XML file and response back to the device using php. What is the safe way to form an XML document and send back to the device?
The only safe way to connect to a webserver is by using SSL/https.
I would recommend SSL and/or XML Signatures
Anything sent over just http is sent in clear text. Anyone can see your traffic on any part of the route from you to the destination. This is why facebook/twitter and a number of sites have switched to an https preferred model.

Categories