char *
http_servlet_tmpl_func_unbuffer(struct tmpl_ctx *ctx,
	char **errmsgp, int ac, char **av)
{
	struct http_servlet_tmpl_arg *const arg = tmpl_ctx_get_arg(ctx);
	const char *const mtype = tmpl_ctx_get_mtype(ctx);

	if (ac != 1) {
		errno = EINVAL;
		return (NULL);
	}
	http_response_send_headers(arg->resp, 1);
	return (STRDUP(mtype, ""));
}
Example #2
0
void
http_response_send(HttpResponse *res)
{
  http_response_send_headers(res);

  if( res->data )
    {
      int n_bytes = res->data_len;
      
      /* Dont send '\0' in response */
      if (res->data[n_bytes-1] == '\0') 
        n_bytes--;

      fwrite(res->data, 1, n_bytes, stdout);
    }
}
Example #3
0
void
http_response_send_bigfile
    (HttpResponse *res, char *filename, char *content)
/* ! basic, just read and copy file bit/bit */
{
  http_response_set_content_type(res, content);
  http_response_send_headers(res);  
  unsigned char *data;
  FILE *fp=fopen(filename,"rb");
  /* get file size and alloc memory */
  fseek (fp , 0 , SEEK_END);
  unsigned long datasize = ftell(fp);
  rewind (fp);
  if (!(data = (unsigned char*)malloc(datasize)))
    exit(-1);
  /* copy */
  while ( datasize-- )
    fputc(fgetc(fp),stdout);
  fclose(fp);
}