Hi Florent,

Nobody seems to have answered this question yet. I ran your code against 
MarkLogic Server 4.1-3, but everything seems to run as expected. Running the 
code as is, returns the Hello message. Calling the bug.xqy directly from a 
browser ('forcing' a GET), returns a 405. Changing one of both queries to 
'break' the who parameter, triggers the return of a 400.

I have to note though, that I had to use a tcp monitor to reveal the response 
codes. Browsers tend to hide such interesting info for us.

By the way, I don't think that MarkLogic Server cares much about which response 
codes you specify. And I used the same response codes for similar reasons in a 
MarkLogic project I have been working on myself.

Good luck.

Kind regards,
Geert

>


Drs. G.P.H. Josten
Consultant


http://www.daidalos.nl/
Daidalos BV
Source of Innovation
Hoekeindsehof 1-4
2665 JZ Bleiswijk
Tel.: +31 (0) 10 850 1200
Fax: +31 (0) 10 850 1199
http://www.daidalos.nl/
KvK 27164984
De informatie - verzonden in of met dit emailbericht - is afkomstig van 
Daidalos BV en is uitsluitend bestemd voor de geadresseerde. Indien u dit 
bericht onbedoeld hebt ontvangen, verzoeken wij u het te verwijderen. Aan dit 
bericht kunnen geen rechten worden ontleend.


> From: [email protected]
> [mailto:[email protected]] On Behalf Of
> Florent Georges
> Sent: vrijdag 4 december 2009 17:46
> To: MarkLogic General ML
> Subject: [MarkLogic Dev General] Strange behavior with 2
> calls to xdmp:set-response-code()
>
>   Hi,
>
>   I've encountered a strange behavior with xdmp:set-response-code.
> I have the following code (it check the request method is
> POST, then check the param 'who' is there and finally return
> a string):
>
>     xquery version "1.0";
>
>     declare namespace xdmp = "http://marklogic.com/xdmp";;
>
>     if ( xdmp:get-request-method() ne 'POST' ) then (
>       xdmp:set-response-code(
>         405, concat('Method not allowed: ',
> xdmp:get-request-method()))
>     )
>     else (
>       let $who as xs:string? := xdmp:get-request-field("who")
>         return
>           if ( empty($who) ) then (
>             (: TODO: I think this is over-abusing the 400 code... :)
>             xdmp:set-response-code(
>               400, 'Bad request, the param who is missing')
>           )
>           else (
>             concat('Hello, ', $who, '!')
>           )
>     )
>
>   With the following client (assuming the above query is in
> the same directory, in bug.xqy):
>
>     <html xmlns="http://www.w3.org/1999/xhtml";>
>        <head>
>           <title>What did I do wrong?</title>
>        </head>
>        <body>
>           <form action="bug.xqy" method="post">
>              <p>
>                 Who: <input type="text" name="who"/>
>                 <input type="submit" value="Go!"/>
>              </p>
>           </form>
>        </body>
>     </html>
>
> everything run fine.  But if I make a typo in the name of the
> param "who", I get unexpected results:
>
>   1/ the result is "405 Method not allowed: GET" ! I would have
>      expected to get the error 400, and certainly not to get GET as
>      the method;
>
>   2/ if I replace the xdmp:set-response-code(405, ...) by the
>      concat (so returning only the message as a string, not setting
>      an error code), the response is "200 OK" with the content is
>      empty;
>
>   3/ if I replace the xdmp:set-response-code(400, ...) by the
>      literal message string ('Bad request, the param who is
>      missing') I get the expected result (this same string as the
>      content of the response), regardless of the sequence ctor in
>      the first 'if'.
>
>   Do I misuse xdmp:set-response-code()?
>
>   Regards,
>
> --
> Florent Georges
> http://www.fgeorges.org/
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
> _______________________________________________
> General mailing list
> [email protected]
> http://xqzone.com/mailman/listinfo/general
>

_______________________________________________
General mailing list
[email protected]
http://xqzone.com/mailman/listinfo/general

Reply via email to