LiteSpeed Technologies
Download Download     Blog Blog     Wiki Wiki     Forum Forum     Store     Contact Contact    

Go Back   LiteSpeed Support Forums > External Applications > Ruby/Rails > 405 Error response when processing POST requests to page cached Rails resources

Reply
 
Thread Tools Display Modes
  #1  
Old 08-15-2008, 08:15 AM
aehso aehso is offline
New Member
 
Join Date: Aug 2008
Posts: 9
Default 405 Error response when processing POST requests to page cached Rails resources

Hi,
I have a rails application that is set up to cache pages for certain URLs for lsws to serve (when they exist) without hitting the rails application. Most of these URLs represent RESTful rails resource (i.e. using map.resource in routes.rb and restful controller implementations). An example resource is a feed url like /v1/feeds/1.app. GET the url and rails generates a cached version.

My problem is that while the resource URL is cached correctly, whenever I try to subsequently POST (create a new resource), PUT (update the resource) or DELETE (delete a resource), lwsw always returns a 405 "Method Not Allowed" response.

I suspect lsws thinks that since the static file exists on disk, it should refuse the request instead of dispatching it to the rails application. Is there any way to stop litespeed from returning the 405?

I have looked at using rewrite to fudge it, and while I can write a condition like
#RewriteCond %{REQUEST_METHOD} ^(POST|DELETE|PUT)$

to detect the incoming request is not a GET, I'm not sure what I can write the subsequent RewriteRule as in order to stop lsws from finding the cached page and instead dispatch to the rails application.

Any suggestions?

John.
Reply With Quote
  #2  
Old 08-15-2008, 12:15 PM
mistwang mistwang is offline
LiteSpeed Staff
 
Join Date: May 2003
Location: New Jersey
Posts: 7,590
Yes, it is a bit tricky.
You can use a rewrite rule at vhost level to work around this like what you thought.

RewriteCond %{REQUEST_METHOD} ^(POST|DELETE|PUT)$
RewriteRule .* /dispatch.lsapi [L]
Reply With Quote
  #3  
Old 08-18-2008, 06:07 AM
aehso aehso is offline
New Member
 
Join Date: Aug 2008
Posts: 9
Quote:
Originally Posted by mistwang View Post
Yes, it is a bit tricky.
You can use a rewrite rule at vhost level to work around this like what you thought.

RewriteCond %{REQUEST_METHOD} ^(POST|DELETE|PUT)$
RewriteRule .* /dispatch.lsapi [L]
Yep, I came up with a similar solution. I was creating an lsapi external app for use by an LSAPI context (using http://www.litespeedtech.com/support...iki:ruby_rails) thinking that might be more flexible and in doing so I ended up adding the following rewrite rules to the vhost rewrite config:

RewriteRule ^/$ /index.html [QSA]
RewriteRule ^/([^.]+)$ /$1.html [QSA]
RewriteCond %{REQUEST_METHOD} ^(POST|DELETE|PUT)$
RewriteRule ^/(.*)$ /dispatch.lsapi [QSA,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^/(.*)$ /dispatch.lsapi [QSA,L]

The second rule sends any POST|DELETE|PUT requests to rails, the last rule makes sure that it will still serve any cached pages (for GETs only)

Then I realised that the lsapi context wasn't necessary as the above rules would dispatch to my original Rails context properly.

All working nicely now!
Reply With Quote
  #4  
Old 08-18-2008, 09:32 AM
mistwang mistwang is offline
LiteSpeed Staff
 
Join Date: May 2003
Location: New Jersey
Posts: 7,590
The rails context implicitly creates the "/dispatch.lsapi" LSAPI context. but you are free to configure everything manually.
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -7. The time now is 09:12 PM.



- Archive - Top
© Copyright 2003-2011 LiteSpeed Technologies, Inc. All rights reserved. Privacy Policy.