-1

Let's say I use Apache, and that I am in /var/www/html/. I do:

mkfifo test.tar tar cvf - ~/test/* > test.tar & 

In a browser, when trying to download http://localhost/test.tar I get:

ERR_EMPTY_RESPONSE (didn’t send any data) 

Is there a specific parameter of mkfifo that would the pipe look really like a regular file? Here the problems seems to come from the fact the file is a named pipe.

In my real example, I might use different webservers (not Apache), like CivetWeb, but first I want to analyze if it works with Apache (that I use the most).

7
  • 3
    This is almost exactly what CGI was invented for, all those years ago. A url triggers invocation of a program on the server, and the output of the program streams data to the browser. There's some extra HTML the program needs to output, so the browser knows that it's receiving a stream and what format the data is in. Commented Jul 13 at 21:19
  • @SottoVoce Yes that's right, good old CGI! :) Alternatively, do you think it is possible to make Apache serve the download of a "file" (which is in fact a mkfifo-ed named pipe file under the hood), without having this ERR_EMPTY_RESPONSE? Commented Jul 14 at 9:59
  • A .tar (Tape ARchive) file is structured, that is, if you miss the beginning, or, in fact, any bytes from the datastreams, the end checksum won't match, and you'll have junk that you can't unTAR. Commented Jul 15 at 21:43
  • 2
    @waltinator, how would you miss bytes from the beginning? Commented Jul 15 at 21:58
  • Following on from other responses, the correct solution here is to write a small piece of code there's executed when you hit the specified URL. The code can read from your named pipe, or even run the code on the other end of the pipe directly. As others have suggested, look up web server cgi Commented Jul 15 at 22:43

1 Answer 1

3
+50

You could offer tar not via a FIFO, but stream the process directly - e.g. with a small CGI script or FastCGI.

#!/bin/bash echo "Content-Type: application/x-tar" echo tar cf - ~/test/ 

Apache must have CGI activated. Then place the script under /usr/lib/cgi-bin/tarstream.cgi e.g., and call it up in the browser:

http://localhost/cgi-bin/tarstream.cgi 

tar stream is pushed directly to the browser. No FIFO necessary. No temporary file. Should works immediately. It works like this in my head...

Most web servers cannot handle fifos as if they were ‘real’ files. For example, they check Metadata such as size, or whether the file can be opened/read regularly. Or they try MIME type recog ... A fifo is more or less the opposite of what a web server expects.

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.