<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Dereferenced.com &#187; HTTP</title>
	<atom:link href="http://www.dereferenced.com/topics/web/http/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.dereferenced.com</link>
	<description>A preponderance of Perl, an excess of XML, and additional alliterations.</description>
	<lastBuildDate>Sun, 29 Aug 2010 23:16:38 +0000</lastBuildDate>
	
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Perl Module Monday: HTTP Parsing Triple-Play</title>
		<link>http://www.dereferenced.com/2009/09/14/perl-module-monday-http-parsing-triple-play/</link>
		<comments>http://www.dereferenced.com/2009/09/14/perl-module-monday-http-parsing-triple-play/#comments</comments>
		<pubDate>Tue, 15 Sep 2009 05:09:31 +0000</pubDate>
		<dc:creator>rjray</dc:creator>
				<category><![CDATA[CPAN]]></category>
		<category><![CDATA[HTTP]]></category>
		<category><![CDATA[Perl]]></category>
		<category><![CDATA[module-monday]]></category>

		<guid isPermaLink="false">http://www.dereferenced.com/?p=54</guid>
		<description><![CDATA[For this week&#8217;s Module Monday, I&#8217;m going to break form a little bit and actually look at three modules. All of these address the same basic problem, which I wrote about yesterday: parsing HTTP messages.
Right after writing the previous post, I discovered (by means of my CPAN Twitter-bot) two other solutions to this problem, both [...]]]></description>
			<content:encoded><![CDATA[<p>For this week&#8217;s Module Monday, I&#8217;m going to break form a little bit and actually look at <em>three</em> modules. All of these address the same basic problem, which I <a href="http://www.dereferenced.com/2009/09/13/parsing-http-headers/">wrote about yesterday</a>: parsing HTTP messages.</p>
<p>Right after writing the previous post, I discovered (by means of my <a href="http://twitter.com/cpan_linked">CPAN Twitter-bot</a>) two other solutions to this problem, both using linked C/C++ code for speed. So let&#8217;s have a look at all of them:</p>
<ul>
<li><a href="http://search.cpan.org/dist/HTTP-Parser/">HTTP::Parser</a> is the first one I discovered, and the one I&#8217;ve stepped up to help maintain. It has a pretty straight-forward interface, but requires that the content be passed to it as strings (though it can handle incremental chunks). Unlike the code in HTTP::Daemon that I hope to eventually replace with this, it does not read directly from a socket or any other file-handle-like source. It uses integer return codes to signal when it is finished parsing a message, at which point you can retrieve a ready-to-use object that will be either a HTTP::Request or an HTTP::Response, depending on the message.</li>
<li><a href="http://search.cpan.org/dist/HTTP-Parser-XS/">HTTP::Parser::XS</a> is the one I discovered via the Twitter-bot, and is also the newest of the pack. <a href="http://bulknews.typepad.com/blog/">Tatsuhiko Miyagawa</a> took this and wrote a <a href="http://github.com/miyagawa/Plack/blob/5f68ec28d2c103d93e31097e249fc7ad18433c86/lib/Plack/HTTPParser/PP.pm">pure-Perl fallback</a>, then integrated them into <a href="http://github.com/miyagawa/Plack">Plack</a> (more on the overall Plack progress in <a href="http://bulknews.typepad.com/blog/2009/09/plack-standalone-and-apache2-support.html">this blog post</a>). The interface is a little unusual, compared to the more minimal approach of the previous option, in that it stuffs most of the information into environment variables in accordance with the <a href="http://github.com/miyagawa/psgi-specs/blob/master/PSGI.pod">PSGI</a> specification (though in this case it uses a hash-table which is passed by reference, rather than actual environment variables). Which is great for projects (like Plack) that are specifically built around PSGI, but may not be as great for more light-weight parsing needs. Also, being very new, the documentation is very spare. It also uses integer return-codes to signal progress, and the codes are very similar in nature to those used by HTTP::Parser (the meaning of -1 seems to differ).</li>
<li><a href="http://search.cpan.org/dist/HTTP-HeaderParser-XS/">HTTP::HeaderParser::XS</a> is the third of the set, and the one I discovered most-recently, as a result of a reference to it in the POD docs of the previous module. This one is over a year old, but seems to have just the one release. It is based on a C++ state-machine, and also offers only sparse documentation.</li>
</ul>
<p>So, as I move forward with making HTTP::Parser a more generally-useful piece of code, these are my competition and hopefully inspiration. I&#8217;d like to see the speed of XS code eventually, but would prefer to make PSGI support an option so that the code is useful in more contexts.</p>
<p>Suggestions always welcome!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.dereferenced.com/2009/09/14/perl-module-monday-http-parsing-triple-play/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Parsing HTTP Headers</title>
		<link>http://www.dereferenced.com/2009/09/13/parsing-http-headers/</link>
		<comments>http://www.dereferenced.com/2009/09/13/parsing-http-headers/#comments</comments>
		<pubDate>Mon, 14 Sep 2009 04:53:07 +0000</pubDate>
		<dc:creator>rjray</dc:creator>
				<category><![CDATA[CPAN]]></category>
		<category><![CDATA[GitHub]]></category>
		<category><![CDATA[HTTP]]></category>
		<category><![CDATA[Perl]]></category>

		<guid isPermaLink="false">http://www.dereferenced.com/?p=51</guid>
		<description><![CDATA[So, I&#8217;ve volunteered to co-maintain the HTTP::Parser CPAN module. I did this because I&#8217;ve been looking for something I can use in RPC::XML::Server instead of my current approach, which is to rely on the parsing capabilities built in to HTTP::Daemon. This is somewhat clumsy, and definitely over-kill; I only have to do this in cases [...]]]></description>
			<content:encoded><![CDATA[<p>So, I&#8217;ve volunteered to co-maintain the <a href="http://search.cpan.org/dist/HTTP-Parser/">HTTP::Parser</a> CPAN module. I did this because I&#8217;ve been looking for something I can use in <a href="http://search.cpan.org/dist/RPC-XML/lib/RPC/XML/Server.pm">RPC::XML::Server</a> instead of my current approach, which is to rely on the parsing capabilities built in to <a href="http://search.cpan.org/dist/libwww-perl/lib/HTTP/Daemon.pm">HTTP::Daemon</a>. This is somewhat clumsy, and definitely over-kill; I only have to do this in cases where the code is <em>not</em> already running under HTTP::Daemon or Apache. If the code is already using HTTP::Daemon, then it has its own <code>accept()</code> loop it can use, and if the code is running under Apache then the request object has already parsed the headers.</p>
<p>My need comes when the code is not in either of these environments, it has to be able to take the socket it gets from a typical TCP/IP-based <code>accept()</code> and read off the HTTP request. To avoid duplicating code, I trick the socket into thinking that it&#8217;s an instance of HTTP::Daemon::ClientConn, which is itself just a GLOB that&#8217;s been blessed into that namespace for the sake of calling methods. So it works. But it makes the code dependent on having HTTP::Daemon loaded, even when the user is not utilising that class for the daemon functionality of the server. I&#8217;ve needed to drop this for a while, now.</p>
<p>(I&#8217;m not impugning HTTP::Daemon or the <a href="http://search.cpan.org/dist/libwww-perl/">libwww-perl</a> package itself&#8211; both are excellent and I utilise them extensively within this module. But if you are not running your RPC server under HTTP::Daemon, then you probably would prefer to not have that code in memory since you aren&#8217;t really using it.)</p>
<p>Thing is, you can use the request and response objects without having to load the user-agent or daemon classes. But there isn&#8217;t an easy, clean way to use just the header-parsing part of the code by itself. The ClientConn class has a <code>get_request()</code> method that can be instructed to parse only the headers and return the HTTP::Request object without the body filled in. The content of the request can then be read off of the socket/object with sysread(). This is why I use the minor hack that I do.</p>
<p>What I <em>want</em> to do, is be able to do this parsing-out of headers without the ugly hack, without loading all of HTTP::Daemon just so I can call one subroutine (albeit 200+ lines of subroutine). (And to be fair, I also call the <code>read_buffer()</code> routine after the header has been read, to get any content that was already read but not part of the header.) So I came across HTTP::Parser. It has a lot of promise, but it&#8217;s not <em>quite</em> where I need it to be. For one thing, it won&#8217;t stop at just parsing the headers. This is something I need, for cases where the user wants to spool larger elements of a message to disk or for handling compressed content. But most of all, it seemed to not be in active maintenance&#8211; there were two bugs in <a href="http://rt.cpan.org">RT</a> that had been sitting there, with patches provided, for over a year.</p>
<p>Fortunately, an e-mail to the author let me offer to help out, and he accepted. The code was not in any repository, so I set up a repo on GitHub for it <a href="http://github.com/rjray/http-parser">here</a>, and seeded it with the four CPAN releases so that there would be something of a history to fall back on. I&#8217;ve applied the patches (well, applied one, and implemented the other with a better solution) and pushed the changes.</p>
<p>Now, I have to decide how to move forward with this, how to make it as efficient (or more so) than the code in HTTP::Daemon, how to make it into something I can use in RPC::XML::Server to eliminate the unsightly hack I have to rely on currently.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.dereferenced.com/2009/09/13/parsing-http-headers/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>
