Add new cookie into headers_in
Maxim Dounin
mdounin at mdounin.ru
Mon Jan 24 18:37:03 MSK 2011
Hello!
On Mon, Jan 24, 2011 at 10:07:04AM -0500, michalkraus wrote:
> Hello,
> I have a filter module in rewrite phase. The module tests if a cookie is
> in the request. If not the module generates one (if cookie is found the
> module modifies it) and then send it back to the client via
> headers_out.
> But I need one more functionality. I want the generated/modified cookie
> to be sent to the proxy module. I have used the headers_more_module for
> this purpose so far and it worked perfectly. I generate an
> $ap_filter_cookie_sid variable in my module that contains the cookie. I
> would like my module to be able to modify headers_in on its own.
> I have managed to modify existing cookie in the headers_in.headers. But
> when no cookie is in headers_in.headers my module is not able to store
> newly generated cookie to headers_in.headers. It seems OK in my module
> but before running proxy module the Nginx stops processing the request.
> When the first request contains a cookie the Nginx server processes it
> correctly and each next request (also withnou cookie) as well. This
> behaviour is a bit confusing and I have no idea how to fix it.
>From architecture point of view, you should never modify
r->headers_in. Instead, you should provide module output as
variable and use proxy_set_header to pass it to backend.
More specifically, modification of r->headers_in will fail and
cause SIGSEGV at least for subrequests even if done perfectly
correctly. Don't do that.
Maxim Dounin
More information about the nginx
mailing list