Ejemplo n.º 1
0
static void proxy_connection_new(liVRequest *vr, liBackendConnection *bcon, proxy_context *ctx) {
	proxy_connection* scon = g_slice_new0(proxy_connection);
	liIOStream *iostream;
	liStream *outplug;
	liStream *http_out;

	proxy_context_acquire(ctx);
	scon->ctx = ctx;
	scon->bcon = bcon;
	iostream = li_iostream_new(vr->wrk, li_event_io_fd(&bcon->watcher), proxy_io_cb, scon);

	/* insert proxy header before actual data */
	outplug = li_stream_plug_new(&vr->wrk->loop);

	li_stream_connect(outplug, &iostream->stream_out);

	proxy_send_headers(vr, outplug->out);
	li_stream_notify_later(outplug);

	http_out = li_stream_http_response_handle(&iostream->stream_in, vr, TRUE, FALSE);

	li_vrequest_handle_indirect(vr, NULL);
	li_vrequest_indirect_connect(vr, outplug, http_out);

	li_iostream_release(iostream);
	li_stream_release(outplug);
	li_stream_release(http_out);
}
Ejemplo n.º 2
0
static proxy_connection* proxy_connection_new(liVRequest *vr, proxy_context *ctx) {
	proxy_connection* pcon = g_slice_new0(proxy_connection);

	proxy_context_acquire(ctx);
	pcon->ctx = ctx;
	pcon->vr = vr;
	pcon->fd = -1;
	ev_init(&pcon->fd_watcher, proxy_fd_cb);
	ev_io_set(&pcon->fd_watcher, -1, 0);
	pcon->fd_watcher.data = pcon;
	pcon->proxy_in = li_chunkqueue_new();
	pcon->proxy_out = li_chunkqueue_new();
	pcon->state = SS_WAIT_FOR_REQUEST;
	li_http_response_parser_init(&pcon->parse_response_ctx, &vr->response, pcon->proxy_in, FALSE, FALSE);
	pcon->response_headers_finished = FALSE;
	return pcon;
}