Не сохраняются cookie из http-обработчика

Sergey S. neavirc at gmail.com
Wed Mar 26 18:52:02 MSK 2008


Здравствуйте.

Почему-то не получается сохранить cookie из http-обработчика. Не подскажите,
где ошибка?

Сам обработчик:

static ngx_int_t ngx_http_test_handler(ngx_http_request_t *r)
{
  ngx_table_elt_t** raw_cookies =
static_cast<ngx_table_elt_t**>(r->headers_in.cookies.elts);
  cout << stdstr(raw_cookies[0]->value) << endl; // stdstr() конвертирует
ngx_str_t в std::string

  ngx_table_elt_t* set_cookie =
static_cast<ngx_table_elt_t*>(ngx_list_push(&r->headers_out.headers));
  set_cookie->hash = 1;
  set_cookie->key.len = sizeof("Set-Cookie") - 1;
  set_cookie->key.data =
(u_char*)"Set-Cookie";


  set_cookie->value.len = sizeof("foobar") - 1;
  set_cookie->value.data = (u_char*)"foobar"; // этот cookie не будет
сохранен у клиента

  ngx_http_send_header(r);

  return NGX_OK;
}

Устанавливается обработчик так:

static ngx_command_t  ngx_http_test_commands[] = {

    { ngx_string("test"),
      NGX_HTTP_LOC_CONF|NGX_CONF_NOARGS,
      ngx_http_test_install_handler,
      NGX_HTTP_LOC_CONF_OFFSET,
      0,
      NULL },
      // ...
      ngx_null_command
}

static char* ngx_http_test_install_handler(ngx_conf_t *cf, ngx_command_t
*cmd, void *conf)
{
  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));
  clcf->handler =
ngx_http_test_handler;


  return NGX_CONF_OK;
}

nginx 0.6.29

Спасибо.

--
С уважением,
Сергей Самохин.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://nginx.org/pipermail/nginx-ru/attachments/20080326/a1fd9930/attachment.html>


More information about the nginx-ru mailing list