AnyEvent-HTTPD-SendMultiHeaderPatch

 view release on metacpan or  search on metacpan

lib/AnyEvent/HTTPD/SendMultiHeaderPatch.pm  view on Meta::CPAN

                         # because the patch module will use it first.
    use AnyEvent::HTTPD::SendMultiHeaderPatch;

    # In the http request handler,
    # separate the multiple values of the same field with \0 character.
    sub {
        my($httpd, $req) = @_;
        # ...
        $req->respond(
            200, 'OK', {
                'Set-Cookie' => "a=123; path=/; domain=.example.com\0b=456; path=/; domain=.example.com"
            }, "Set the cookies"
        );
    }

    # Or use the added util function header_add in AnyEvent::HTTPD::Util.
    use AnyEvent::HTTPD::Util;

    sub {
        my($httpd, $req) = @_;
        # ...
        my %header;
        header_add(\%header, 'Set-Cookie', 'a=123; path=/; domain=.example.com');
        header_add(\%header, 'Set-Cookie', 'b=456; path=/; domain=.example.com');
        $req->respond(200, 'OK', \%header, "Set the cookies");
    }

    # There also introduced another util function header_gets in AnyEvent::HTTPD::Util,
    # to extract multiple values in the header
    sub {
        my($httpd, $req) = @_;
        # ...
        my %header;
        header_add(\%header, 'Example', 'a');



( run in 0.886 second using v1.01-cache-2.11-cpan-e9199f4ba4c )