1
1
/*
2
- * @file: nginx_moufle_echo .c
2
+ * @file: nginx_http_echo_module .c
3
3
* @brief: Nginx echo command output a string
4
- * @author: Panda <vozlt@vozlt .com>
4
+ * @author: Panda <itwujunze@163 .com>
5
5
* @version: 1.0.1
6
6
* @date: 2017/6/12
7
7
*
8
8
* Compile:
9
- * shell> ./configure --add-module=/path/to/nginx_moudle_echo .c
9
+ * shell> ./configure --add-module=/path/to/nginx_http_echo_module .c
10
10
*
11
11
*/
12
12
@@ -34,7 +34,7 @@ static ngx_command_t ngx_http_echo_commands[] = {
34
34
NGX_HTTP_LOC_CONF | NGX_CONF_TAKE1 ,
35
35
ngx_http_echo ,
36
36
NGX_HTTP_LOC_CONF_OFFSET ,
37
- offsetof(ngx_http_echo_oc_conf_t , ed ),
37
+ offsetof(ngx_http_echo_loc_conf_t , ed ),
38
38
NULL ,
39
39
},
40
40
ngx_null_command ,
@@ -123,11 +123,11 @@ ngx_http_echo_handler(ngx_http_request_t *r)
123
123
b = ngx_pcalloc (r -> pool , sizeof (ngx_buf_t ));
124
124
if (b == NULL )
125
125
{
126
- ngx_log_error (NGX_LOG_ERROR , r -> connection -> log , 0 , "Failed to allocate response buffer." );
126
+ ngx_log_error (NGX_LOG_ERR , r -> connection -> log , 0 , "Failed to allocate response buffer." );
127
127
return NGX_HTTP_INTERNAL_SERVER_ERROR ;
128
128
}
129
129
out .buf = b ;
130
- put .next = NULL ;
130
+ out .next = NULL ;
131
131
b -> pos = elcf -> ed .data ;
132
132
b -> last = elcf -> ed .data + (elcf -> ed .len );
133
133
b -> memory = 1 ;
@@ -148,12 +148,12 @@ ngx_http_echo_handler(ngx_http_request_t *r)
148
148
* @return ngx status code
149
149
*/
150
150
static char *
151
- ngx_http_echo (ngx_conf_t * f ,ngx_command_t * cmd , void * conf )
151
+ ngx_http_echo (ngx_conf_t * cf ,ngx_command_t * cmd , void * conf )
152
152
{
153
153
ngx_http_core_loc_conf_t * clcf ;
154
- clcf = ngx_http_conf_get_module_loc_conf (cf ,ngx_http_core_module );
155
- clcf -> handle = ngx_http_echo_handler ; //修改核心模块配置(也就是当前location),将其handler替换为我们自己定义的ngx_http_echo_handler
156
- ngx_conf_set_str_slot (cf ,cmf ,conf );
154
+ clcf = ngx_http_conf_get_module_loc_conf (cf , ngx_http_core_module );
155
+ clcf -> handler = ngx_http_echo_handler ; //修改核心模块配置(也就是当前location),将其handler替换为我们自己定义的ngx_http_echo_handler
156
+ ngx_conf_set_str_slot (cf ,cmd ,conf );
157
157
return NGX_CONF_OK ;
158
158
}
159
159
@@ -164,7 +164,7 @@ ngx_http_echo(ngx_conf_t *f,ngx_command_t *cmd , void *conf)
164
164
* @param cf
165
165
* @return
166
166
*/
167
- static char *
167
+ static void *
168
168
ngx_http_echo_create_loc_conf (ngx_conf_t * cf )
169
169
{
170
170
ngx_http_echo_loc_conf_t * conf ;
@@ -202,18 +202,6 @@ ngx_http_echo_merge_loc_conf(ngx_conf_t *cf, void *parent, void *child)
202
202
static ngx_int_t
203
203
ngx_http_echo_init (ngx_conf_t * cf )
204
204
{
205
- ngx_http_handler_pt * h ;
206
- ngx_http_core_main_conf_t * cmcf ;
207
-
208
- cmcf = ngx_http_conf_get_module_main_conf (cf , ngx_http_core_module );
209
-
210
- h = ngx_array_push (& cmcf -> phases [NGX_HTTP_CONTENT_PHASE ].handlers );
211
- if (h == NULL ) {
212
- return NGX_ERROR ;
213
- }
214
-
215
- * h = ngx_http_echo_handler ;
216
-
217
205
return NGX_OK ;
218
206
}
219
207
0 commit comments