← Back to team overview

zorba-coders team mailing list archive

[Merge] lp:~zorba-coders/zorba/bug-955574 into lp:zorba

 

Matthias Brantner has proposed merging lp:~zorba-coders/zorba/bug-955574 into lp:zorba.

Requested reviews:
  Matthias Brantner (matthias-brantner)
  Till Westmann (tillw)
Related bugs:
  Bug #955574 in Zorba: "http-client "hangs" if following a POST request"
  https://bugs.launchpad.net/zorba/+bug/955574

For more details, see:
https://code.launchpad.net/~zorba-coders/zorba/bug-955574/+merge/97537

fixed bug #955574 (http-client "hangs" if following a POST request)

The solution is to raise an error if the user wants to follow a redirect on a POST, PUT, or DELETE request.
-- 
https://code.launchpad.net/~zorba-coders/zorba/bug-955574/+merge/97537
Your team Zorba Coders is subscribed to branch lp:zorba.
=== modified file 'ChangeLog'
--- ChangeLog	2012-03-12 20:01:39 +0000
+++ ChangeLog	2012-03-14 23:16:22 +0000
@@ -49,6 +49,7 @@
   * Fixed bug #911585 (management of variables during eval)
   * Fixed bug #866423 (fn:empty and fn:exists iterators must reset their input in
     case of early-out)
+  * Fixed bug #955574 (http-client "hangs" if following a POST request)
   * Fixed bug #945241 (StaticCollectionManager::declaredIndexes() and temporary indexes)
   * Fixed bug #872288 (reset recursive flag during node rename)
   * Fixed bug #905041 (allow for the default element and function namespaces to be

=== modified file 'modules/com/zorba-xquery/www/modules/http-client-error.xq'
--- modules/com/zorba-xquery/www/modules/http-client-error.xq	2011-08-17 19:19:17 +0000
+++ modules/com/zorba-xquery/www/modules/http-client-error.xq	2012-03-14 23:16:22 +0000
@@ -67,3 +67,10 @@
  : but make no sense (for example: http:send-request((), ())).
  :)
 declare variable $err:HCV01 as xs:QName := fn:QName($err:errNS, "err:HCV01");
+
+(:~
+ : Zorba specific error
+ : This error is raised if trying to follow a redirect for a POST, PUT, or
+ : DELETE request
+ :)
+declare variable $err:HCV02 as xs:QName := fn:QName($err:errNS, "err:HCV02");

=== modified file 'modules/com/zorba-xquery/www/modules/http-client.xq'
--- modules/com/zorba-xquery/www/modules/http-client.xq	2012-02-16 14:11:02 +0000
+++ modules/com/zorba-xquery/www/modules/http-client.xq	2012-03-14 23:16:22 +0000
@@ -286,6 +286,7 @@
  : @error error:HC004 The src attribute on the body element is mutually exclusive with all other attribute (except the media-type).
  : @error error:HC005 The input request element is not valid.
  : @error error:HC006 A timeout occurred waiting for the response.
+ : @error error:HCV02 Trying to follow a redirect of a POST, PUT, or DELETE request
  :
  : @example test/rbkt/Queries/zorba/http-client/send-request/send-request_href.xq
  : @example test/rbkt/Queries/zorba/http-client/send-request/http3-post.xq
@@ -455,6 +456,7 @@
  : @error error:HC001 An HTTP error occurred.
  : @error error:HC002 Error parsing the response content as XML.
  : @error error:HC006 A timeout occurred waiting for the response.
+ : @error error:HCV02 Trying to follow a redirect of a PUT request.
  :
  : @example test/rbkt/Queries/zorba/http-client/put/put2_element.xq
  :)
@@ -498,6 +500,7 @@
  : @error error:HC001 An HTTP error occurred.
  : @error error:HC002 Error parsing the response content as XML.
  : @error error:HC006 A timeout occurred waiting for the response.
+ : @error error:HCV02 Trying to follow a redirect of a PUT request.
  :
  : @example test/rbkt/Queries/zorba/http-client/put/put3_html_br.xq
  :)
@@ -538,6 +541,7 @@
  : @error error:HC001 An HTTP error occurred.
  : @error error:HC002 Error parsing the response content as XML.
  : @error error:HC006 A timeout occurred waiting for the response.
+ : @error error:HCV02 Trying to follow a redirect of a DELETE request.
  :
  : @example test/rbkt/Queries/zorba/http-client/delete/delete.xq
  :)
@@ -564,6 +568,7 @@
  : @error error:HC001 An HTTP error occurred.
  : @error error:HC002 Error parsing the response content as XML.
  : @error error:HC006 A timeout occurred waiting for the response.
+ : @error error:HCV02 Trying to follow a redirect of a POST request.
  :
  : @example test/rbkt/Queries/zorba/http-client/post/post2_comment.xq
  :)
@@ -608,6 +613,7 @@
  : @error error:HC001 An HTTP error occurred.
  : @error error:HC002 Error parsing the response content as XML.
  : @error error:HC006 A timeout occurred waiting for the response.
+ : @error error:HCV02 Trying to follow a redirect of a POST request.
  :
  : @example test/rbkt/Queries/zorba/http-client/post/post3_xml.xq
  :)

=== modified file 'modules/com/zorba-xquery/www/modules/http-client.xq.src/http_client.cpp'
--- modules/com/zorba-xquery/www/modules/http-client.xq.src/http_client.cpp	2012-03-07 09:26:50 +0000
+++ modules/com/zorba-xquery/www/modules/http-client.xq.src/http_client.cpp	2012-03-14 23:16:22 +0000
@@ -187,7 +187,7 @@
 
       if (lReqSet) {
         lHandler.reset(new HttpRequestHandler(lCURL, args[2]));
-        lParser.reset(new RequestParser(lHandler.get()));
+        lParser.reset(new RequestParser(lHandler.get(), thrower));
         lParser->parse(lRequest);
       }
       if (lHrefSet) {

=== modified file 'modules/com/zorba-xquery/www/modules/http-client.xq.src/request_parser.cpp'
--- modules/com/zorba-xquery/www/modules/http-client.xq.src/request_parser.cpp	2011-07-05 11:16:42 +0000
+++ modules/com/zorba-xquery/www/modules/http-client.xq.src/request_parser.cpp	2012-03-14 23:16:22 +0000
@@ -15,6 +15,7 @@
  */
 #include "request_parser.h"
 #include "request_handler.h"
+#include "error_thrower.h"
 
 #include <cassert>
 #include <iostream>
@@ -87,6 +88,7 @@
     bool lSendAuthorization = false;
     String lOverrideContentType;
     bool lFollowRedirect = true;
+    bool lUserDefinedFollowRedirect = false;
     int lTimeout = -1;
 
     Iterator_t lIter = aItem.getAttributes();
@@ -117,10 +119,22 @@
       } else if (lLocalName == "follow-redirect") {
         String lString = lItem.getStringValue();
         lFollowRedirect = lString == "true";
+        lUserDefinedFollowRedirect = true;
       } else if (lLocalName == "timeout") {
         lTimeout = lItem.getIntValue();
       }
     }
+
+    if (lUserDefinedFollowRedirect && lFollowRedirect &&
+        (lMethod != "GET" && lMethod != "HEAD" && lMethod != "OPTIONS"))
+    {
+      std::ostringstream lMsg;
+      lMsg << lMethod << ": cannot follow redirect";
+      theThrower->raiseException(
+        "http://expath.org/ns/error";, "HCV02", lMsg.str()
+       );
+    }
+
     theHandler->beginRequest(lMethod, lHref, lStatusOnly, lUsername,
       lPassword, lAuthMethod, lSendAuthorization, lOverrideContentType,
       lFollowRedirect, lTimeout);

=== modified file 'modules/com/zorba-xquery/www/modules/http-client.xq.src/request_parser.h'
--- modules/com/zorba-xquery/www/modules/http-client.xq.src/request_parser.h	2010-11-05 16:00:27 +0000
+++ modules/com/zorba-xquery/www/modules/http-client.xq.src/request_parser.h	2012-03-14 23:16:22 +0000
@@ -21,13 +21,15 @@
 
 namespace http_client {
 class RequestHandler;
+class ErrorThrower;
 
 class RequestParser {
 protected:
   RequestHandler* theHandler;
+  ErrorThrower*   theThrower;
 
 public:
-  RequestParser(RequestHandler* aHandler) : theHandler(aHandler) {}
+  RequestParser(RequestHandler* aHandler, ErrorThrower& aThrower) : theHandler(aHandler), theThrower(&aThrower) {}
   bool parse(const Item& aItem);
 
 private:

=== added file 'test/rbkt/Queries/zorba/http-client/send-request/http4-post-redirect.spec'
--- test/rbkt/Queries/zorba/http-client/send-request/http4-post-redirect.spec	1970-01-01 00:00:00 +0000
+++ test/rbkt/Queries/zorba/http-client/send-request/http4-post-redirect.spec	2012-03-14 23:16:22 +0000
@@ -0,0 +1,1 @@
+Error: http://expath.org/ns/error:HCV02

=== added file 'test/rbkt/Queries/zorba/http-client/send-request/http4-post-redirect.xq'
--- test/rbkt/Queries/zorba/http-client/send-request/http4-post-redirect.xq	1970-01-01 00:00:00 +0000
+++ test/rbkt/Queries/zorba/http-client/send-request/http4-post-redirect.xq	2012-03-14 23:16:22 +0000
@@ -0,0 +1,5 @@
+import module namespace http="http://www.zorba-xquery.com/modules/http-client";;
+
+declare namespace h = "http://expath.org/ns/http-client";;
+
+http:send-request(<h:request href="http://zorbatest.lambda.nu:8080/remotequeue"; method="POST" follow-redirect="true"/>, (), ());


Follow ups