Commit 990acc30 authored by Wandenberg's avatar Wandenberg

change padding on eventsource mode to be a comment instead of a CRLF

parent 5c80c3f4
......@@ -242,6 +242,7 @@ struct ngx_http_push_stream_shm_data_s {
ngx_shm_zone_t *ngx_http_push_stream_global_shm_zone = NULL;
ngx_str_t **ngx_http_push_stream_module_paddings_chunks = NULL;
ngx_str_t **ngx_http_push_stream_module_paddings_chunks_for_eventsource = NULL;
// channel
static ngx_int_t ngx_http_push_stream_send_response_all_channels_info_summarized(ngx_http_request_t *r);
......
......@@ -380,7 +380,38 @@ ngx_http_push_stream_postconfig(ngx_conf_t *cf)
ngx_conf_log_error(NGX_LOG_ERR, cf, 0, "push stream module: unable to allocate memory to create padding messages");
return NGX_ERROR;
}
padding->data = aux->data;
padding->data = &aux->data[aux->len - len];
padding->len = len;
len = i * 100;
}
}
if ((ngx_http_push_stream_padding_max_len > 0) && (ngx_http_push_stream_module_paddings_chunks_for_eventsource == NULL)) {
ngx_uint_t steps = ngx_http_push_stream_padding_max_len / 100;
if ((ngx_http_push_stream_module_paddings_chunks_for_eventsource = ngx_palloc(cf->pool, sizeof(ngx_str_t) * (steps + 1))) == NULL) {
ngx_conf_log_error(NGX_LOG_ERR, cf, 0, "push stream module: unable to allocate memory to create padding messages for eventsource");
return NGX_ERROR;
}
u_int padding_max_len = ngx_http_push_stream_padding_max_len + ((ngx_http_push_stream_padding_max_len % 2) ? 1 : 0);
ngx_str_t *aux = ngx_http_push_stream_create_str(cf->pool, padding_max_len);
if (aux == NULL) {
ngx_conf_log_error(NGX_LOG_ERR, cf, 0, "push stream module: unable to allocate memory to create padding messages value");
return NGX_ERROR;
}
ngx_memset(aux->data, ':', padding_max_len);
padding_max_len -= 2;
ngx_memcpy(aux->data + padding_max_len, CRLF, 2);
ngx_int_t i, len = ngx_http_push_stream_padding_max_len;
for (i = steps; i >= 0; i--) {
ngx_str_t *padding = ngx_pcalloc(cf->pool, sizeof(ngx_str_t));
if ((*(ngx_http_push_stream_module_paddings_chunks_for_eventsource + i) = padding) == NULL) {
ngx_conf_log_error(NGX_LOG_ERR, cf, 0, "push stream module: unable to allocate memory to create padding messages");
return NGX_ERROR;
}
padding->data = &aux->data[aux->len - len];
padding->len = len;
len = i * 100;
}
......
......@@ -648,11 +648,14 @@ static ngx_int_t
ngx_http_push_stream_send_response_padding(ngx_http_request_t *r, size_t len, ngx_flag_t sending_header)
{
ngx_http_push_stream_module_ctx_t *ctx = ngx_http_get_module_ctx(r, ngx_http_push_stream_module);
ngx_http_push_stream_loc_conf_t *pslcf = ngx_http_get_module_loc_conf(r, ngx_http_push_stream_module);
ngx_flag_t eventsource = (pslcf->location_type == NGX_HTTP_PUSH_STREAM_SUBSCRIBER_MODE_EVENTSOURCE);
if (ctx->padding != NULL) {
ngx_int_t diff = ((sending_header) ? ctx->padding->header_min_len : ctx->padding->message_min_len) - len;
if (diff > 0) {
ngx_str_t *padding = *(ngx_http_push_stream_module_paddings_chunks + diff / 100);
ngx_int_t padding_index = diff / 100;
ngx_str_t *padding = eventsource ? ngx_http_push_stream_module_paddings_chunks_for_eventsource[padding_index] : ngx_http_push_stream_module_paddings_chunks[padding_index];
ngx_http_push_stream_send_response_text(r, padding->data, padding->len, 0);
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment