NAME

HTTP::Headers::Fancy - Fancy naming schema of HTTP headers

VERSION

version 0.001

SYNOPSIS

my %fancy = decode_hash('content-type' => ..., 'x-foo-bar-baf-baz' => ...);
my $content_type = $fancy{ContentType};
my $x_foo_bar_baf_baz = $fancy{XFooBarBafBaz};

my %headers = encode_hash(ContentType => ..., x_foo_bar => ...);
# %headers = ('content-type' => ..., 'x-foo-bar' => ...);

DESCRIPTION

This module provides method for renaming HTTP header keys to a lightier, easier-to-use format.

FUNCTIONS

decode_key

Decode original HTTP header name

my $new = decode_key($old);

The header field name will be separated by the dash ('-') sign into pieces. Every piece will be lowercased and the first character uppercased. The pieces will be concatenated.

# Original -> Fancy
# Accept   Accept
# accept   Accept
# aCCEPT   Accept
# Acc-Ept  AccEpt
# Content-Type ContentType
# x-y-z    XYZ
# xyz      Xyz
# x-yz     XYz
# xy-z     XyZ

decode_hash

Decode a hash (or HashRef) of HTTP headers and rename the keys

my %new_hash = decode_hash(%old_hash);
my $new_hashref = decode_hash($old_hashref);

encode_key

Encode fancy key name to a valid HTTP header key name

my $new = encode_key($old);

Any uppercase (if not at beginning) will be prepended with a dash sign. Underscores will be replaced by a dash-sign too. The result will be lowercased.

# Fancy -> Original
# FooBar   foo-bar
# foo_bar  foo-bar
# FoOoOoF  fo-oo-oo-f

encode_hash

Encode a hash (or HashRef) of HTTP headers and rename the keys

Removes also a keypair if a value in undefined.

my %new_hash = encode_hash(%old_hash);
my $new_hashref = encode_hash($old_hashref);

BUGS

Please report any bugs or feature requests on the bugtracker website https://github.com/zurborg/libhttp-headers-fancy-perl/issues

When submitting a bug or request, please include a test-file or a patch to an existing test-file that illustrates the bug or desired feature.

AUTHOR

David Zurborg <zurborg@cpan.org>

COPYRIGHT AND LICENSE

This software is Copyright (c) 2015 by David Zurborg.

This is free software, licensed under:

The ISC License