To return a binary response from an HTTP server in Ruby, you need to set the response's content type to "application/octet-stream". Then, you can set the response body to the binary data using the "write" method of the response object.
Here's an example code snippet that demonstrates how to do this:
main.rb529 chars26 lines
In this example, the server listens for incoming connections on port 8080 of the localhost. When a request is received, it sends a response with a content type of "application/octet-stream" and a content disposition of "attachment", which tells the browser to treat the response as a file download. Then, it writes the binary data to the response using the "write" method of the client object. Finally, it closes the connection.
gistlibby LogSnag