[EMAIL PROTECTED] (Philippe 'BooK' Bruhat) writes:

> So, should expect hop-by-hop headers to look like:
> 
>    Connection: Foo, Bar
>    Foo: This is the foo hop-by-hop header
>    Bar: This is the bar hop-by-hop header
> 
> or more like:
> 
>    Connection: Foo
>    Foo: This is the foo hop-by-hop header
>    Connection: Bar
>    Bar: This is the bar hop-by-hop header
> 
> ?

Both are legal as far as I can tell.  Most sane implementation would
probably generate the first.

> In the first case, this means that I cannot count on HTTP::Headers to
> do the splitting for me in list context, but that I should split on
> ',' myself.

The HTTP::Headers::Util::split_header_words() function should do the
right thing for you:

  split_header_words($r->header("Connection"));

> Is it ok for me to do something like the following:
> 
>     # hop-by-hop headers are set aside
>     my $hop = HTTP::Headers->new();
>     for ( qw( Connection Keep-Alive Proxy-Authenticate Proxy-Authorization 
>         TE Trailers Transfer-Encoding Upgrade Proxy-Connection Public ) ) {
>         if( $message->headers->header($_) ) {

You can drop "->headers" here I think.  At least if $message is an
HTTP::Message or some subclass.

>             $hop->header( $_ => $message->headers->header($_) );

You would have to make it

  $hop->header( $_ => [$message->headers->header($_)] )

to deal with multivalued fields correctly.

>             $headers->remove_header($_);
>         }
>     }
>     # new hop-by-hop headers (in the Connection: header)
>     for (map { split /\s*,\s*/ } $hop->header( 'Connection' ) ) {

I would use split_header_words() here.

>         if( $message->headers->header($_) ) {
>             $hop->header( $_ => $message->headers->header($_) );
>             $headers->remove_header($_);
>         }
>     }

I would probably implement this with a hash initialized with the know
hop-by-hop headers and then suplemented with the Connection headers.
Then I would use $message->scan() to walk though the headers and then
copy them to either $hop or $headers depending of hits in this h2h
hash.

Regards,
Gisle

Reply via email to