Skip to content
Browse files

added ddebug.h since Valery won't merge this branch to his mainstream…

… anyway.
  • Loading branch information...
1 parent 35d826e commit f4a75e5dc185982c99d268faa78800c511bca6a1 @agentzh agentzh committed
Showing with 96 additions and 0 deletions.
  1. +71 −0 ddebug.h
  2. +25 −0 ngx_http_eval_module.c
View
71 ddebug.h
@@ -0,0 +1,71 @@
+#ifndef DDEBUG_H
+#define DDEBUG_H
+
+#include <ngx_core.h>
+
+#if defined(DDEBUG) && (DDEBUG)
+
+# if (NGX_HAVE_VARIADIC_MACROS)
+
+# define dd(...) fprintf(stderr, "eval *** "); \
+ fprintf(stderr, __VA_ARGS__); \
+ fprintf(stderr, " at %s line %d.\n", __FILE__, __LINE__)
+
+# else
+
+#include <stdarg.h>
+#include <stdio.h>
+
+#include <stdarg.h>
+
+static void dd(const char * fmt, ...) {
+}
+
+# endif
+
+#else
+
+# if (NGX_HAVE_VARIADIC_MACROS)
+
+# define dd(...)
+
+# else
+
+#include <stdarg.h>
+
+static void dd(const char * fmt, ...) {
+}
+
+# endif
+
+#endif
+
+#if defined(DDEBUG) && (DDEBUG)
+
+#define dd_check_read_event_handler(r) \
+ dd("r->read_event_handler = %s", \
+ r->read_event_handler == ngx_http_block_reading ? \
+ "ngx_http_block_reading" : \
+ r->read_event_handler == ngx_http_test_reading ? \
+ "ngx_http_test_reading" : \
+ r->read_event_handler == ngx_http_request_empty_handler ? \
+ "ngx_http_request_empty_handler" : "UNKNOWN")
+
+#define dd_check_write_event_handler(r) \
+ dd("r->write_event_handler = %s", \
+ r->write_event_handler == ngx_http_handler ? \
+ "ngx_http_handler" : \
+ r->write_event_handler == ngx_http_core_run_phases ? \
+ "ngx_http_core_run_phases" : \
+ r->write_event_handler == ngx_http_request_empty_handler ? \
+ "ngx_http_request_empty_handler" : "UNKNOWN")
+
+#else
+
+#define dd_check_read_event_handler(r)
+#define dd_check_write_event_handler(r)
+
+#endif
+
+#endif /* DDEBUG_H */
+
View
25 ngx_http_eval_module.c
@@ -4,6 +4,8 @@
*/
+#define DDEBUG 0
+#include "ddebug.h"
#include <ngx_config.h>
#include <ngx_core.h>
#include <ngx_http.h>
@@ -316,6 +318,8 @@ ngx_http_eval_post_subrequest_handler(ngx_http_request_t *r, void *data, ngx_int
content_type.len = sizeof("application/octet-stream") - 1;
}
+ dd("content_type: %.*s", content_type.len, content_type.data);
+
while(f->content_type.len) {
if(!ngx_strncasecmp(f->content_type.data, content_type.data,
@@ -345,6 +349,8 @@ ngx_http_eval_octet_stream(ngx_http_request_t *r, ngx_http_eval_ctx_t *ctx)
ngx_http_variable_value_t *value = ctx->values[0];
ngx_http_eval_ctx_t *sr_ctx;
+ dd("eval octet stream");
+
sr_ctx = ngx_http_get_module_ctx(r, ngx_http_eval_module);
if (sr_ctx && sr_ctx->buffer.start) {
@@ -373,6 +379,8 @@ ngx_http_eval_plain_text(ngx_http_request_t *r, ngx_http_eval_ctx_t *ctx)
u_char *p;
ngx_http_variable_value_t *value = ctx->values[0];
+ dd("eval plain text");
+
rc = ngx_http_eval_octet_stream(r, ctx);
if(rc != NGX_OK) {
@@ -718,6 +726,8 @@ ngx_http_eval_subrequest_in_memory(ngx_conf_t *cf,
ngx_http_eval_loc_conf_t *elcf = conf;
char *res;
+ dd("eval subrequest in memory");
+
res = ngx_conf_set_flag_slot(cf, cmd, conf);
if (res != NGX_CONF_OK) {
return res;
@@ -746,6 +756,7 @@ ngx_http_eval_init(ngx_conf_t *cf)
*h = ngx_http_eval_handler;
if (ngx_http_eval_requires_filter) {
+ dd("requires filter");
ngx_http_next_header_filter = ngx_http_top_header_filter;
ngx_http_top_header_filter = ngx_http_eval_header_filter;
@@ -774,6 +785,8 @@ ngx_http_eval_header_filter(ngx_http_request_t *r)
/* suppress header output */
+ dd("header filter called: type: %.*s", r->headers_out.content_type.len, r->headers_out.content_type.data);
+
return NGX_OK;
}
@@ -796,9 +809,12 @@ ngx_http_eval_body_filter(ngx_http_request_t *r, ngx_chain_t *in)
return ngx_http_next_body_filter(r, in);
}
+ dd("in body filter");
+
b = &ctx->buffer;
if (b->start == NULL) {
+ dd("allocate buffer");
conf = ngx_http_get_module_loc_conf(r->parent, ngx_http_eval_module);
b->start = ngx_palloc(r->pool, conf->buffer_size);
@@ -817,15 +833,24 @@ ngx_http_eval_body_filter(ngx_http_request_t *r, ngx_chain_t *in)
}
if ( ! ngx_buf_in_memory(cl->buf)) {
+ dd("buf not in memory!");
continue;
}
len = cl->buf->last - cl->buf->pos;
+
+ if (len == 0) {
+ continue;
+ }
+
if (len > (size_t) rest) {
/* we truncate the exceeding part of the response body */
+ dd("truncate and ignore exceeding bufs");
len = rest;
}
+
+ dd("copied data '%.*s' (len %d, c0: %d)", len, cl->buf->pos, len, *(cl->buf->pos));
b->last = ngx_copy(b->last, cl->buf->pos, len);
}

0 comments on commit f4a75e5

Please sign in to comment.
Something went wrong with that request. Please try again.