Esempio n. 1
0
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;
}
Esempio n. 2
0
static nxe_ssize_t ssi_buffer_data_in_write(nxe_ostream* os, nxe_istream* is, int fd, nx_file_reader* fr, nxe_data ptr, nxe_size_t size, nxe_flags_t* _flags) {
  ssi_buffer* ssib=OBJ_PTR_FROM_FLD_PTR(ssi_buffer, data_in, os);
  //nxe_loop* loop=os->super.loop;

  nxweb_log_debug("ssi_buffer_data_in_write");

  nxe_flags_t flags=*_flags;
  if (ssib->overflow) { // reached max_ssi_size
    // swallow input data
  }
  else {
    int wsize=size;
    if (ssib->data_size+wsize > MAX_SSI_SIZE) wsize=MAX_SSI_SIZE-ssib->data_size;
    assert(wsize>=0);
    if (wsize>0) {
      nx_file_reader_to_mem_ptr(fd, fr, &ptr, &size, &flags);
      if (((int)size)<wsize) wsize=size;
      nxb_make_room(ssib->nxb, wsize);
      char* dptr=nxb_get_room(ssib->nxb, 0);
      memcpy(dptr, ptr.cptr, wsize);
      nxb_blank_fast(ssib->nxb, wsize);
      ssib->data_size+=wsize;
      while (parse_text(ssib));
      if (ssib->data_size >= MAX_SSI_SIZE) {
        ssib->overflow=1;
      }
    }
  }
  if (flags&NXEF_EOF) {
    nxe_ostream_unset_ready(os);

    int nbytes;
    char* ptr=nxb_finish_stream(ssib->nxb, &nbytes);
    if (nbytes) {
      nxweb_composite_stream_append_bytes(ssib->cs, ptr, nbytes);
    }
    nxweb_composite_stream_close(ssib->cs);
  }
  return size;
}