我正在学习为我正在从事的项目编写 Apache 模块。我找到了官方指南,结果非常有用。
在第一页,“为 Apache HTTP Server 2.4 开发模块”,“构建处理程序”部分,“request_rec
结构”小节提供了一些示例代码:
static int example_handler(request_rec *r)
{
/* Set the appropriate content type */
ap_set_content_type(r, "text/html");
/* Print out the IP address of the client connecting to us: */
ap_rprintf(r, "<h2>Hello, %s!</h2>", r->useragent_ip);
/* If we were reached through a GET or a POST request, be happy, else sad. */
if ( !strcmp(r->method, "POST") || !strcmp(r->method, "GET") ) {
ap_rputs("You used a GET or a POST method, that makes us happy!<br/>", r);
}
else {
ap_rputs("You did not use POST or GET, that makes us sad :(<br/>", r);
}
/* Lastly, if there was a query string, let's print that too! */
if (r->args) {
ap_rprintf(r, "Your query string was: %s", r->args);
}
return OK;
}
引起我注意的是正在strcmp
查看r->method
它是POST
,GET
还是其他东西。这很奇怪。我认为唯一的 HTTP 方法是GET
and POST
? 是否还有其他原因,或者只是开发人员(或记录人员)不必要地谨慎?