LiTiang / js-test-driver

Automatically exported from code.google.com/p/js-test-driver
0 stars 0 forks source link

proxy sometimes responses 412 (precondition failed) #233

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. run server with proxy
2. do couple of requests to proxied urls

What is the expected output? What do you see instead?
Proper response :-D

Please use labels and text to provide additional information.
It responses with 412 (precondition failed).
Not always. When running about 120 tests (roughly 150 proxied requests), 
usually about 20 - 30 errors.
Problematic requests are not all the name urls.

When clearing the cache no problem (one run after clearing cache).

Tested in Chrome, Firefox.

After discussion with Cory - this is Jetty related issue.

Original issue reported on code.google.com by vojta.jina on 21 Apr 2011 at 4:46

GoogleCodeExporter commented 9 years ago
Actually, the 412 precondition failed is response from the server that jstd 
(jetty) proxies to...

The problem is, that sometimes, jstd (jetty) changes GET method into POST!

Original comment by vojta.jina on 24 Apr 2011 at 8:24

GoogleCodeExporter commented 9 years ago
Here's an example request that Jetty 6's ProxyServlet.Transparent changes from 
GET to POST, and the reason is the value of the Content-Type header:

Apr 28, 2011 8:32:35 PM 
com.google.jstestdriver.requesthandlers.RequestDispatcher dispatch
FINEST: proxying /angular.validator.html GET /angular.validator.html HTTP/1.1
Host: localhost:9876
Connection: keep-alive
Referer: http://localhost:9876/index.html
User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/534.24 (KHTML, like 
Gecko) Chrome/11.0.696.57 Safari/534.24
Accept: application/json, text/plain, */*
Accept-Encoding: gzip,deflate,sdch
Accept-Language: en-US,en;q=0.8
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.3
X-Requested-With: XMLHttpRequest
*********Content-Type: application/x-www-form-urlencoded**********

Original comment by robertsd...@gmail.com on 29 Apr 2011 at 12:42

GoogleCodeExporter commented 9 years ago
I'll rework our proxy to use something better than Jetty.

Original comment by robertsd...@gmail.com on 29 Apr 2011 at 12:43

GoogleCodeExporter commented 9 years ago
Hey Robert, thanks a lot for this observation. This is really helpful - you 
saved me a lot of time. I did analyse the headers, but I didn't notice this 
content-type. Now, we know at least how to avoid that by specifying different 
content-type...

Original comment by vojta.jina on 29 Apr 2011 at 7:20

GoogleCodeExporter commented 9 years ago
FWIW - I found the reverse problem - in my application IE 8 sends an AJAX POST 
that doesn't include a 'Content-Type' in it and the proxy fails to send the 
form-data off to the remote server. 

I was able to work around it by forcing the AJAX request to stick a 
'Content-Type: application/x-www-form-urlencoded' in the headers with the 
request.

Original comment by eric.lam...@gmail.com on 14 Jul 2011 at 3:01

GoogleCodeExporter commented 9 years ago
I attached a patch to the Jetty 6.1.19 Servlet that fixes this issue. The key 
was to not set hasContent=true on GETs. This triggered a call to 
connection.getOutputStream() which changed GETs to POSTs.

Line 136 (add):  boolean isGet = request.getMethod().equals("GET");
Line 149 (edit): if ("content-type".equals(lhdr) && !isGet) //added && !isGet

To patch:
1. Download attached src
2. javac -classpath <path>/JsTestDriver.jar 
org/mortbay/servlet/ProxyServlet.java
3. jar uvf <path>/JsTestDriver.jar org/mortbay/servlet/*.class

Original comment by neli...@gmail.com on 8 Aug 2011 at 6:52

Attachments: