2012-06-19 11 views
5

मैं एक nginx फिल्टर मॉड्यूल पढ़ सकते हैं कि/कोडिंग किया गया है आने वाले अनुरोधों के लिए कुकीज़ लिखें। यदि कोई विशेष कुकी सही ढंग से सेट नहीं होती है (यानी प्रमाणीकरण कुकी), तो यह आउटगोइंग हेडर स्थिति उचित त्रुटि कोड पर सेट कर देगा। यह Evan Miller's tutorial के निर्देशों के अनुसार ठीक काम करता है। अगले भाग में मैं काम करने की कोशिश कर रहा हूं (और अब तक नहीं है) शरीर फ़िल्टर को बुलाया जा रहा है, इसलिए त्रुटि प्रतिक्रियाओं का सामना करते समय मैं शरीर प्रतिक्रिया पाठ को सम्मिलित/प्रतिस्थापित कर सकता हूं। मैंने फिर से शरीर फिल्टर पर Evan Miller's tutorial का पालन किया, और मैं इस काम को पाने के लिए नहीं कर सकता। यहाँ मेरी सेटअप है:nginx हैडर और शारीरिक फ़िल्टर मॉड्यूल

static ngx_http_output_header_filter_pt ngx_http_next_header_filter; 
static ngx_http_output_body_filter_pt ngx_http_next_body_filter; 
... 
... 


static ngx_http_module_t ngx_http_source_cookie_module_ctx = { 
    NULL,        /* preconfiguration */ 
    ngx_http_source_cookie_init,    /* postconfiguration */ 

    NULL,        /* create main configuration */ 
    NULL,        /* init main configuration */ 

    NULL,        /* create server configuration */ 
    NULL,        /* merge server configuration */ 

    ngx_http_source_cookie_create_loc_conf, /* create location configuration */ 
    ngx_http_source_cookie_merge_loc_conf /* merge location configuration */ 
}; 

ngx_module_t ngx_http_source_cookie_module = { 
    NGX_MODULE_V1, 
    &ngx_http_source_cookie_module_ctx,  /* module context */ 
    ngx_http_source_cookie_commands,   /* module directives */ 
    NGX_HTTP_MODULE,     /* module type */ 
    NULL,        /* init master */ 
    NULL,        /* init module */ 
    NULL,        /* init process */ 
    NULL,        /* init thread */ 
    NULL,        /* exit thread */ 
    NULL,        /* exit process */ 
    NULL,        /* exit master */ 
    NGX_MODULE_V1_PADDING 
}; 
/*--------------------------------------------------------------------------*/ 

/*--------------------------------------------------------------------------*/ 
static ngx_int_t 
ngx_http_source_cookie_header_filter(ngx_http_request_t *r) 
{ 
    // this gets invoked 
    ... 
} 

/*--------------------------------------------------------------------------*/ 

/*--------------------------------------------------------------------------*/ 
static ngx_int_t 
ngx_http_body_filter(ngx_http_request_t *r, ngx_chain_t *in) 
{ 
    // this never get invoked 
    ... 
} 

/*--------------------------------------------------------------------------*/ 

/*--------------------------------------------------------------------------*/ 
static ngx_int_t 
ngx_http_source_cookie_init(ngx_conf_t *cf) 
{ 
    // registering of my filters 

    ngx_http_next_header_filter = ngx_http_top_header_filter; 
    ngx_http_top_header_filter = ngx_http_source_cookie_header_filter; 

    ngx_http_next_body_filter = ngx_http_top_body_filter; 
    ngx_http_top_body_filter = ngx_http_body_filter; 

    return NGX_OK; 
} 

यह मेरी बुनियादी सेटअप है, और जहाँ तक मैं बता सकता हूँ, यह सब उदाहरण/ट्यूटोरियल मैं का सामना करना पड़ा पर जगह है। मैं सोच रहा हूं कि अगर कुछ अलग है तो मुझे सक्षम करने की आवश्यकता है ... एक एनजीआईएनएक्स कॉन्फ़िगरेशन विकल्प, एनजीआईएनएक्स।/कॉन्फिगर कम्पाइल विकल्प, आदि

किसी भी मदद की बहुत सराहना की जाती है।

+0

nginx संस्करण का उपयोग कर रहे हैं? आपने क्या //configure पैरामीटर का उपयोग किया था? मुझे स्थिर संस्करण के साथ बॉडी फ़िल्टर मॉड्यूल चलाने की कोशिश करने में एक ही समस्या थी, फिर मैंने dev संस्करण (1.3.5) के साथ प्रयास किया और यह काम किया (पता नहीं क्यों)। – Alex

उत्तर

0

मैं ध्यान दें ngx_http_<module_name>_header_filter() में है कि इवान does not को ठीक http सामग्री की लंबाई।

यदि मैं http सामग्री लंबाई (r->headers_out.content_length_n) नहीं जोड़ता, अनुरोध के अंत में सम्मिलित पाठ nginx-1.2.7 स्थिर से आउटपुट नहीं होगा।

इसके अलावा, आप footer filter module देख सकते हैं।

संबंधित मुद्दे