Skip to content

Instantly share code, notes, and snippets.

/fast.diff Secret

Created February 10, 2016 21:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/24ebc6cf3d349126c5b2 to your computer and use it in GitHub Desktop.
Save anonymous/24ebc6cf3d349126c5b2 to your computer and use it in GitHub Desktop.
diff --git a/lib/Mojo/Headers.pm b/lib/Mojo/Headers.pm
index 320d4a4..1004eee 100644
--- a/lib/Mojo/Headers.pm
+++ b/lib/Mojo/Headers.pm
@@ -20,9 +20,20 @@ my %NORMALCASE = map { lc() => $_ } (
qw(Upgrade User-Agent Vary WWW-Authenticate)
);
for my $header (values %NORMALCASE) {
- my $name = lc $header;
+ my $name = my $key = lc $header;
$name =~ y/-/_/;
- monkey_patch __PACKAGE__, $name, sub { shift->header($header => @_) };
+ monkey_patch __PACKAGE__, $name, sub {
+ my $self = shift;
+
+ unless (@_) {
+ return undef unless my $headers = $self->{headers}{$key};
+ return join ', ', @$headers;
+ }
+
+ $self->{normalcase}{$key} //= $name unless $NORMALCASE{$key};
+ $self->{headers}{$key} = [@_];
+ return $self;
+ };
}
sub add {
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment