📄 websurlhandlerdefine.htm
字号:
<html>
<head>
<title>websUrlHandlerDefine -- GoAhead WebServer API</title>
<link rel="stylesheet" href="../../style/doc.htm" type="text/css">
</head>
<body>
<TABLE border=0 width=100% cellspacing=0 cellpadding=0>
<TR>
<TD class=title-left><b>websUrlHandlerDefine</b></TD>
<TD class=title-center><b> GoAhead WebServer API</b></TD>
<TD class=title-right><B> GoAhead EMF</B></TD>
</TR>
</TABLE>
<HR>
<h2>Synopsis</h2>
<p> Define a new URL handler</p>
<h2>Prototype</h2>
<pre>
#include "webs.h"
int <b>websUrlHandlerDefine</b>(char_t *path,
int (*fn)(webs_t wp, char_t *url, char_t *path, char_t *query), int flags);
</pre>
<h2>Parameters</h2>
<p><table width=90%>
<TR>
<TD width=40>wp
<TD>Web server connection
handle</TD> </TR></table></p>
<h2>Description</h2>
<P> The websUrlHandlerDefine procedure is used to add a
new URL handler by associating a URL path segment with a processing function.
URL handlers are called in sorted order beginning with the handlers with longer
path segments. For example: the handler for "/myUrl" would be called before the handler
for "/my".</P>
<P>
</P>
<P> The flags parameter can specify two special
sorting values:</P>
<ul><li>WEBS_HANDLER_FIRST<li>WEBS_HANDLER_LAST</li></ul>
<P>
If specified the flags modify the calling order of the
handler. Multiple handlers may specify these flags, in which case the order of
all the handlers specifiying WEBS_HANDLER_FIRST is undefined. Similarly for
multiple handlers using
WEBS_HANDLER_LAST.</P>
<P> </P>
<p>A URL handler is a C procedure according to the following prototype:</p>
<P> </P>
<pre>
int myHandler(webs_t wp, char_t *url, char_t *path, char_t *query);
</pre>
<P> </P>
<P>The <i>url</i> parameter contains the entire URL. The <i> path</i>
parameter holds the URL portion after the hostname and port number. The <i>query</i>
parameter holds any optional query.</P>
<P>
</P>
<p>The URL handler must return 1 if it elects to process the
URL. Otherwise it should return 0 to indicate that a later URL handler should
process the URL. A handler may modify the URL request using any of the websSetRequest APIs. In this case,
if it returns 0, a subsequent URL handler will process the modified request.</p>
<h2>Return Value</h2>
<p> Returns 0 if successful. Otherwise returns -1.</p>
<h2>Example</h2>
<pre>
int myHandler(webs_t wp, char_t *url, char_t *path, char_t *query)
{
/* Processing here */
return 1;
}
websUrlHandlerDefine("", myHandler, WEBS_HANDLER_FIRST);
websUrlHandlerDefine("/mypath", myOtherHandler, 0);
</pre>
<h2>See Also</h2>
<p>
<A href="websSecurityHandler.htm">websSecurityHandler</A>
</p>
</body>
</html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -