Internal Redirect w/ Rails

Discussion in 'Ruby/Rails' started by jpeduto, Dec 3, 2007.

  1. jpeduto

    jpeduto Member

    I am trying to serve some files in the most secure fashion using Litespeed's INternal Redirect that I read about here:

    When from my controller I send:

    headers['Location'] = "/path/to/file"

    It doesn't seem to flow through to the web server as I am reading through the logs. Does anyone have any experience with this... or perhaps some ruby code that may show an example of this.

    Thanks in advance!
  2. mistwang

    mistwang LiteSpeed Staff

    It should be "/URL/to/file", not "/path/to/file". Try "X-LiteSpeed-Location"
  3. jpeduto

    jpeduto Member

    Thanks for the reply:

    Please help me verify that I am doing the right thing. The document root of my rails app is of course the public folder. In the public folder I have a folder called products and inside that folder is a file called test.mp3.

    With that information in mind here is the statement I am not using in my controller: headers['X-LiteSpeed-Location'] = "/products/test.mp3"

    Using "X-LiteSpeed-Location" seems to have got me further than just 'Location' did... I am now seeing some information in the log that shows the URL to the file is at least being passed through. But the file is still not coming out on the back end. Here is a snippet from my log in the area of concern.

    Please let me know if everything looks kosher here:

    2007-12-03 13:13:41.063 [DEBUG] [] process packet header 8 bytes
    2007-12-03 13:13:41.063 [DEBUG] [] process response stream 921 bytes, packet left: 921
    2007-12-03 13:13:41.063 [DEBUG] [] response header finished!
    2007-12-03 13:13:41.063 [DEBUG] [] HttpIOLink::continueWrite()...
    2007-12-03 13:13:41.063 [DEBUG] [] write resumed!
    2007-12-03 13:13:41.063 [DEBUG] [] process packet header 0 bytes
    2007-12-03 13:13:41.064 [DEBUG] [] HttpIOLink::handleEvents() events=4!
    2007-12-03 13:13:41.064 [DEBUG] [] HttpIOLink::suspendWrite()...
    2007-12-03 13:13:41.064 [DEBUG] [] redirect to:
    2007-12-03 13:13:41.064 [DEBUG] [] Find context with URI: [/], location: [/u/apps/guifx_store/releases/20071202215503/public/]
    2007-12-03 13:13:41.064 [DEBUG] [] processContextPath() return 0
    2007-12-03 13:13:41.064 [DEBUG] [] HttpExtConnector::cleanUp() ...
    2007-12-03 13:13:41.064 [DEBUG] [] abort request...
    2007-12-03 13:13:41.064 [DEBUG] [] [LSAPI] send abort packet!
    2007-12-03 13:13:41.064 [DEBUG] [] release ExtProcessor!
    2007-12-03 13:13:41.064 [DEBUG] [idle] [ExtConn] close()
    2007-12-03 13:13:41.064 [DEBUG] [uds://tmp/lshttpd/guifx_store:_.sock] add recycled connection to connection pool!

    A few lines after the line where it shows the redirect_to: and the URI being effectively set to /products/text.mp3 it says the request was aborted... is this where my new problem lies?
  4. mistwang

    mistwang LiteSpeed Staff

    It is normal I think, LSWS just abort the Rails request after receiving the redirect in header. Are there more logging entry for after the request aborted.
  5. jpeduto

    jpeduto Member

    In addition to the "X-LiteSpeed-Location" header do I need to send any additional headers as I had stated before the files aren't downloading.. they seem to just be appearing in the window.

    Here is the rest of what was logged on that request:

    2007-12-03 13:13:41.064 [DEBUG] [] readyCacheData() return 0
    2007-12-03 13:13:41.064 [DEBUG] [] Written to client: 327
    2007-12-03 13:13:41.064 [DEBUG] [] Written to client: 10136
    2007-12-03 13:13:41.064 [DEBUG] [] m_pHandler->onWrite() return 1
    2007-12-03 13:13:41.064 [DEBUG] [] HttpIOLink::continueWrite()...
    2007-12-03 13:13:41.064 [DEBUG] [] write resumed!
    2007-12-03 13:13:41.143 [DEBUG] [] HttpIOLink::handleEvents() events=4!
    2007-12-03 13:13:41.143 [DEBUG] [] Written to client: 4344
    2007-12-03 13:13:41.143 [DEBUG] [] m_pHandler->onWrite() return 1
    2007-12-03 13:13:41.219 [DEBUG] [] HttpIOLink::handleEvents() events=4!
    2007-12-03 13:13:41.219 [DEBUG] [] Written to client: 13032
    2007-12-03 13:13:41.219 [DEBUG] [] m_pHandler->onWrite() return 1
    2007-12-03 13:13:41.245 [DEBUG] [] HttpIOLink::handleEvents() events=1!
    2007-12-03 13:13:41.245 [DEBUG] [] HttpIOLink::suspendRead()...
    2007-12-03 13:13:41.267 [DEBUG] [] HttpIOLink::handleEvents() events=24!
    2007-12-03 13:13:41.267 [DEBUG] [] Close socket ...
    2007-12-03 13:13:42.310 [DEBUG] [] Keep-alive timeout, close!
    2007-12-03 13:13:42.311 [DEBUG] [] Shutting down out-bound socket ...
    2007-12-03 13:13:43.383 [DEBUG] [] Shutdown time out!
    2007-12-03 13:13:43.383 [DEBUG] [] Close socket ...
    2007-12-03 13:14:19.011 [DEBUG] [idle] Idle connection timed out, close!
    2007-12-03 13:14:19.011 [DEBUG] [idle] [ExtConn] close()
    2007-12-03 13:19:20.087 [DEBUG] Remove pid: 3136
  6. mistwang

    mistwang LiteSpeed Staff

    You can try the request from command line tool like "lynx -mime_header <url>", or with FireFox module, live-header or firbug. I think the Content-type has not been set properly.

    Maybe the rails app set "content-type" to "text/html", and the Content-Type has not been overridden properly for the new file, you can try set it explicitly in the rails application to match the mime-type for the file.
  7. jpeduto

    jpeduto Member

    Great, thanks so much for the help...

    Is there some type of 'vague' content-type.... I will be serving both .zip files and .exe files to my customers.
  8. mistwang

    mistwang LiteSpeed Staff

    application/octet-stream, better use the dedicate MIME type for that type of file though.
  9. beakid

    beakid Member

    Did you solve your problem? I have a similar problem here

Share This Page