|
|
xdmp:get-request-body(
|
|
[$format as xs:string?]
|
| ) as item()* |
|
 |
Summary:
For PUT requests, returns the body of the request.
For POST requests, returns the body of the request if it is not of
content-type application/x-www-form-urlencoded.
Returns the empty sequence if it is not called from an application
server.
|
Parameters:
$format
(optional):
The format ("xml", "text", or "binary") to interpret the body as. If not supplied,
the format associated with the content-type header in mimetypes.xml is used. If no
content-type header exists, the default format is "binary".
|
|
Usage Notes:
If the content-type of the POST body is application/x-www-form-urlencoded,
it is not available here, but instead is available in its decoded form
through xdmp:get-request-field-names() and
xdmp:get-request-field().
If there is no content-type header in the request, then the request
body defaults to application/x-www-form-urlencoded, and therefore
xdmp:get-request-body will return the empty sequence. If
you want to read the request body, then the POST must include a
content-type header.
You can use this function to process certain types of web service
SOAP requests with MarkLogic Server.
The output of an xdmp:get-request-body call is
typically a document node, so if you want to get the contents of
the POST, you should add a /node() XPath step to
the output. The contents of the document node could be a text node,
an element node, or a binary node.
|
Example:
xdmp:get-request-body()/node()
=> "<a>Contents of POST body.</a>"
|
|
|
|
xdmp:get-request-client-address( ) as xs:string?
|
|
 |
Summary:
Returns as a string the internet address of the
client from which the HTTP server request is issued.
Returns the empty sequence if it is not called from an HTTP server.
|
Usage Notes:
Use this function if you need to get the internet protocol (IP) address of
the requesting client. For example, you can create an application that
contains conditional code based on IP addresses (see the example below).
|
Example:
The following example shows logic which checks if the request was
submitted from the "localhost" IP address (127.0.0.1).
if (xdmp:get-request-client-address() eq "127.0.0.1")
then "Submitted from localhost."
else "Only localhost access is allowed for this application."
|
Example:
xdmp:get-request-client-address()
=> "127.0.0.1"
|
|
|
|
xdmp:get-request-client-certificate( ) as xs:string?
|
|
 |
Summary:
Returns the PEM encoded client certificate if one was presented.
Returns the empty sequence if it is not called from an HTTP server, if
SSL is not enabled for the HTTP server, or if no certificate is available.
A clients will not send its certificate unless the server requests it.
|
Usage Notes:
Use this function if you need to examine a client's certificate.
|
Example:
The following example returns an XML representation
of a client certificate if one is available.
for $p in xdmp:get-request-client-certificate()
return xdmp:x509-certificate-extract($p)
|
|
|
|
xdmp:get-request-field(
|
|
$name as xs:string,
|
|
[$default as xs:string?]
|
| ) as item()* |
|
 |
Summary:
Returns the value of a named request field. If the request field
is a multipart/form-data type in a POST form, you can
use xdmp:get-request-field for file upload applications
(see the second example below).
|
Parameters:
$name
:
Request field name.
|
$default
(optional):
A default value to return if there is no request field.
|
|
Example:
xdmp:get-request-field("index")
=> "10"
|
Example:
Consider a form.xqy XQuery module with the following content:
<html xmlns="http://www.w3.org/1999/xhtml">
<body>
<form name="test" action="upload.xqy?uid={xdmp:random()}" method="post"
enctype="multipart/form-data">
<p><label>File to upload:
<input type="file" class="name" name="upload" size="50"/></label></p>
<p><input type="submit" value="Upload and Get Results"/></p>
</form>
</body>
</html>
Then have an upload.xqy XQuery module as follows:
let $filename := xdmp:get-request-field-filename("upload")
let $disposition := fn:concat("attachment; filename=""",$filename,"""")
let $x := xdmp:add-response-header("Content-Disposition", $disposition)
let $x:= xdmp:set-response-content-type(
xdmp:get-request-field-content-type("upload"))
return
xdmp:get-request-field("upload")
Execute the form.xqy file, select a file, and click the
"Upload and Get Results" button. The file you uploaded
will open according to the mime type the browser. If you
wanted to save it to the database, you could use
xdmp:document-insert to do so.
|
|
|
|
xdmp:get-request-protocol( ) as xs:string?
|
|
 |
Summary:
Returns as a string the request protocol (either "http" or "https")
Returns the empty sequence if it is not called from an HTTP server.
|
Usage Notes:
Use this function if you need to determine whether the client connection
is HTTP or HTTPs.
|
Example:
The following example shows logic which checks if the request was
submitted via https.
if (xdmp:get-request-protocol() eq "https")
then "Submitted via https."
else "Application requires secure connections only."
|
Example:
xdmp:get-request-protocol()
=> "https"
|
|
|
|
xdmp:login(
|
|
$name as xs:string,
|
|
[$password as xs:string?],
|
|
[$set-session as xs:boolean?]
|
| ) as xs:boolean |
|
 |
Summary:
Logs in a user on an application server that is using
application-level authentication and sends a session cookie containing
the session ID to the user's browser.
Returns true on success, false on failure.
If the user calling this function has the xdmp:login
privilege, this function can be called without a password or with the empty
sequence as the password. In this case, login will succeed if
the specified user exists. Therefore, use the xdmp:login
privilege carefully, as any user with that
privilege will be able to execute code that uses the xdmp:login
function to log in as any user.
Note that only HTTP App Servers allow application-level authentication,
and therefore this function only works on an HTTP App Server; it always
returns false against an XDBC server.
|
Parameters:
$name
:
The username of the user to be logged in.
|
$password
(optional):
The user's password. The password is not needed if the user
calling the function has the xdmp:login execute privilege.
|
$set-session
(optional):
A boolean value specifying whether to set a session variable for the
login. The default is true. Set to false to not set the
session variable to maintain the user logged in.
|
|
Usage Notes:
The session exists in the E-node on which it was created; you cannot
access that session from a different E-node.
You can use the xdmp:set-session-field function to
set a named value in the session and the xdmp:get-session-field
function to return a value set in a session field.
The user session expires when the session reaches its timeout limit.
The session cookie remains on the browser until the browser exits or the
cookie is explicitly removed by the user.
|
Example:
xdmp:login("mark","secret")
=> true() -- if user "mark" has password "secret"
|
Example:
xdmp:login("username") or xdmp:login("username", ())
=> true() -- if user calling the function has the
xdmp:login privilege
|
Example:
xdmp:login("username") or xdmp:login("username", ())
=> SEC-PRIV exception if the user calling the function does
not have the xdmp:login privilege
|
Example:
xdmp:login("username")
=> true() -- if current user has the xdmp:login privilege
|
Example:
xdmp:login("username")
=> SEC-PRIV exception if current user does not have the
xdmp:login privilege
|
|
|
|
xdmp:set-server-field(
|
|
$name as xs:string,
|
|
$value as item()*
|
| ) as item()* |
|
 |
Summary:
Sets the value of a named server field. A server field is created with
xdmp:set-server-field and stores a name/value
pair in memory. The server field is available on the App Server in which
it is set on the host in which the App Server runs, via
xdmp:get-server-field; a server field that is set on one
App Server is not available on other App Servers on that host or on the same
App Server running on another host.
|
Parameters:
$name
:
The name of the server field.
|
$value
:
The value of the server field.
|
|
Required Privilege:
http://marklogic.com/xdmp/privileges/xdmp-set-server-field
|
Usage Notes:
If you use a server field with the system Plugin Framework (by placing
the xdmp:set-server-field code in a main module under
the Plugins directory on a host), then the server field
will be populated for each App Server on the host before the first request
against each App Server is run.
If you set a server field to the empty sequence, it deletes
the server field and it will not appear when you run
xdmp:get-server-field-names.
If you set a session or server field to a value that comes from a
database node (for example, from the value of a search or the
fn:doc function), then that session or server field expires
after the request time limit (10 minutes by default). These fields expire
because they contain references to stands in the database, and as long as
those references exist the stand cannot be reclaimed (merged). To keep
such a node in a session or server field, make a copy of the node
before adding it to the session or server field instead of using the node
directly from the database.
|
Example:
xdmp:set-server-field("foo", "bar")
=> "bar"
|
|
|