rstudio / httpuv

HTTP and WebSocket server package for R
Other
227 stars 86 forks source link

returning binary files from the 1.5.0 WebServer? #216

Closed paul-shannon closed 5 years ago

paul-shannon commented 5 years ago

My Bioconductor package igvR, built on BrowserViz - recently updated to use httpuv 1.5.0 - needs to return a binary file to igv.js running in the browser. In the current case, this a genomic BAM (binary alignment map) file.

The httpuv WebServer nicely supports returning other genomic text files used by igv: bed, vcf, bedGraph. Can it return a binary file over http also?

FWIW, BrowserViz detects and responds to file requests using a technique I developed (probably borrowed from example code) with httpuv 1.3.x. Maybe it is antiquated, needs updating, and in updating I'd get binary file support? Here's how I currently do it:

   wsCon$call = function(req) {
      qs <- req$QUERY_STRING
      if(nchar(qs) > 0){
         queryProcessorFunction <- BrowserViz.state[["httpQueryProcessingFunction"]]
         if(!is.null(queryProcessorFunction))
           body <- queryProcessorFunction(qs)
         else
           body <- "no query processor registered"
         return(list(status=200L, headers = list('Content-Type' = 'text/html'),
                     body=body))
         } # the request had a query string

Advice eagerly accepted!

jcheng5 commented 5 years ago

You should just be able to use a raw vector in place of the string, for the body. Here's the relevant section of the Rook spec: https://github.com/jeffreyhorner/Rook/blob/master/README.md#the-body

paul-shannon commented 5 years ago

Thanks for the pointer @jcheng5. I'll get a better understanding of Rook.

wch commented 5 years ago

I think you also need to use a different Content-Type:

   headers = list('Content-Type' = 'application/octet-stream')
paul-shannon commented 5 years ago

Seems obvious now that you pointed that out! Thank you.

On Apr 10, 2019, at 9:12 AM, Winston Chang notifications@github.com wrote:

I think you also need to use a different Content-Type:

headers = list('Content-Type' = 'application/octet-stream')

— You are receiving this because you modified the open/close state. Reply to this email directly, view it on GitHub, or mute the thread.