NAME
HTTP::XSHeaders - Fast XS Header library, replacing HTTP::Headers and HTTP::Headers::Fast.
VERSION
Version 0.200000
SYNOPSIS
# load once
use HTTP::XSHeaders;
# keep using HTTP::Headers or HTTP::Headers::Fast as you wish
ALPHA RELEASE
This is a work in progress. Once we feel it is stable, the version will be bumped to 1.0. Until then, feel free to use and try and submit tickets, but do this at your own risk.
DESCRIPTION
By loading HTTP::XSHeaders anywhere, you replace any usage of HTTP::Headers and HTTP::Headers::Fast with a fast C implementation.
You can continue to use HTTP::Headers and HTTP::Headers::Fast and any other module that depends on them just like you did before. It's just faster now.
WHY
First there was HTTP::Headers. It's good, stable, and ubiquitous. However, it's slow.
Along came HTTP::Headers::Fast. Gooder, stable, and used internally by Plack, so you know it means business.
Not fast enough, we implemented an XS version of it, released under the name HTTP::Headers::Fast::XS. It was a successful experiment. However, we thought we could do better.
HTTP::XSHeaders provides a complete rework of the headers library with the intent of being fast, lean, and clear. It does not attempt to implement the original algorithm, but instead uses its own C-level implementation with an interface that is mostly compatible with both HTTP::Headers and HTTP::Headers::Fast.
This module attempts to replace HTTP::Headers
, HTTP::Headers::Fast
, and the XS imeplemntation of it, HTTP::Headers::Fast::XS
. We attempt to continue developing this module and perhaps deprecate HTTP::Headers::Fast::XS
.
COMPATIBILITY
While we keep compatibility with the interfaces of HTTP::Headers and HTTP::Headers::Fast, we've taken the liberty to make several changes that were deemed reasonable and sane:
Aligning in
as_string
methodas_string
method does weird stuff in order to keep the original indentation. This is unnecessary and unhelpful. We simply add one space as indentation after the first newline.No messing around in header names and casing
The headers are stored as given (
MY-HeaDER
staysMY-HeaDER
) and compared as lowercase. We do not uppercase or lowercase anything (other than for comparing header names internally).Case normalization using leading colon is not supported
Following the previous item, we also do not normalize based on leading colon.
$TRANSLATE_UNDERSCORE
is not supported$TRANSLATE_UNDERSCORE
(which controls whether underscores are translated or not) is not supported. It's barely documented (or isn't at all), it isn't used by anything on CPAN, nor can we find any use-case other than the tests. So, instead, we always convert underscores to dashes.Storable is loaded but not used
Both HTTP::Headers and HTTP::Headers::Fast use Storable for cloning. While
HTTP::Headers
loads it automatically,HTTP::Headers::Fast
loads it lazily.Since we override both, we load
Storable
always. However, we do not use it for cloning and instead implemented our C-level struct cloning.
BENCHMARKS
HTTP::Headers 6.05, HTTP::Headers::Fast 0.19, HTTP::XSHeaders 0.200000
-- as_string
Implementation Time
xsheaders 0.00468778222396934
fast 0.0964434631535363
orig 0.105793242864311
-- as_string_without_sort
Implementation Time
xsheaders_as_str 0.00475378949036912
xsheaders_as_str_wo 0.00484256407093758
fast_as_str 0.0954295831126767
fast_as_str_wo 0.0736790240349744
orig 0.105823918835043
-- get_content_length
Implementation Time
xsheaders 0.0105355231679
fast 0.0121647090348415
orig 0.0574727505777773
-- get_date
Implementation Time
xsheaders 0.077750453123065
fast 0.0826203668485442
orig 0.101090469267193
-- get_header
Implementation Time
xsheaders 0.00505807073565111
fast 0.0612525710276364
orig 0.0820842156588862
-- push_header
Implementation Time
xsheaders 0.00271070907120684
fast 0.0178986201816726
orig 0.0242003530752845
-- push_header_many
Implementation Time
xsheaders 0.00426636619488888
fast 0.0376390665501822
orig 0.0503843871625857
-- scan
Implementation Time
xsheaders 0.0142865143596716
fast 0.061759048917916
orig 0.0667217048891246
-- set_date
Implementation Time
xsheaders 0.114970609213125
fast 0.130542749562301
orig 0.168121156055091
-- set_header
Implementation Time
xsheaders 0.0456117003715809
fast 0.0868535344701981
orig 0.135920422020881
METHODS
These match the API described in HTTP::Headers and HTTP::Headers::Fast, with caveats described above in COMPATIBILITY.
new
Create a new object.
clone
Create a new object from this object's headers.
header
Get or set a header.
clear
Clears all headers.
push_header
Add a header value.
init_header
Initialize a header.
remove_header
Removes a header.
remove_content_headers
Removes all content headers.
as_string
Returns a sorted string representation of all headers.
as_string_without_sort
Returns a non-sorted string representation of all headers.
header_field_names
Returns all header field names.
scan
Apply a function to each header value.
content_type
Get the content type header.
content_type_charset
Get the content type charset header.
referer
Get or set the referer header.
referrer
Same as referer
but in proper English (unlike the HTTP spec).
AUTHORS
Gonzalo Diethelm
gonzus AT cpan DOT org
Sawyer X
xsawyerx AT cpan DOT org
THANKS
Rafaël Garcia-Suarez
p5pclub
1 POD Error
The following errors were encountered while parsing the POD:
- Around line 467:
You forgot a '=back' before '=head1'