[英]Apache module - get request body
我正在創建一個簡單的apache模塊,以捕獲所有HTTP通信,以由安全軟件進行實時處理。 我的目標是從請求和響應中獲取標頭和正文。 到目前為止,我設法獲得了我所需要的一切,但請求正文除外。 在輸出過濾器中或在任何其他鈎子/處理程序中獲取帶有所有相關信息的請求響應“元組”的最佳方法是什么?
static apr_status_t ef_output_filter(ap_filter_t *f, apr_bucket_brigade *bb)
{
apr_status_t rv;
request_rec *r = f->r;
apr_bucket *e = APR_BRIGADE_FIRST(bb);
const char *data;
apr_size_t length;
std::ofstream outfile;
outfile.open("/var/log/apache2/test.txt", std::ios_base::app);
outfile << r->method << r->unparsed_uri << std::endl;
apr_table_do(loop_table, &outfile, r->headers_in, NULL);
//!!! READ REQUST BODY HERE !!!!
outfile << r->status << std::endl;
apr_table_do(loop_table, &outfile, r->headers_out, NULL);
outfile << std::endl;
while (e != APR_BRIGADE_SENTINEL(bb)) {
apr_bucket_read(e, &data, &length, APR_BLOCK_READ);
e = APR_BUCKET_NEXT(e);
outfile << data;
}
outfile.flush();
outfile.close();
return ap_pass_brigade(f->next, bb);
}
任何幫助
您可以從ap_filter_t指針變量派生的request_rec指針中讀取正文。
因此,您可以按照以下方式進行購買:
char buffer[SOME_BUFER_SIZE];
int ret_code = ap_setup_client_block(r, REQUEST_CHUNKED_ERROR);
if (ret_code == OK) {
if (ap_should_client_block(r)) {
int dataBytesRead = ap_get_client_block(r, buffer, SOME_BUFFER_SIZE);
...
}
}
在撰寫本文時,您可以在以下位置找到更多信息: https : //docstore.mik.ua/orelly/apache_mod/139.htm或此處: http : //byteandbits.blogspot.com/2013/09/example-apache-module -for-reading.html
希望能幫助到你...
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.