Здравствуйте.<br><br>Почему-то не получается сохранить cookie из http-обработчика. Не подскажите, где ошибка?<br><br>Сам обработчик:<br><br>static ngx_int_t ngx_http_test_handler(ngx_http_request_t *r)<br>{<br> ngx_table_elt_t** raw_cookies = static_cast<ngx_table_elt_t**>(r->headers_in.cookies.elts);<br>
cout << stdstr(raw_cookies[0]->value) << endl; // stdstr() конвертирует ngx_str_t в std::string<br><br> ngx_table_elt_t* set_cookie = static_cast<ngx_table_elt_t*>(ngx_list_push(&r->headers_out.headers));<br>
set_cookie->hash = 1;<br> set_cookie->key.len = sizeof("Set-Cookie") - 1;<br> set_cookie->key.data = (u_char*)"Set-Cookie"; <br>
<br> set_cookie->value.len = sizeof("foobar") - 1;<br> set_cookie->value.data = (u_char*)"foobar"; // этот cookie не будет сохранен у клиента<br><br> ngx_http_send_header(r);<br><br> return NGX_OK;<br>
}<br><br>Устанавливается обработчик так:<br><br>static ngx_command_t ngx_http_test_commands[] = {<br><br> { ngx_string("test"),<br> NGX_HTTP_LOC_CONF|NGX_CONF_NOARGS,<br> ngx_http_test_install_handler,<br>
NGX_HTTP_LOC_CONF_OFFSET,<br> 0,<br> NULL },<br> // ...<br> ngx_null_command<br>}<br> <br>static char* ngx_http_test_install_handler(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)<br>{<br> ngx_http_core_loc_conf_t* clcf = static_cast<ngx_http_core_loc_conf_t*>(ngx_http_conf_get_module_loc_conf(cf, ngx_http_core_module));<br>
clcf->handler = ngx_http_test_handler; <br><br> return NGX_CONF_OK;<br>
}<br><br>nginx 0.6.29<br><br>Спасибо.<br><br>--<br>С уважением,<br>Сергей Самохин.<br>