]> Dogcows Code - chaz/p5-HTTP-AnyUA/blobdiff - lib/HTTP/AnyUA/Util.pm
add middleware
[chaz/p5-HTTP-AnyUA] / lib / HTTP / AnyUA / Util.pm
index 580b850ddefc951d32bc744808404c421339332f..3729c56e45029257864f73e00232132e85f5ce24 100644 (file)
@@ -1,5 +1,5 @@
 package HTTP::AnyUA::Util;
-# ABSTRACT: Utility subroutines for HTTP::AnyUA backends
+# ABSTRACT: Utility subroutines for HTTP::AnyUA backends and middleware
 
 use warnings;
 use strict;
@@ -13,6 +13,7 @@ our @EXPORT_OK = qw(
     http_headers_to_native
     native_to_http_request
     coderef_content_to_string
+    normalize_headers
     internal_exception
     http_date
     parse_http_date
@@ -102,6 +103,28 @@ sub http_headers_to_native {
     return $native;
 }
 
+=func normalize_headers
+
+    $normalized_headers = normalize_headers(\%headers);
+
+Normalize headers. Currently lowercases header keys.
+
+=cut
+
+sub normalize_headers {
+    my $headers_in = shift;
+
+    my $headers = {};
+
+    if (defined $headers_in) {
+        while (my ($key, $value) = each %{$headers_in || {}}) {
+            $headers->{lc($key)} = $value;
+        }
+    }
+
+    return $headers;
+}
+
 =func internal_exception
 
     $response = internal_exception($content);
This page took 0.0174 seconds and 4 git commands to generate.