// this function is required in order to support buffer reuse - it hooks the 
//	initial call to ngx_http_handler. after this function returns the upstream 
//	is already allocated by the proxy module, so it's possible to set its buffer
static void
ngx_http_parallel_fiber_initial_wev_handler(ngx_http_request_t *r)
{
	ngx_http_parallel_fiber_ctx_t* fiber;
	ngx_http_upstream_t* u;
	ngx_connection_t    *c;

	c = r->connection;

	// call the default request handler
	r->write_event_handler = ngx_http_handler;
	ngx_http_handler(r);

	// if request was destoryed ignore
	if (c->destroyed)
	{
		return;
	}

	// at this point the upstream should have been allocated by the proxy module
	u = r->upstream;
	if (u == NULL)
	{
		return;
	}

	// initialize the upstream buffer
	fiber = ngx_http_get_module_ctx(r, ngx_http_parallel_module);
	u->buffer = *fiber->cl->buf;

	// initialize the headers list
	u->headers_in.headers = fiber->upstream_headers;
	u->headers_in.headers.last = &u->headers_in.headers.part;
}
static void
ngx_child_request_initial_wev_handler(ngx_http_request_t *r)
{
	ngx_child_request_context_t* ctx;
	ngx_http_upstream_t* u;
	ngx_connection_t    *c;

	c = r->connection;

	// call the default request handler
	r->write_event_handler = ngx_http_handler;
	ngx_http_handler(r);

	// if request was destroyed ignore
	if (c->destroyed)
	{
		return;
	}

	// at this point the upstream should have been allocated by the proxy module
	u = r->upstream;
	if (u == NULL)
	{
		ngx_log_error(NGX_LOG_WARN, r->connection->log, 0,
			"ngx_child_request_initial_wev_handler: upstream is null");
		return;
	}

	// if the upstream module already started receiving, don't touch the buffer
	if (u->buffer.start != NULL)
	{
		ngx_log_error(NGX_LOG_WARN, r->connection->log, 0,
			"ngx_child_request_initial_wev_handler: upstream buffer was already allocated");
		return;
	}

	// initialize the upstream buffer
	ctx = ngx_http_get_module_ctx(r, ngx_http_vod_module);
	if (ctx == NULL)
	{
		ngx_log_error(NGX_LOG_WARN, r->connection->log, 0,
			"ngx_child_request_initial_wev_handler: context is null");
		return;
	}
	u->buffer = *ctx->response_buffer;

	// initialize the headers list
	u->headers_in.headers = ctx->upstream_headers;
	u->headers_in.headers.last = &u->headers_in.headers.part;
}