| 1 | package HTTP::Engine::Role::RequestBuilder::Standard; | ||
| 2 | use Any::Moose '::Role'; | ||
| 3 | |||
| 4 | use Socket qw[AF_INET inet_aton]; | ||
| 5 | |||
| 6 | with qw(HTTP::Engine::Role::RequestBuilder); | ||
| 7 | use CGI::Simple::Cookie (); | ||
| 8 | |||
| 9 | sub _build_cookies { | ||
| 10 | my($self, $req) = @_; | ||
| 11 | |||
| 12 | if (my $header = $req->header('Cookie')) { | ||
| 13 | return { CGI::Simple::Cookie->parse($header) }; | ||
| 14 | } else { | ||
| 15 | return {}; | ||
| 16 | } | ||
| 17 | } | ||
| 18 | |||
| 19 | sub _build_hostname { | ||
| 20 | my ( $self, $req ) = @_; | ||
| 21 | gethostbyaddr( inet_aton( $req->address ), AF_INET ); | ||
| 22 | } | ||
| 23 | |||
| 24 | # for win32 hacks | ||
| 25 | BEGIN { | ||
| 26 | if ($^O eq 'MSWin32') { | ||
| 27 | no warnings 'redefine'; | ||
| 28 | *_build_hostname = sub { | ||
| 29 | my ( $self, $req ) = @_; | ||
| 30 | my $address = $req->address; | ||
| 31 | return 'localhost' if $address eq '127.0.0.1'; | ||
| 32 | return gethostbyaddr( inet_aton( $address ), AF_INET ); | ||
| 33 | }; | ||
| 34 | } | ||
| 35 | } | ||
| 36 | |||
| 37 | 1; |