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