static nxweb_result subreq_on_request(nxweb_http_server_connection* conn, nxweb_http_request* req, nxweb_http_response* resp) { nxweb_set_response_content_type(resp, "text/html"); nxweb_composite_stream* cs=nxweb_composite_stream_init(conn, req); nxweb_composite_stream_append_bytes(cs, "[test1]", sizeof("[test1]")-1); int fd=open("www/root/index.htm", O_RDONLY|O_NONBLOCK); nxweb_composite_stream_append_fd(cs, fd, 0, 15); // fd will be auto-closed nxweb_composite_stream_append_subrequest(cs, 0, "/8777/"); nxweb_composite_stream_append_bytes(cs, "[test2]", sizeof("[test2]")-1); nxweb_composite_stream_close(cs); nxweb_composite_stream_start(cs, resp); return NXWEB_OK; }
static nxweb_result ssi_do_filter(nxweb_filter* filter, nxweb_http_server_connection* conn, nxweb_http_request* req, nxweb_http_response* resp, nxweb_filter_data* fdata) { ssi_filter_data* sfdata=(ssi_filter_data*)fdata; if (resp->status_code && resp->status_code!=200 && resp->status_code!=404) return NXWEB_OK; if (!resp->content_length) return NXWEB_OK; if (resp->gzip_encoded) { fdata->bypass=1; return NXWEB_NEXT; } if (!resp->ssi_on) { if (!resp->mtype && resp->content_type) { resp->mtype=nxweb_get_mime_type(resp->content_type); } if (!resp->mtype || !resp->mtype->ssi_on) { fdata->bypass=1; return NXWEB_NEXT; } } nxd_http_server_proto_setup_content_out(&conn->hsp, resp); // attach content_out to ssi_buffer ssi_buffer_init(&sfdata->ssib, conn, req); if (resp->content_length>0) ssi_buffer_make_room(&sfdata->ssib, min(MAX_SSI_SIZE, resp->content_length)); nxe_connect_streams(conn->tdata->loop, resp->content_out, &sfdata->ssib.data_in); nxweb_set_request_data(req, SSIB_REQ_KEY, (nxe_data)(void*)&sfdata->ssib, 0); // will be used for variable lookups in parent requests // replace content_out with composite stream nxweb_composite_stream* cs=nxweb_composite_stream_init(conn, req); nxweb_composite_stream_start(cs, resp); // reset previous response content resp->content=0; resp->sendfile_path=0; if (resp->sendfile_fd) { // save it to close on finalize sfdata->input_fd=resp->sendfile_fd; resp->sendfile_fd=0; } resp->last_modified=0; sfdata->ssib.cs=cs; return NXWEB_OK; }