xml_http_request?() method always return FALSE. It turns out that request.env[''HTTP_X_REQUESTED_WITH''] is nil no matter what. I found this is due to header "X-Requested-With" was filtered by mod_scgi. I tested on Apache2 + mod_scgi 1.7. I added following one line in apache2/mod_scgi.c at line 325: add_header(t, "HTTP_X_REQUESTED_WITH", lookup_header(r, "X-Requested-With")); Run "apxs -i -c mod_scgi.c" again and it works for me now. This is just a quick hack without much thought, not clear how fcgi does on this. I''m copying Neil (author of mod_scgi) hope this can be fixed in the next release. Hope this can help anyone that is caught by this too. Kevin
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 On Oct 6, 2005, at 9:38 PM, K C wrote:> xml_http_request?() method always return FALSE. It turns out that > request.env[''HTTP_X_REQUESTED_WITH''] is nil no matter what. I found > this is due to header "X-Requested-With" was filtered by mod_scgi. I > tested on Apache2 + mod_scgi 1.7. > > I added following one line in apache2/mod_scgi.c at line 325: > > add_header(t, "HTTP_X_REQUESTED_WITH", lookup_header(r, "X- > Requested-With")); > > Run "apxs -i -c mod_scgi.c" again and it works for me now. This is > just a quick hack without much thought, not clear how fcgi does on > this. I''m copying Neil (author of mod_scgi) hope this can be fixed in > the next release. > > Hope this can help anyone that is caught by this too.Nice workaround, Kevin. However, this is the expected behavior for mod_scgi. See the thread on this topic from last week: http://thread.gmane.org/gmane.comp.lang.ruby.rails/23754 Best, jeremy -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.2 (Darwin) iD8DBQFDRhBUAQHALep9HFYRArmDAJ9uC9bsgvck/gaOmR7ambQj/WaFFACg3t8o SExVtfOic8mSMKRp1M4cUWM=y+Vc -----END PGP SIGNATURE-----
Ah, I did read that thread but totally forgot, or say I didn''t understand it at that time that can''t recall. Hopefully Zed can work around it in SRR so I can drop my hack. Anyway it''s not bad to have a customized mod_scgi, that''s the beauty of Opensource, isn''t it? Cheers On 10/6/05, Jeremy Kemper <jeremy-w7CzD/W5Ocjk1uMJSBkQmQ@public.gmane.org> wrote:> -----BEGIN PGP SIGNED MESSAGE----- > Hash: SHA1 > > On Oct 6, 2005, at 9:38 PM, K C wrote: > > xml_http_request?() method always return FALSE. It turns out that > > request.env[''HTTP_X_REQUESTED_WITH''] is nil no matter what. I found > > this is due to header "X-Requested-With" was filtered by mod_scgi. I > > tested on Apache2 + mod_scgi 1.7. > > > > I added following one line in apache2/mod_scgi.c at line 325: > > > > add_header(t, "HTTP_X_REQUESTED_WITH", lookup_header(r, "X- > > Requested-With")); > > > > Run "apxs -i -c mod_scgi.c" again and it works for me now. This is > > just a quick hack without much thought, not clear how fcgi does on > > this. I''m copying Neil (author of mod_scgi) hope this can be fixed in > > the next release. > > > > Hope this can help anyone that is caught by this too. > > Nice workaround, Kevin. However, this is the expected behavior for > mod_scgi. > See the thread on this topic from last week: > http://thread.gmane.org/gmane.comp.lang.ruby.rails/23754 > > Best, > jeremy > -----BEGIN PGP SIGNATURE----- > Version: GnuPG v1.4.2 (Darwin) > > iD8DBQFDRhBUAQHALep9HFYRArmDAJ9uC9bsgvck/gaOmR7ambQj/WaFFACg3t8o > SExVtfOic8mSMKRp1M4cUWM> =y+Vc > -----END PGP SIGNATURE----- >
Actually Jeremy, I hate to say it but you''re wrong and Kevin is right on this one. You said in that last thread that there needed to be several gsub calls to fix up CGI parameters that should already be in CGI form. I thought this was weird, so I tested it. Here''s the parameters I get from lighttpd: REQUEST_URI = /testme/say_hello REDIRECT_URI = /dispatch.scgi QUERY_STRING REQUEST_METHOD = POST REDIRECT_STATUS = 200 SERVER_PROTOCOL = HTTP/1.1 HTTP_HOST = localhost:8000 HTTP_USER_AGENT = Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.7.12) Gecko/20050921 Firefox/1.0.7 HTTP_ACCEPT text/xml,application/xml,application/xhtml +xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5 HTTP_ACCEPT_LANGUAGE = en-us,en;q=0.5 HTTP_ACCEPT_ENCODING = gzip,deflate HTTP_ACCEPT_CHARSET = ISO-8859-1,utf-8;q=0.7,*;q=0.7 HTTP_KEEP_ALIVE = 300 HTTP_CONNECTION = close HTTP_X_REQUESTED_WITH = XMLHttpRequest HTTP_X_PROTOTYPE_VERSION = 1.3.1 CONTENT_TYPE = application/x-www-form-urlencoded HTTP_CONTENT_LENGTH = 0 HTTP_COOKIE = _session_id=018ba27c380b93140128d57e1700bfd6 HTTP_PRAGMA = no-cache HTTP_CACHE_CONTROL = no-cache This is off an Ajax link_to_remote call. Notice that none of the parameters need the gsub, that the HTTP_X_REQUESTED_WITH is there, and that everything else looks the way it should. What you were confusing is in regular CGI you need to process the ENV to set things up for CGI processing. In SCGI you don''t do this as the parameters are already put in the proper CGI form when the request is received. So, since this all works great and correctly under lighttpd, the question is why does Apache not work? Let''s look at what apache sends: CONTENT_LENGTH = 0 SCGI = 1 SERVER_SOFTWARE = Apache SERVER_PROTOCOL = HTTP/1.1 SERVER_NAME = localhost SERVER_ADMIN = you-yFB3ml5VAxWDnTpkrL3ZLw@public.gmane.org SERVER_ADDR = 127.0.0.1 SERVER_PORT = 80 REMOTE_ADDR = 127.0.0.1 REMOTE_PORT = 56121 REQUEST_METHOD = POST REQUEST_URI = /testme/say_hello QUERY_STRING SCRIPT_NAME = /testme/say_hello SCRIPT_NAME PATH_INFO = /testme/say_hello CONTENT_TYPE = application/x-www-form-urlencoded DOCUMENT_ROOT = /home/httpd/html HTTP_ACCEPT = text/xml,application/xml,application/xhtml +xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5 HTTP_ACCEPT_CHARSET = ISO-8859-1,utf-8;q=0.7,*;q=0.7 HTTP_ACCEPT_ENCODING = gzip,deflate HTTP_ACCEPT_LANGUAGE = en-us,en;q=0.5 HTTP_COOKIE = _session_id=018ba27c380b93140128d57e1700bfd6 HTTP_HOST = localhost HTTP_USER_AGENT = Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.7.12) Gecko/20050921 Firefox/1.0.7 And, here you see Apache is also properly HTTP_ encoding all parameters without requiring any modification, BUT that Apache is not passing in the HTTP_X_REQUESTED_WITH parameter like it should. This means that it''s a bug in Apache''s mod_scgi which Kevin just found and fixed. In other words Jeremy, even if SRR was processing the CGI parameters wrong (which it isn''t), it couldn''t possibly be the culprit on this since Apache isn''t even passing the HTTP_X_REQUESTED_WITH header. How would SRR possibly fix that? Invent it out of thin air? Zed A. Shaw On Thu, 6 Oct 2005 23:06:09 -0700 Jeremy Kemper <jeremy-w7CzD/W5Ocjk1uMJSBkQmQ@public.gmane.org> wrote:> Nice workaround, Kevin. However, this is the expected behavior for > mod_scgi. > See the thread on this topic from last week: > http://thread.gmane.org/gmane.comp.lang.ruby.rails/23754
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 On Oct 7, 2005, at 10:01 AM, Zed A. Shaw wrote:> Actually Jeremy, I hate to say it but you''re wrong and Kevin is right > on this one. You said in that last thread that there needed to be > several gsub calls to fix up CGI parameters that should already be in > CGI form. I thought this was weird, so I tested it. Here''s the > parameters I get from lighttpd:Yes, based on what you said about SCGI passing headers directly. It is sensible that it closely emulates CGI instead.> What you were confusing is in regular CGI you need to process the ENV > to set things up for CGI processing. In SCGI you don''t do this as the > parameters are already put in the proper CGI form when the request is > received.CGI expects some standard environment variables. It does no processing.> And, here you see Apache is also properly HTTP_ encoding all > parameters > without requiring any modification, BUT that Apache is not passing in > the HTTP_X_REQUESTED_WITH parameter like it should. This means that > it''s a bug in Apache''s mod_scgi which Kevin just found and fixed.That''s good news.> In other words Jeremy, even if SRR was processing the CGI parameters > wrong (which it isn''t), it couldn''t possibly be the culprit on this > since Apache isn''t even passing the HTTP_X_REQUESTED_WITH header. How > would SRR possibly fix that? Invent it out of thin air?I''m glad you were able to clear it up. Regards, jeremy -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.2 (Darwin) iD8DBQFDRsEsAQHALep9HFYRAv/rAKC3+p1S0X6mI8HplMcHXC1kVrM63ACfTqqM 6JTIAMKD7tmPz25+Ygt/mLE=l1FY -----END PGP SIGNATURE-----
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 - -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 On Oct 7, 2005, at 10:01 AM, Zed A. Shaw wrote:> Actually Jeremy, I hate to say it but you''re wrong and Kevin is right > on this one. You said in that last thread that there needed to be > several gsub calls to fix up CGI parameters that should already be in > CGI form. I thought this was weird, so I tested it. Here''s the > parameters I get from lighttpd: >Yes, based on what you said about SCGI passing headers directly. It is sensible that it closely emulates CGI instead.> What you were confusing is in regular CGI you need to process the ENV > to set things up for CGI processing. In SCGI you don''t do this as the > parameters are already put in the proper CGI form when the request is > received. >CGI expects some standard environment variables. It does no processing.> And, here you see Apache is also properly HTTP_ encoding all > parameters > without requiring any modification, BUT that Apache is not passing in > the HTTP_X_REQUESTED_WITH parameter like it should. This means that > it''s a bug in Apache''s mod_scgi which Kevin just found and fixed. >That''s good news.> In other words Jeremy, even if SRR was processing the CGI parameters > wrong (which it isn''t), it couldn''t possibly be the culprit on this > since Apache isn''t even passing the HTTP_X_REQUESTED_WITH header. How > would SRR possibly fix that? Invent it out of thin air? >I''m glad you were able to clear it up. Regards, jeremy - -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.2 (Darwin) iD8DBQFDRsEsAQHALep9HFYRAv/rAKC3+p1S0X6mI8HplMcHXC1kVrM63ACfTqqM 6JTIAMKD7tmPz25+Ygt/mLE=l1FY - -----END PGP SIGNATURE----- -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.2 (Darwin) iD8DBQFDRsV3AQHALep9HFYRAivaAJ91ZneUGcfY1qFuMXaOb6sRRwPYJQCg0c1A Uanlxv9X4q0eB+pstIpsDEk=yEdh -----END PGP SIGNATURE-----
On Fri, Oct 07, 2005 at 12:00:53AM -0700, K C wrote:> Ah, I did read that thread but totally forgot, or say I didn''t > understand it at that time that can''t recall. Hopefully Zed can work > around it in SRR so I can drop my hack. Anyway it''s not bad to have a > customized mod_scgi, that''s the beauty of Opensource, isn''t it?I implemented a better fix. All HTTP headers are now passed to SCGI servers. You can grab the latest modules here (also a Darcs repository): http://arctrix.com/nas/scgi/src/ BTW, I''m happy to see that some Ruby people have discovered mod_scgi. Cheers, Neil
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 On Oct 10, 2005, at 9:10 AM, Neil Schemenauer wrote:> On Fri, Oct 07, 2005 at 12:00:53AM -0700, K C wrote: >> Ah, I did read that thread but totally forgot, or say I didn''t >> understand it at that time that can''t recall. Hopefully Zed can work >> around it in SRR so I can drop my hack. Anyway it''s not bad to >> have a >> customized mod_scgi, that''s the beauty of Opensource, isn''t it? > > I implemented a better fix. All HTTP headers are now passed to SCGI > servers. You can grab the latest modules here (also a Darcs > repository): > > http://arctrix.com/nas/scgi/src/ > > BTW, I''m happy to see that some Ruby people have discovered > mod_scgi. Cheers,Awesome; thanks Neil. jeremy -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.2 (Darwin) iD8DBQFDSpggAQHALep9HFYRAuoyAKCtXxmRdymBRJWBwhglSqyd9zqhnwCcCEKC 0hV5ngckejAbx9LoVpdV/jU=lwN+ -----END PGP SIGNATURE-----
It works, thanks Neil. Kevin On 10/10/05, Neil Schemenauer <nas-hBfk5MI2mhdBDgjK7y7TUQ@public.gmane.org> wrote:> On Fri, Oct 07, 2005 at 12:00:53AM -0700, K C wrote: > > Ah, I did read that thread but totally forgot, or say I didn''t > > understand it at that time that can''t recall. Hopefully Zed can work > > around it in SRR so I can drop my hack. Anyway it''s not bad to have a > > customized mod_scgi, that''s the beauty of Opensource, isn''t it? > > I implemented a better fix. All HTTP headers are now passed to SCGI > servers. You can grab the latest modules here (also a Darcs > repository): > > http://arctrix.com/nas/scgi/src/ > > BTW, I''m happy to see that some Ruby people have discovered > mod_scgi. Cheers, > > Neil >