<?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>House of Metnetsky &#187; http</title>
	<atom:link href="http://cowarthill.com/blog/index.php/tag/http/feed/" rel="self" type="application/rss+xml" />
	<link>http://cowarthill.com/blog</link>
	<description>Run Tortoise Run</description>
	<lastBuildDate>Fri, 26 Feb 2010 17:15:33 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Mono + SCGI</title>
		<link>http://cowarthill.com/blog/index.php/2009/06/10/mono-scgi/</link>
		<comments>http://cowarthill.com/blog/index.php/2009/06/10/mono-scgi/#comments</comments>
		<pubDate>Wed, 10 Jun 2009 21:46:13 +0000</pubDate>
		<dc:creator>MET</dc:creator>
				<category><![CDATA[programming]]></category>
		<category><![CDATA[.net]]></category>
		<category><![CDATA[http]]></category>
		<category><![CDATA[mono]]></category>
		<category><![CDATA[scgi]]></category>

		<guid isPermaLink="false">http://cowarthill.com/blog/?p=267</guid>
		<description><![CDATA[Over a year ago I started a SCGI daemon for Mono (scgi-mono-server). For those who don&#8217;t know, the &#8220;SCGI protocol is a replacement for the Common Gateway Interface (CGI) protocol. It is a standard for applications to interface with HTTP servers. It is similar to FastCGI but is designed to be easier to implement&#8221;.I stopped [...]]]></description>
			<content:encoded><![CDATA[<div>Over a year ago I started a <a title="http://python.ca/scgi/protocol.txt" href="http://" target="_blank">SCGI</a> daemon for <a title="http://www.mono-project.com/" href="http://" target="_blank">Mono</a> (scgi-mono-server). For those who don&#8217;t know, the <a href="http://www.mems-exchange.org/software/scgi" target="_blank">&#8220;SCGI protocol is a replacement for the Common Gateway Interface (CGI) protocol. It is a standard for applications to interface with HTTP servers. It is similar to FastCGI but is designed to be easier to implement&#8221;</a>.I stopped all development shortly after I started because <a href="http://www.lighttpd.net/" target="_blank">lighttpd</a> (the web server I cared about) required a very small patch to be useful. Having supplied the <a href="http://redmine.lighttpd.net/projects/lighttpd/repository/revisions/2223/diff/branches/lighttpd-1.4.x/src/mod_scgi.c" target="_blank">patch</a> I waited around for it to be rolled into a release (<a href="http://www.lighttpd.net/2008/9/30/1-4-20-Otherwise-the-terrorists-win" target="_blank">1.4.20</a>) and then waited for it to be picked up by <a href="http://packages.ubuntu.com/search?keywords=lighttpd&amp;searchon=names&amp;suite=jaunty&amp;section=all" target="_blank">Ubuntu</a>, but it still hasn&#8217;t. So what brought it back to life? A silly bug: <a href="https://bugs.launchpad.net/ubuntu/+source/mod-mono/+bug/227781" target="_blank">https://bugs.launchpad.net/ubuntu/+source/mod-mono/+bug/227781</a>.</div>
<p>Some of our servers need both PHP5 &amp; Mono to run side-by-side so one of our guys listed the options:</p>
<div>
<ul>
<li dir="ltr">Pull mono &amp; <a href="http://www.mono-project.com/Mod_mono" target="_blank">mod-mono</a> 1.9.1 back-ports from a <a href="https://launchpad.net/ubuntu/+ppas" target="_blank">PPA</a> (<a href="http://ppa.launchpad.net/directhex/ppa/ubuntu">http://ppa.launchpad.net/directhex/ppa/ubuntu</a>)</li>
<li dir="ltr">Patch and rebuild <a href="http://www.mono-project.com/Mod_mono" target="_blank">mod-mono</a> 1.2.5 ourselves</li>
<li dir="ltr">Switch to <a href="http://en.wikipedia.org/wiki/FastCGI" target="_blank">FastCGI</a> for PHP5, so we can use apache2-mpm-worker for mod-mono-server</li>
<li dir="ltr">Switch from Apache to lighttpd (and rebuild with our patch)</li>
<li dir="ltr">Switch from Apache + mod-mono to Apache + FastCGI or SCGI (requires patching lighttpd)</li>
<li dir="ltr">Switch from Apache + mod-mono to Apache + mod_proxy for <a href="http://www.mono-project.com/ASP.NET#ASP.NET_hosting_with_XSP" target="_blank">XSP</a></li>
</ul>
<p>Given our growing dislike for Apache &amp; appreciation for lighttpd we decided on a phased approach:</p>
<ul>
<li dir="ltr">Switch PHP5 to Apache + <a href="http://en.wikipedia.org/wiki/FastCGI" target="_blank">FastCGI</a></li>
<li dir="ltr">Switch Mono to Apache + SCGI</li>
<li dir="ltr">Run for a while (make sure everything works well)</li>
<li dir="ltr">Switch from Apache to lighttpd</li>
</ul>
<p>We choose SCGI for Mono over <a href="http://en.wikipedia.org/wiki/FastCGI" target="_blank">FastCGI</a> because:</p>
<ul>
<li dir="ltr">FastCGI requires a lot of chatter between the client &amp; server</li>
<li dir="ltr">Great incentive to finally give the server to Mono</li>
</ul>
<p>With our approach in mind I started working on scgi-mono-server again, but with a new target &#8211; Apache. This shouldn&#8217;t have been very hard given that mod_scgi is provided by <strong>Quixote</strong>, but there were a few stumbling blocks. Apache, for whatever reason, has decided to break the SCGI specification (in my eyes).  As stated in the <strong>Protocol</strong>: &#8220;[t]he format of the response is not specified&#8221; &#8211; meaning whatever the SCGI server sends back to the client (Apache, lighttpd, etc) should go back to the originator (web browser). Apache however, does not honor this. </p>
<p>The first line of any HTTP response (AFAIK) should be it&#8217;s <em>Status Line</em>:</p>
<p><strong>HTTP/1.1 200 OK</strong>.</p>
<p>Apache&#8217;s mod_scgi requires that all lines until the body have a colon so that is can parse the header and update it&#8217;s internal data model. Therefore, our first line now has to be replaced by:</p>
<p><strong>Status: 200 OK</strong></p>
<p>Thankfully the <strong>Example</strong> section of the protocol showed me how to <strong><em>fix the issue</em></strong>. I&#8217;m tempted to patch Apache/mod_scgi but I&#8217;m a bit worried about how many SCGI servers require this broken code. So for now I&#8217;ve added a configuration option that can be put inside ASP.NET&#8217;s web.config to control the <strong><em>hack</em></strong>:</p>
<pre class="brush: xml; title: ; notranslate">
&lt;appSettings&gt;
	&lt;add key=&quot;MonoServerApacheStatus&quot; value=&quot;true&quot; /&gt;
&lt;/appSettings&gt;
</pre>
<p>I&#8217;ll be submitting the server back to Mono with some documentation after it goes through some solid developer testing on our side &#8211; so I hope someone enjoys!</p>
</div>
]]></content:encoded>
			<wfw:commentRss>http://cowarthill.com/blog/index.php/2009/06/10/mono-scgi/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PHP Annoyances: header()</title>
		<link>http://cowarthill.com/blog/index.php/2009/02/10/php-annoyances-header/</link>
		<comments>http://cowarthill.com/blog/index.php/2009/02/10/php-annoyances-header/#comments</comments>
		<pubDate>Wed, 11 Feb 2009 04:04:23 +0000</pubDate>
		<dc:creator>MET</dc:creator>
				<category><![CDATA[programming]]></category>
		<category><![CDATA[flex]]></category>
		<category><![CDATA[http]]></category>
		<category><![CDATA[kmbs]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://cowarthill.com/blog/?p=138</guid>
		<description><![CDATA[Earlier today, and yesterday in fact, I was successfully downloading generated PDF&#8217;s from a FLEX application from an Apache2 server via mod_php5. Tonight however, it kept failing with an IOErrorEvent #2038. There&#8217;s lots of fun references to this issue like this one. Sadly downloading via FileReference doesn&#8217;t trigger the HTTPStatusEvent event, so I can&#8217;t lie [...]]]></description>
			<content:encoded><![CDATA[<p>Earlier today, and yesterday in fact, I was successfully downloading generated PDF&#8217;s from a FLEX application from an Apache2 server via mod_php5. Tonight however, it kept failing with an IOErrorEvent #2038. There&#8217;s lots of fun references to this issue like this <a target="_blank">one</a>. Sadly downloading via FileReference doesn&#8217;t trigger the HTTPStatusEvent event, so I can&#8217;t lie to FLEX.</p>
<p>I eventually stopped brute forcing an attempt and intelligently looked at Apache2&#8242;s logs and found this wonderful line:</p>
<p><em style="font-size:6">10.10.220.130 &#8211; - [10/Feb/2009:20:24:16 -0500] &#8220;GET /vrm/Create_Report.php?download=vrm_report_17_10-10-220-130.pdf HTTP/1.1&#8243; 1 68856 &#8220;-&#8221; &#8220;Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; &#8230;)&#8221;</em></p>
<p>Do you notice whats wrong? No? Look for the 1 after &#8220;HTTP/1.1&#8243; and before the &#8220;68856&#8243; &#8211; this is where the HTTP Status Code should be. Eh? What happened? Where&#8217;d my status go? The server-side looked like this:</p>
<pre class="brush: php; title: ; notranslate">
if (file_exists($file)) {
	header('Content-Type', 'application/octet-stream', true);
	header('Content-Disposition', 'attachment/filename=' . $filename, true);
	header('Content-Length', filesize($file), true);
	header('Content-Description', 'File Transfer');
	readfile($file);
}
</pre>
<p>Any one notice the issue &#8211; header is being use inappropriately. The first argument should be the entire response header, the second argument is the option to override a matching header, and the third is the status code. &#8220;true&#8221; evaluates &#8220;1&#8243; and thus the status of 1. You might ask as I am right now: Why is he divulging that he&#8217;s an idiot? Well folks it goes like this:</p>
<p>It&#8217;s 10:55PM and I&#8217;ve been programming since 8:30AM to meet a deadline. Things get missed and stupid mistakes happen. The above code worked on (IIS 6 + PHP5) but failed on (Apache2 + PHP5) &#8211; and this is one of the many reasons I hate PHP. The second argument should be a boolean and should SCREAM to the error log if you don&#8217;t match the type expected. Instead it says nothing, and leaves you to your madness.</p>
<p>Anyways, lets fix the code and go home!</p>
<pre class="brush: php; title: ; notranslate">
	header('Content-Type: application/octet-stream', true, 200);
	header('Content-Disposition: attachment/filename=' . $filename, true);
	header('Content-Length: ' . filesize($file), true);
	header('Content-Description: File Transfer');
</pre>
<p><em style="font-size:8">10.10.220.130 &#8211; - [10/Feb/2009:22:14:15 -0500] &#8220;GET /vrm/Create_Report.php?download=vrm_report_1_10-10-220-130.pdf HTTP/1.1&#8243; 200 68856 &#8220;-&#8221; &#8220;Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; &#8230;)&#8221;</em></p>
<p>Gah ;-0</p>
]]></content:encoded>
			<wfw:commentRss>http://cowarthill.com/blog/index.php/2009/02/10/php-annoyances-header/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Internet Explorer Quirks: 204</title>
		<link>http://cowarthill.com/blog/index.php/2008/12/02/internet-explorer-quirks-204/</link>
		<comments>http://cowarthill.com/blog/index.php/2008/12/02/internet-explorer-quirks-204/#comments</comments>
		<pubDate>Wed, 03 Dec 2008 00:50:11 +0000</pubDate>
		<dc:creator>MET</dc:creator>
				<category><![CDATA[programming]]></category>
		<category><![CDATA[http]]></category>
		<category><![CDATA[ie7]]></category>
		<category><![CDATA[kmbs]]></category>
		<category><![CDATA[printgroove]]></category>

		<guid isPermaLink="false">http://cowarthill.com/blog/?p=52</guid>
		<description><![CDATA[A long time ago when I first started doing a lot of REST + Ajax developement I hit a really strange issue. Apparently, if your server returns a HTTP Status code of 204 in response to a POST method IE partially blows up. Part of this has to do with IE requiring try/catch blocks around [...]]]></description>
			<content:encoded><![CDATA[<p>A long time ago when I first started doing a lot of REST + Ajax developement I hit a really strange issue. Apparently, if your server returns a HTTP Status code of 204 in response to a POST method IE partially blows up. Part of this has to do with IE requiring try/catch blocks around code that could be devastating &#8211; like XMLHttpRequest.send()? And part of it has to do with IE not parsing a 204 response.</p>
<p>Upon receipt of 204 IE appears to halt parsing as the XMLHttpRequest instance becomes corrupt and is no longer usable. Checking true/false against the instance works (and is false), but querying a method or variable from the instance produces an error.</p>
<pre class="brush: jscript; title: ; notranslate">
var xhr = null;

try {
    // without try/catch IE throws error for no good reason
    xhr = new Ajax.Request(url, options);
} catch (exe) {
    /* will never fail on IE for 204 */
    console.error(exe);
}

// xhr is invalid for IE + POST + 204
if (xhr) {
    resp = xhr.transport;
} else if (/^post$/i.test(method) &amp;&amp; this.isInternetExplorer()) {
    resp = this.FAKE_204_RESPONSE();
}
</pre>
<p>I vaguely remember reading on some site that IE fails on POST + 204 because it helps the browser short circuit and keep from redrawing the interface from a &lt;form/&gt; submission. This <strong><em>sort of</em></strong> makes sense because you can then upload/POST form data without having to redraw the page and still know if everything succeeded.</p>
<p>Either way, it is truly annoying. And the only reason I&#8217;m evening posting about this, other than education and helping myself remember, is that my original comments around the code above was vulgar. It happened to have been 3AM or so and my polite-o-meter wasn&#8217;t working well. It is now almost three years later and I believe some people have seen the original comments and didn&#8217;t find it appropriate &#8211; to which they are correct.</p>
<p>With that said &#8211; Internet Explorer has some weird quirks.</p>
]]></content:encoded>
			<wfw:commentRss>http://cowarthill.com/blog/index.php/2008/12/02/internet-explorer-quirks-204/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

