views:

43

answers:

2

I need to serve a file on localhost to a certain application which only accepts http URI-s. However, the files are generated on the fly and I would like to avoid writing to disk, so I decided to write a simple HTTP server using QTcpServer. Luckily, I even found a nice tutorial explaining just that. However, I'm not familiar with HTTP responses. How do I serve a flash file? Is there a particular MIME type for that? And after putting the header together, do I just dump the stream to the socket and that's all?

+1  A: 

This doesn't answer your complete question but you can look for MIME type here:

http://www.w3schools.com/media/media_mimeref.asp

SWF is application/x-shockwave-flash

dierre
+2  A: 

The mime type you are looking for is: application/x-shockwave-flash

What you need to set is

  1. Set the content type to application/x-shockwave-flash
  2. Set the content length to the total size of the swf to serve
  3. Set the header with content disposition like: Content-Disposition=attachment;filename=SWFToServe.swf
  4. Start writing out all the bytes of the swf file.
  5. Flush the response

And that's all, the client should start downloading it...

Garis Suero