Forum OpenACS Q&A: Using AOLserver as a proxy server

Collapse
Posted by Dan Mascenik on
I'm looking for a way to make AOLserver proxy requests for certain binary files to another server behind a firewall.  _ns_http_read doesn't seem to handle binary data very well, and I would also rather not store data in a buffer before returning it the way util_httpget does.

Has anyone had any luck just piping the data stream (mime type and all) from an HTTP GET straight to the connection?

Collapse
Posted by Tom Jackson on

You can take a look at tclvhr for examples. The only problem I have encountered with this proxy is that you get error messages in your log if a user interrupts a download. In other words, this proxy doesn't do any checking if the client is still connected. Otherwise it works pretty fast. You could probably use ns_cache or something similar fairly easily.

Collapse
Posted by Dan Mascenik on
ns_writefp was the command I was looking for. This does exactly what I wanted in that it streams data from some foreign server to the connection:
set conn [ns_httpopen GET $some_arbitrary_URL {} 30]
set read_desc [lindex $conn 0]
set write_desc [lindex $conn 1]
set headers [lindex $conn 2]

set mime_type [ns_set get $headers content-type]

set head "HTTP/1.0 200 OK
MIME-Version: 1.0
Content-Type: $mime_type\r\n\r\n"
# Plus any more headers you need.

ns_write $head
ns_startcontent -type $mime_type    
ns_writefp $read_desc

Thanks again, Tom!