apache模块开发 request_rec结构体中变量的值

   request_rec结构体中用很多成员变量,这里只输出了char和int两种类型的值。

   source

 1 #include "httpd.h"

 2 #include "http_config.h"

 3 #include "http_protocol.h"

 4 #include "ap_config.h"

 5 

 6 #define frputs(f, buff, r, prop) /

 7             sprintf(buff, "%s:" f "/n", #prop, r->prop); /

 8             ap_rputs(buff, r);

 9 #define crputs(buff, r, prop) frputs("%s", buff, r, prop)

10 #define irputs(buff, r, prop) frputs("%d", buff, r, prop)

11 

12 static int print_request_handler(request_rec *r)

13 {

14     if (strcmp(r->handler, "print_request")) {

15         return DECLINED;

16     }

17     r->content_type = "text/plain";

18 

19     if (r->header_only) {

20         return OK;

21     }

22 

23     char buff[4096];

24 

25     ap_rputs("request_rec構造体のchar型のメンバをちょっとダンプします。/n", r);

26     crputs(buff, r, the_request);

27     crputs(buff, r, protocol);

28     crputs(buff, r, hostname);

29     crputs(buff, r, status_line);

30     crputs(buff, r, method);

31     crputs(buff, r, range);

32     crputs(buff, r, content_type);

33     crputs(buff, r, handler);

34     crputs(buff, r, content_encoding);

35     crputs(buff, r, vlist_validator);

36     crputs(buff, r, user);

37     crputs(buff, r, ap_auth_type);

38     crputs(buff, r, unparsed_uri);

39     crputs(buff, r, uri);

40     crputs(buff, r, filename);

41     crputs(buff, r, canonical_filename);

42     crputs(buff, r, path_info);

43     crputs(buff, r, args);

44 

45     irputs(buff, r, assbackwards);

46     irputs(buff, r, proxyreq);

47     irputs(buff, r, header_only);

48     irputs(buff, r, proto_num);

49     irputs(buff, r, status);

50     irputs(buff, r, method_number);

51     irputs(buff, r, chunked);

52     irputs(buff, r, read_body);

53     irputs(buff, r, read_chunked);

54     irputs(buff, r, no_cache);

55     irputs(buff, r, no_local_copy);

56     irputs(buff, r, used_path_info);

57     irputs(buff, r, eos_sent);

58 

59 

60     return OK;

61 }

62 

63 static void print_request_register_hooks(apr_pool_t *p)

64 {

65     ap_hook_handler(print_request_handler, NULL, NULL, APR_HOOK_MIDDLE);

66 }

67 

68 /* Dispatch list for API hooks */

69 module AP_MODULE_DECLARE_DATA print_request_module = {

70     STANDARD20_MODULE_STUFF, 

71     NULL,                  /* create per-dir    config structures */

72     NULL,                  /* merge  per-dir    config structures */

73     NULL,                  /* create per-server config structures */

74     NULL,                  /* merge  per-server config structures */

75     NULL,                  /* table of config file commands       */

76     print_request_register_hooks  /* register hooks                      */

77 };




 

用下记URL访问的结果

http://localhost/print_request?foo=bar&baz=foobar

request_rec构造体的char型成员的返回值。

the_request:GET /print_request?foo=bar&baz=foobar HTTP/1.1

protocol:HTTP/1.1

hostname:localhost

status_line:(null)

method:GET

range:(null)

content_type:text/plain

handler:print_request

content_encoding:(null)

vlist_validator:(null)

user:(null)

ap_auth_type:(null)

unparsed_uri:/print_request?foo=bar&baz=foobar

uri:/print_request

filename:/var/www/html/print_request

canonical_filename:/var/www/html/print_request

path_info:

args:foo=bar&baz=foobar

assbackwards:0

proxyreq:0

header_only:0

proto_num:1001

status:200

method_number:0

chunked:0

read_body:0

read_chunked:0

no_cache:0

no_local_copy:0

used_path_info:2

eos_sent:0

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值