on_buffer_done(content, good) {
// do something with subrequest response
}
// from nxd_buffer.c clone the source of ibuffer
// (2 functions: ibuffer_data_in_do_read and nxd_ibuffer_init)
// - rename it mybuffer
// replace line: nxe_publish(&ib->data_complete, (nxe_data)-1/0);
// with this line: on_buffer_done(ib->data_ptr, 0/1);
static void mybuffer_data_in_do_read(nxe_ostream* os, nxe_istream* is) {
...
on_buffer_done(ib->data_ptr, 0);
...
on_buffer_done(ib->data_ptr, 1);
...
}
static const nxe_ostream_class mybuffer_data_in_class={.do_read=mybuffer_data_in_do_read};
void mybuffer_init(nxd_ibuffer* ib, nxb_buffer* nxb, int max_data_size) {
...
ib->data_in.super.cls.os_cls=&mybuffer_data_in_class;
...
}
on_response_ready(subconn) {
// connect mybuffer to response content_out to collect the response body
int status=subconn->hsp.resp->status_code;
if (!subconn->subrequest_failed && (!status || status==200) && subconn->hsp.resp->content_length) {
mybuffer_init(&ib, subconn->hsp.nxb, subconn->hsp.resp->content_length>0? subconn->hsp.resp->content_length+1 : NXWEB_MAX_REQUEST_BODY_SIZE);
nxe_connect_streams(subconn->tdata->loop, subconn->hsp.resp->content_out, &ib.data_in);
}
}
// initiate subrequest
subconn=nxweb_http_server_subrequest_start(cs->conn, on_response_ready, host, url);