Example #1
0
static void rawstream_ensure_headers_sent(full_subscriber_t *fsub) {
  ngx_http_request_t             *r = fsub->sub.request;
  //nchan_request_ctx_t            *ctx = ngx_http_get_module_ctx(r, ngx_nchan_module);
  
  if(!fsub->data.shook_hands) {
    nchan_cleverly_output_headers_only_for_later_response(r);
    fsub->data.shook_hands = 1; 
  }
}
Example #2
0
static void chunked_ensure_headers_sent(full_subscriber_t *fsub) {
  static ngx_str_t         transfer_encoding_header = ngx_string("Transfer-Encoding");
  static ngx_str_t         transfer_encoding = ngx_string("chunked");
  
  ngx_http_request_t             *r = fsub->sub.request;
  ngx_http_core_loc_conf_t       *clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module);
  if(!fsub->data.shook_hands) {
  
    clcf->chunked_transfer_encoding = 0;
    
    //r->headers_out.content_type.len = content_type.len;
    //r->headers_out.content_type.data = content_type.data;
    
    nchan_add_response_header(r, &transfer_encoding_header, &transfer_encoding);
    
    nchan_cleverly_output_headers_only_for_later_response(r);
    
    fsub->data.shook_hands = 1; 
  }
}
static void multipart_ensure_headers_sent(full_subscriber_t *fsub) {
  nchan_buf_and_chain_t          *bc;
  
  ngx_http_request_t             *r = fsub->sub.request;
  ngx_http_core_loc_conf_t       *clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module);
  nchan_request_ctx_t            *ctx = ngx_http_get_module_ctx(r, nchan_module);
  multipart_privdata_t           *mpd = (multipart_privdata_t *)fsub->privdata;
  
  if(!fsub->data.shook_hands) {
    clcf->chunked_transfer_encoding = 0;
    nchan_request_set_content_type_multipart_boundary_header(r, ctx);
    
    nchan_cleverly_output_headers_only_for_later_response(r);
    
    //set preamble in the request ctx. it would be nicer to store in in the subscriber data, 
    //but that would mean not reusing longpoll's fsub directly
    
    if((bc = nchan_bufchain_pool_reserve(ctx->bcp, 1)) == NULL) {
      ERR("can't reserve bufchain for multipart headers");
      nchan_respond_status(fsub->sub.request, NGX_HTTP_INTERNAL_SERVER_ERROR, NULL, 1);
      return;
    }
    
    ngx_memzero(&bc->buf, sizeof(ngx_buf_t));
    bc->buf.start = mpd->boundary + 2;
    bc->buf.pos = bc->buf.start;
    bc->buf.end = mpd->boundary_end;
    bc->buf.last = bc->buf.end;
    bc->buf.memory = 1;
    bc->buf.last_buf = 0;
    bc->buf.last_in_chain = 1;
    bc->buf.flush = 1;
    
    nchan_output_filter(r, &bc->chain);
    
    fsub->data.shook_hands = 1; 
  }
}
Example #4
0
static void es_ensure_headers_sent(full_subscriber_t *fsub) {
  static const ngx_str_t   content_type = ngx_string("text/event-stream; charset=utf-8");
  static const ngx_str_t   hello = ngx_string(": hi\n\n");
  ngx_http_request_t             *r = fsub->sub.request;
  ngx_http_core_loc_conf_t       *clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module);
  nchan_buf_and_chain_t           bc;
  nchan_request_ctx_t            *ctx = ngx_http_get_module_ctx(r, nchan_module);
  nchan_loc_conf_t               *cf;
  
  if(!fsub->data.shook_hands) {
  
    clcf->chunked_transfer_encoding = 0;
    
    r->headers_out.content_type.len = content_type.len;
    r->headers_out.content_type.data = content_type.data;
    r->headers_out.content_length_n = -1;
    //send headers
    
    if(ctx->request_origin_header.len > 0) {
      cf = ngx_http_get_module_loc_conf(r, nchan_module);
      nchan_add_response_header(r, &NCHAN_HEADER_ALLOW_ORIGIN, &cf->allow_origin);
    }
    
    nchan_cleverly_output_headers_only_for_later_response(r);

    //send a ":hi" comment
    ngx_init_set_membuf(&bc.buf, hello.data, hello.data + hello.len);
    bc.chain.buf = &bc.buf;
    
    bc.buf.last_buf = 0;
    bc.buf.flush = 1;

    bc.chain.next = NULL;
    nchan_output_filter(fsub->sub.request, &bc.chain);
    
    fsub->data.shook_hands = 1; 
  }
}