<?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>Pheromone Lab &#187; code</title>
	<atom:link href="http://lab.pheromone.ca/tag/code/feed/" rel="self" type="application/rss+xml" />
	<link>http://lab.pheromone.ca</link>
	<description>Inspiration, Experimentation, Innovation</description>
	<lastBuildDate>Mon, 30 Jan 2012 23:56:51 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Issues with bad implementations of &#8220;Accept&#8221; HTTP header</title>
		<link>http://lab.pheromone.ca/2009/11/16/http-accept-header-implementatio/</link>
		<comments>http://lab.pheromone.ca/2009/11/16/http-accept-header-implementatio/#comments</comments>
		<pubDate>Mon, 16 Nov 2009 21:37:55 +0000</pubDate>
		<dc:creator>karl</dc:creator>
				<category><![CDATA[Tech]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[firefox]]></category>
		<category><![CDATA[http]]></category>
		<category><![CDATA[implementation]]></category>
		<category><![CDATA[security]]></category>
		<category><![CDATA[server]]></category>

		<guid isPermaLink="false">http://lab.pheromone.ca/?p=182</guid>
		<description><![CDATA[<p>The DDOS which was not a DDOS. We had an issue recently between the Web sites of <a href="http://www.rds.ca/" title="RDS.ca">RDS</a> and <a href="http://legrandclub.rds.ca/" title="LE GRAND CLUB - Accueil">Le Grand Club</a>. Le Grand Club has been literally killed by the trafic coming from RDS, which is around 1 million hits a day. When checking the Grand Club HTTP logs of Le Grand Club, we noticed that all referers were coming from the home page of RDS, but coming from many different&#8230; <a href="http://lab.pheromone.ca/2009/11/16/http-accept-header-implementatio/" class="read_more">...</a></p>]]></description>
			<content:encoded><![CDATA[<p>The DDOS which was not a DDOS. We had an issue recently between the Web sites of <a href="http://www.rds.ca/" title="RDS.ca">RDS</a> and <a href="http://legrandclub.rds.ca/" title="LE GRAND CLUB - Accueil">Le Grand Club</a>. Le Grand Club has been literally killed by the trafic coming from RDS, which is around 1 million hits a day. When checking the Grand Club HTTP logs of Le Grand Club, we noticed that all referers were coming from the home page of RDS, but coming from many different IP addresses and User Agents. What was happening? A security issue? An implementation issue on Le Grand Club in Rails?</p>
<p>No. Just a human error in the markup and bad HTTP browsers implementations.</p>
<p>An <code>IMG</code> element on the home page was calling a dynamic html file of Le Grand Club. With each request on the home page of RDS, a request was made on Le Grand Club.</p>
<p>How to avoid that this happens again in the future?</p>
<h2 id="accept">Accept header in HTTP 1.1</h2>
<p>When typing a URL in a browser address bar or following a link in a Web page, the client (browsers such as Firefox, Opera, Safari for example) sends  information to the server. It&#8217;s a &#8220;business card&#8221; giving enough details for knowing how the server should handle the client. This is a common pattern of social relationship before entering into a dialog.</p>
<p>The Accept header as defined in the HTTP specification.</p>
<blockquote><p>14.1 Accept</p>
<p>The Accept request-header field can be used to specify certain media types which are acceptable for the response. Accept headers can be used to indicate that the request is specifically limited to a small set of desired types, as in the case of a request for an in-line image.</p>
<pre style="font-family: Courier, fixed;">
       Accept         = &quot;Accept&quot; &quot;:&quot;
                        #( media-range [ accept-params ] )
       media-range    = ( &quot;*/*&quot;
                        | ( type &quot;/&quot; &quot;*&quot; )
                        | ( type &quot;/&quot; subtype )
                        ) *( &quot;;&quot; parameter )
       accept-params  = &quot;;&quot; &quot;q&quot; &quot;=&quot; qvalue *( accept-extension )
       accept-extension = &quot;;&quot; token [ &quot;=&quot; ( token | quoted-string ) ]</pre>
<p>The asterisk &quot;*&quot; character is used to group media types into ranges, with &quot;*/*&quot; indicating all media types and &quot;type/*&quot; indicating all subtypes of that type. The media-range MAY include media type parameters that are applicable to that range.</p>
<p>via<a href='http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html'>HTTP/1.1: Header Field Definitions</a>.</p>
</blockquote>
<h2 id="practice">Accept header in practice</h2>
<p>Let&#8217;s try to visit the <a href="http://w3.org/">W3C Web site</a>. The following is what Firefox is sending to the Apache server of W3C.</p>
<pre style="font-family: Courier, fixed;">Host:              www.w3.org
User-Agent:        Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.5; fr; rv:1.9.1.5) Gecko/20091102 Firefox/3.5.5
<strong>Accept:            text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8</strong>
Accept-Language:   fr,fr-fr;q=0.8,en-us;q=0.5,en;q=0.3
Accept-Encoding:   gzip,deflate
Accept-Charset:    ISO-8859-1,utf-8;q=0.7,*;q=0.7
Keep-Alive:        300
Connection:        keep-alive
If-Modified-Since: Sun, 15 Nov 2009 13:42:32 GMT
If-None-Match:     "703c-478691095e200;89-3f26bd17a2f00"
Cache-Control:     max-age=0</pre>
<p>The <code>Accept</code> header informs the server that the client will be able to process document of a certain nature. In this case, Firefox is saying: &#8220;I accept document which are html (text/html) or xhtml (application/xhtml+xml) or xml (application/xml) or if everything else fails, try to send me something in another format.&#8221;</p>
<p>If the server has what is needed, it will send the requested document for this specific URL in the right format (here html). So far no magic. Everything is perfect. Simple!</p>
<p>We receive the document which contains calls to other resources on the Web, such as stylesheet, scripts, and <strong>images</strong>. The html document will contain <code>IMG</code> element and get from the <code>src</code> attribute, the url to <code>GET</code>. Firefox sends again an accept header for this image.</p>
<pre style="font-family: Courier, fixed;">Accept: image/png,image/*;q=0.8,*/*;q=0.5</pre>
<p>It clearly says that Firefox is accepting images, PNG format in priority, then other type of images if no PNG available, and finally anything. The server receiving this request can send back an image in PNG, or GIF, or JPEG.</p>
<h2 id="solution-rails">Solution Rails</h2>
<p>We know that for specific URLs, we have specific type of contents. So when Firefox is sending an accept image for a URL which is in fact HTML. We can easily decide that the server should reply &#8220;<code>406 Not Acceptable</code>&#8220;, the proper way in HTTP to say that you can&#8217;t provide the right format to the client. The next morning, I seat with Benoit Goyette and discussed about handling in Rails this HTTP corner case. Better be ready for the next time. In a few times, Benoit finished a prototype code, perfectly working in a test environment.</p>
<pre style="font-family: Courier, fixed;">
before_filter :accept_headers
  def accept_headers
  if request.env['HTTP_ACCEPT'] =~ /^image.*$/ &amp;&amp; !(request.env['REQUEST_PATH'] =~ /^.*[jpg|jpeg|gif|png]$/)
    render :nothing => true, :status => 406
  end
end
</pre>
<p>Hourra? Not exactly… It was without counting the bad implementation landscape of browsers. What about Opera?</p>
<pre style="font-family: Courier, fixed;">text/html, application/xml;q=0.9, application/xhtml+xml, application/x-obml2d, image/png, image/jpeg, image/gif, image/x-xbitmap, */*;q=0.1</pre>
<p>and Webkit? like Internet Explorer… worse.</p>
<pre style="font-family: Courier, fixed;">*/*</pre>
<p>Accept header is then not the solution for blocking this case of bad markup. We are still exploring an elegant and flexible solution.</p>
]]></content:encoded>
			<wfw:commentRss>http://lab.pheromone.ca/2009/11/16/http-accept-header-implementatio/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>CSS Orienté Objet</title>
		<link>http://lab.pheromone.ca/2009/10/14/css-oriente-objet/</link>
		<comments>http://lab.pheromone.ca/2009/10/14/css-oriente-objet/#comments</comments>
		<pubDate>Wed, 14 Oct 2009 11:21:08 +0000</pubDate>
		<dc:creator>Olivier Théreaux</dc:creator>
				<category><![CDATA[Tech]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[css]]></category>
		<category><![CDATA[framework]]></category>
		<category><![CDATA[oocss]]></category>
		<category><![CDATA[web]]></category>

		<guid isPermaLink="false">http://lab.pheromone.ca/?p=132</guid>
		<description><![CDATA[<p>Parmi les projets auxquels j&#8217;ai participé avant de rejoindre Pheromone, la refonte du <a href="http://www.w3.org" title="World Wide Web Consortium">site du w3c</a> est un de ceux qui me fait le plus plaisir à voir enfin public. Les attentes quant au travail sur le site de l&#8217;organisation des standards du Web était telle que l&#8217;équipe qui le gérait aura souvent été tenté par l&#8217;immobilisme comme rempart à l&#8217;inévitable pluie de critique que tout changement de style, ou de code, génèrerait.</p>
<p>Parmi les&#8230; <a href="http://lab.pheromone.ca/2009/10/14/css-oriente-objet/" class="read_more">...</a></p>]]></description>
			<content:encoded><![CDATA[<p>Parmi les projets auxquels j&#8217;ai participé avant de rejoindre Pheromone, la refonte du <a href="http://www.w3.org" title="World Wide Web Consortium">site du w3c</a> est un de ceux qui me fait le plus plaisir à voir enfin public. Les attentes quant au travail sur le site de l&#8217;organisation des standards du Web était telle que l&#8217;équipe qui le gérait aura souvent été tenté par l&#8217;immobilisme comme rempart à l&#8217;inévitable pluie de critique que tout changement de style, ou de code, génèrerait.</p>
<p>Parmi les changements majeurs apportés par cette refonte, outre le massif ouvrage de simplification de la navigation et d&#8217;architecture d&#8217;information, il est intéressant de noter que l&#8217;équipe du W3C a décidé d&#8217;utiliser pour ses feuilles de style la méthodologie de «CSS orienté objet» développée par <a href="http://www.stubbornella.org/content/">Nicole Sullivan</a>. Les principes fondateurs du ooCSS partent d&#8217;observations qui rejoignent les miennes: tout site d&#8217;envergure, de croissance organique, ou qui voit son design évoluer au fil du temps voit aussi ses feuilles de style se transformer en bazar inextricable. </p>
<p>Résultat: des feuilles de style lourdes, mal organisées, redondantes, utilisant rarement les potentialités (notamment pour les aspects de cascade) du langage CSS… Tous les projets de &#8220;refactorisation de code CSS&#8221; auxquels j&#8217;ai pu assister se transforment souvent en vilaine farce: on efface tout et on recommence. C&#8217;est souvent une perte de temps, un gâchis d&#8217;argent, et dans la plupart des cas le travail de rationalisation des feuilles de style est repoussé aux calendes grecques, à savoir à une éventuelle refonte complète du site.</p>
<p>C&#8217;est dans ce contexte que ooCSS fait son entrée. Se réclamant de deux principes fondateurs: «séparer la structure et l&#8217;habillage» et «séparer le contenu du contenant», le CSS orienté objet part surtout d&#8217;une affirmation: le CSS, c&#8217;est du code, et il revient aux professionels du Web de le traiter en tant que tel. Et tout comme la plupart des «frameworks» de code (Rails pour Ruby, Django pour Python, etc.) auront permis aux développeurs de structurer leur code autour d&#8217;une <a href="http://en.wikipedia.org/wiki/Representational_State_Transfer">architecture réfléchie et adaptée au Web</a>, il faut se réjouir de voir un effort similaire, quoique sans doute encore maladroit, tenter de structurer la pratique du langage CSS.</p>
<p>Pour en savoir plus sur ooCSS, la meilleure introduction au sujet demeure <a href="http://www.slideshare.net/stubbornella/object-oriented-css">cette présentation par Nicole</a> de son framework, et bien entendu, la <a href="http://wiki.github.com/stubbornella/oocss" title="documentation et téléchargement du framework CSS orienté objet - ooCSS">mise en pratique</a>. </p>
]]></content:encoded>
			<wfw:commentRss>http://lab.pheromone.ca/2009/10/14/css-oriente-objet/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>

