alex-sherwin / missing-link

Simple ant http plugin
0 stars 1 forks source link

'303 See Other' redirect status from a POST reported as '200 OK' #25

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Configure an Ant buildfile to POST to a URL; e.g.
<http method="POST" url="${url}" 
    statusProperty="status" >
  <headers>
    <header name="Content-Type" value="application/x-www-form-urlencoded" />
  </headers>
  <entity value="${entity.body}" />
</http>
2. Set the ${url} property to a 'real world' URL that returns a '303 See Other' 
HTTP status code in the response.

What is the expected output? What do you see instead?

Expected: 

     [http] HTTP Request
     [http] ********************
     [http] URL:                (some URL here)
     [http] Method:     POST
     [http]     Content-Type: application/x-www-form-urlencoded
     [http] 
     [http] HTTP Response
     [http] ********************
     [http] Status:     303

The value of ${status} (from statusProperty="") would be expected to be set to 
303, as well.

Am seeing instead:

The status value set to '200', both in the output from the HTTP post and in the 
${status} value.

What version of the product are you using? On what operating system?

1.1.3, Ant 1.8.2, Java 1.6.0_16, Fedora Linux

Please provide any additional information below.

One URL you can try, that seems to always return a 303 redirect - to different 
URLs - on either success or failure:

http://demo.collectionspace.org/collectionspace/ui/core/html/index.html

Original issue reported on code.google.com by aronrobe...@gmail.com on 19 Aug 2011 at 8:47

GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
This may turn out to be a more general issue regarding (at least) how 3xx 
responses are reported.  And it may not be specific to POST, but apply to other 
HTTP methods as well.

When using the <http> task to GET a resource URL that returns a 302 Moved 
Temporarily response, the default output emitted by that task includes (eliding 
whitespace) 'Status: 200'.  In addition, the value of its statusProperty is 
also set to '200'.

Sample:

<http method="GET" 
url="http://demo.collectionspace.org/collectionspace/ui/core/html" 
    statusProperty="status.property.redirect" >
</http>
<echo message="${status.property.redirect}" />

(A '200' status code appears in the output from the <http> task, and is also 
output by the <echo> task.)

When sending this same GET request via 'curl', however, a '302' response is 
received, as in this excerpt:

curl -i http://demo.collectionspace.org/collectionspace/ui/core/html
HTTP/1.1 302 Moved Temporarily
...
Location: 
http://demo.collectionspace.org/collectionspace/ui/core/html/index.html

Original comment by aronrobe...@gmail.com on 19 Aug 2011 at 10:38

GoogleCodeExporter commented 9 years ago
I see this problem with 1.1.3, Ant 1.7.1, Java 1.6.0_27.

The statusProperty for the 'http' ant task is set to 200 whereas I have my web 
server configured to return 301 for a specific page. When I inspect the element 
in Chrome I do see the 301 followed by the 200 when it lands on the destination 
of the redirect.

If it was possible to prevent redirects being followed perhaps the status of 
the initial request could be captured. (For example: boolean: 'followRedirects')

Original comment by stuart.w...@gmail.com on 18 Oct 2012 at 3:46

GoogleCodeExporter commented 9 years ago
For now I have hard-code redirects in my local 
'org.missinglink.http.client.HttpClient' at line 349:

      // disable following redirects
      httpUrlConnection.setFollowRedirects(false);

If time permits I will create a patch so the Ant task can configure this value.

Original comment by stuart.w...@gmail.com on 18 Oct 2012 at 6:33