<?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>Pivotal Labs &#187; rack</title>
	<atom:link href="http://pivotallabs.com/tag/rack/feed/" rel="self" type="application/rss+xml" />
	<link>http://pivotallabs.com</link>
	<description>Agility Developed</description>
	<lastBuildDate>Tue, 21 May 2013 16:50:52 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.5.1</generator>
		<item>
		<title>&#8220;expect errors&#8221;</title>
		<link>http://pivotallabs.com/expect-errors/</link>
		<comments>http://pivotallabs.com/expect-errors/#comments</comments>
		<pubDate>Fri, 08 Feb 2013 17:21:24 +0000</pubDate>
		<dc:creator>Phil Goodwin</dc:creator>
				<category><![CDATA[Standup]]></category>
		<category><![CDATA[agile]]></category>
		<category><![CDATA[clang]]></category>
		<category><![CDATA[db]]></category>
		<category><![CDATA[party]]></category>
		<category><![CDATA[rack]]></category>
		<category><![CDATA[ruby]]></category>

		<guid isPermaLink="false">http://pivotallabs.com/?p=15155</guid>
		<description><![CDATA[<p>Helps &#34;expect errors&#34; when compiling Ruby with clang Compiled Ruby with clang and the compile output contained a warning to &#34;expect errors&#34;. Has anyone experienced these alleged errors? One member or our audience said that they had compiled the same way and not experienced any problems. Interestings Update your rack gem Nasty remote execution vulnerability. rack.github.com parallel_tests prepare task does not drop tables If you&#39;re using parallel_tests, be aware that, unlike rake db:test:prepare, the rake parallel:prepare task does not purge the databases before it loads the schema. You&#39;ll only notice this if you&#39;re dropping tables &#8211; the dropped tables will stay forever in the parallel databases. We have a fork that works properly. (Pull request coming soon.) https://github.com/pivotal-gemini/parallel_tests Events 02/15: Block Party http://engine.is/blockparty next Friday celebrating start ups in SF w/food trucks at lunch time.</p><p>The post <a href="http://pivotallabs.com/expect-errors/">&#8220;expect errors&#8221;</a> appeared first on <a href="http://pivotallabs.com">Pivotal Labs</a>.</p>]]></description>
				<content:encoded><![CDATA[<h2>Helps</h2>
<h3>&quot;expect errors&quot; when compiling Ruby with clang</h3>
<p>Compiled Ruby with clang and the compile output contained a warning to &quot;expect errors&quot;. Has anyone experienced these alleged errors?</p>
<p>One member or our audience said that they had compiled the same way and not experienced any problems.</p>
<h2>Interestings</h2>
<h3>Update your rack gem</h3>
<p>Nasty remote execution vulnerability.</p>
<p>rack.github.com</p>
<h3>parallel_tests prepare task does not drop tables</h3>
<p>If you&#39;re using parallel_tests, be aware that, unlike rake db:test:prepare, the rake parallel:prepare task does not purge the databases before it loads the schema. You&#39;ll only notice this if you&#39;re dropping tables &#8211; the dropped tables will stay forever in the parallel databases.</p>
<p>We have a fork that works properly. (Pull request coming soon.)<br />
<a href="https://github.com/pivotal-gemini/parallel_tests">https://github.com/pivotal-gemini/parallel_tests</a></p>
<h2>Events</h2>
<h3>02/15: Block Party</h3>
<p><a href="http://engine.is/blockparty">http://engine.is/blockparty</a></p>
<p>next Friday celebrating start ups in SF w/food trucks at lunch time.</p>
<p>The post <a href="http://pivotallabs.com/expect-errors/">&#8220;expect errors&#8221;</a> appeared first on <a href="http://pivotallabs.com">Pivotal Labs</a>.</p>]]></content:encoded>
			<wfw:commentRss>http://pivotallabs.com/expect-errors/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Announcing Refraction</title>
		<link>http://pivotallabs.com/announcing-refraction/</link>
		<comments>http://pivotallabs.com/announcing-refraction/#comments</comments>
		<pubDate>Sat, 24 Oct 2009 18:31:00 +0000</pubDate>
		<dc:creator>Pivotal Labs</dc:creator>
				<category><![CDATA[Labs]]></category>
		<category><![CDATA[cloud]]></category>
		<category><![CDATA[opensource]]></category>
		<category><![CDATA[rack]]></category>
		<category><![CDATA[refraction]]></category>

		<guid isPermaLink="false">http://pivotallabs.com/announcing-refraction/</guid>
		<description><![CDATA[<p><p>One of the things I've always liked least about building web applications is dealing with <code>mod_rewrite</code>. It's a very useful feature, but it's quirky and the config languages for webservers are difficult to use &#40;at least from my experience with Apache and Nginx&#41;. But like it or not, <code>mod_rewrite</code> is often a necessary part of a web app. Until now...</p>

<p>Recently I had to redo the rewrite rules for <a href="http://pivotallabs.com/">pivotallabs.com</a> when we switched from Apache to Nginx, which we did when <a href="http://pivotallabs.com/users/jsusser/blog/articles/916-becoming-more-flexible">moving to EngineYard's cloud hosting</a>.  Since then our Nginx config has grown to over 150 lines, mainly to deal with multiple virtual hosts.</p>

<p>Now, managing a custom Nginx config on the EY cloud system isn't as simple as I'd like, especially when the configs are different on production and demo environments.  &#40;Demo is what we call our usual environment for doing feature acceptance.&#41;  It's far easier to use the automatically generated config, but that doesn't work when you need to support multiple domain names.</p>

<p>The obvious thing to do was to move the rewrite/redirect logic out of the Nginx config.  I found a couple Rack middleware components that did something sort of like what we needed, but none of them were sufficient for what we needed.  So we created our own.</p>

<p><a href="http://github.com/pivotal/refraction">Refraction</a> is a Rack middleware replacement for <code>mod_rewrite</code>.  With Refraction we were able to replace our 150+ line Nginx config with a 50 line Ruby file, and go back to using the standard automatically generated config on EY cloud.</p>

<p>Here's an example Refraction config file:</p>

<pre><code>Refraction.configure do &#124;req&#124;
  feedburner  = "http://feeds.pivotallabs.com/pivotallabs"

  if req.env['HTTP_USER_AGENT'] !~ /FeedBurner&#124;FeedValidator/ &#38;&#38; req.host =~ /pivotallabs.com/
    case req.path
    when %r{^/&#40;talks&#124;blabs&#124;blog&#41;.&#40;atom&#124;rss&#41;$}        ; req.found! "#{feedburner}/#{$1}.#{$2}"
    when %r{^/users/&#40;chris&#124;edward&#41;/blog.&#40;atom&#124;rss&#41;$} ; req.found! "#{feedburner}/#{$1}.#{$2}"
    end
  else
    case req.host
    when 'tweed.pivotallabs.com'
      req.rewrite! "http://pivotallabs.com/tweed#{req.path}"
    when /&#40;[-w]+.&#41;?pivotallabs.com/
      # passthrough with no change
    else  # wildcard domains &#40;e.g. pivotalabs.com&#41;
      req.permanent! :host =&#62; "pivotallabs.com"
    end
  end
end
</code></pre>

<p>These rules are extracted from the full config file for pivotallabs.com.  They redirect high-traffic syndication feeds to feedburner, rewrite a subdomain &#40;tweed.pivotallabs.com&#41; to a path for that sub-site &#40;pivotallabs.com/tweed&#41;, and redirect some aliases to our standard domain name &#40;pivotalabs anyone?&#41;.</p>

<p>Refraction is thread-safe, which means you can put it outside the Rack::Lock, something we felt was important for performance.  It will never have the performance of <code>mod_rewrite</code>, but it will certainly be better than handling redirections in Rails itself.</p>

<p>Full documentation is available in the README.  Contributions welcome.</p>

<p>And of course big thanks to <a href="http://pivotallabs.com/users/spierson/blog">Sam Pierson</a> and Wai Lun Mang who both paired with me on developing Refraction.</p> <a href="http://pivotallabs.com/announcing-refraction/">Continue reading <span class="meta-nav">&#8594;</span></a></p><p>The post <a href="http://pivotallabs.com/announcing-refraction/">Announcing Refraction</a> appeared first on <a href="http://pivotallabs.com">Pivotal Labs</a>.</p>]]></description>
				<content:encoded><![CDATA[<p>One of the things I&#8217;ve always liked least about building web applications is dealing with <code>mod_rewrite</code>. It&#8217;s a very useful feature, but it&#8217;s quirky and the config languages for webservers are difficult to use &#40;at least from my experience with Apache and Nginx&#41;. But like it or not, <code>mod_rewrite</code> is often a necessary part of a web app. Until now&#8230;</p>
<p>Recently I had to redo the rewrite rules for <a href="http://pivotallabs.com/">pivotallabs.com</a> when we switched from Apache to Nginx, which we did when <a href="http://pivotallabs.com/users/jsusser/blog/articles/916-becoming-more-flexible">moving to EngineYard&#8217;s cloud hosting</a>.  Since then our Nginx config has grown to over 150 lines, mainly to deal with multiple virtual hosts.</p>
<p>Now, managing a custom Nginx config on the EY cloud system isn&#8217;t as simple as I&#8217;d like, especially when the configs are different on production and demo environments.  &#40;Demo is what we call our usual environment for doing feature acceptance.&#41;  It&#8217;s far easier to use the automatically generated config, but that doesn&#8217;t work when you need to support multiple domain names.</p>
<p>The obvious thing to do was to move the rewrite/redirect logic out of the Nginx config.  I found a couple Rack middleware components that did something sort of like what we needed, but none of them were sufficient for what we needed.  So we created our own.</p>
<p><a href="http://github.com/pivotal/refraction">Refraction</a> is a Rack middleware replacement for <code>mod_rewrite</code>.  With Refraction we were able to replace our 150+ line Nginx config with a 50 line Ruby file, and go back to using the standard automatically generated config on EY cloud.</p>
<p>Here&#8217;s an example Refraction config file:</p>
<pre><code>Refraction.configure do |req|
  feedburner  = "http://feeds.pivotallabs.com/pivotallabs"

  if req.env['HTTP_USER_AGENT'] !~ /FeedBurner|FeedValidator/ &amp;&amp; req.host =~ /pivotallabs.com/
    case req.path
    when %r{^/&#40;talks|blabs|blog&#41;.&#40;atom|rss&#41;$}        ; req.found! "#{feedburner}/#{$1}.#{$2}"
    when %r{^/users/&#40;chris|edward&#41;/blog.&#40;atom|rss&#41;$} ; req.found! "#{feedburner}/#{$1}.#{$2}"
    end
  else
    case req.host
    when 'tweed.pivotallabs.com'
      req.rewrite! "http://pivotallabs.com/tweed#{req.path}"
    when /&#40;[-w]+.&#41;?pivotallabs.com/
      # passthrough with no change
    else  # wildcard domains &#40;e.g. pivotalabs.com&#41;
      req.permanent! :host =&gt; "pivotallabs.com"
    end
  end
end
</code></pre>
<p>These rules are extracted from the full config file for pivotallabs.com.  They redirect high-traffic syndication feeds to feedburner, rewrite a subdomain &#40;tweed.pivotallabs.com&#41; to a path for that sub-site &#40;pivotallabs.com/tweed&#41;, and redirect some aliases to our standard domain name &#40;pivotalabs anyone?&#41;.</p>
<p>Refraction is thread-safe, which means you can put it outside the Rack::Lock, something we felt was important for performance.  It will never have the performance of <code>mod_rewrite</code>, but it will certainly be better than handling redirections in Rails itself.</p>
<p>Full documentation is available in the README.  Contributions welcome.</p>
<p>And of course big thanks to <a href="http://pivotallabs.com/users/spierson/blog">Sam Pierson</a> and Wai Lun Mang who both paired with me on developing Refraction.</p>
<p>The post <a href="http://pivotallabs.com/announcing-refraction/">Announcing Refraction</a> appeared first on <a href="http://pivotallabs.com">Pivotal Labs</a>.</p>]]></content:encoded>
			<wfw:commentRss>http://pivotallabs.com/announcing-refraction/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>Sanitizing POST params with custom Rack middleware</title>
		<link>http://pivotallabs.com/sanitizing-post-params-with-custom-rack-middleware/</link>
		<comments>http://pivotallabs.com/sanitizing-post-params-with-custom-rack-middleware/#comments</comments>
		<pubDate>Thu, 11 Jun 2009 11:48:00 +0000</pubDate>
		<dc:creator>Pivotal Labs</dc:creator>
				<category><![CDATA[Labs]]></category>
		<category><![CDATA[rack]]></category>

		<guid isPermaLink="false">http://pivotallabs.com/sanitizing-post-params-with-custom-rack-middleware/</guid>
		<description><![CDATA[<p><p><strong>The problem: Improperly escaped post data</strong></p>

<p>I recently worked on an app that processed xml files.  Once a week, a legacy system posted a large xml document to the app.  For almost a year the app worked perfectly, and then we updated to rails 2.3.2 and the posts started failing spectacularly.  Looking at the log files, I noticed that the params were incorrect:</p>

<pre>&#60;code&#62;{&#34;message&#34;=&#62;&#34;hello&#34;, &#34;xml&#34;=&#62;&#34;&#60;xml&#62;Foo &#38;amp&#34;, &#34;Bar&#60;/xml&#62;&#34;=&#62;nil, &#34;action&#34;=&#62;&#34;not_scrubbed&#34;, &#34;controller&#34;=&#62;&#34;examples&#34;}&#60;/code&#62;</pre>

<p>After looking into it further, I realized that the data that was being posted contained semi-colons:</p>

<pre>&#60;code&#62;xml=&#60;xml&#62;Foo %26amp; Bar&#60;/xml&#62;&#38;message=hello&#60;/code&#62;</pre>

<p>It turns out that rails used to only split params on ampersands, but that rack splits on both ampersands and semi-colons.  We couldn't change the legacy system, so we had to remove the semi-colons before the post params got to rails.  </p>

<p><strong>The solution: Rack middleware</strong></p>

<p>Using Rack middleware it's was easy to insert code before rails params parsing code executed.  To start, build a class that conforms to the signature of a rack middleware layer, like so:</p> <a href="http://pivotallabs.com/sanitizing-post-params-with-custom-rack-middleware/">Continue reading <span class="meta-nav">&#8594;</span></a></p><p>The post <a href="http://pivotallabs.com/sanitizing-post-params-with-custom-rack-middleware/">Sanitizing POST params with custom Rack middleware</a> appeared first on <a href="http://pivotallabs.com">Pivotal Labs</a>.</p>]]></description>
				<content:encoded><![CDATA[<p><strong>The problem: Improperly escaped post data</strong></p>
<p>I recently worked on an app that processed xml files.  Once a week, a legacy system posted a large xml document to the app.  For almost a year the app worked perfectly, and then we updated to rails 2.3.2 and the posts started failing spectacularly.  Looking at the log files, I noticed that the params were incorrect:</p>
<pre>&lt;code&gt;{&quot;message&quot;=&gt;&quot;hello&quot;, &quot;xml&quot;=&gt;&quot;&lt;xml&gt;Foo &amp;amp&quot;, &quot;Bar&lt;/xml&gt;&quot;=&gt;nil, &quot;action&quot;=&gt;&quot;not_scrubbed&quot;, &quot;controller&quot;=&gt;&quot;examples&quot;}&lt;/code&gt;</pre>
<p>After looking into it further, I realized that the data that was being posted contained semi-colons:</p>
<pre>&lt;code&gt;xml=&lt;xml&gt;Foo %26amp; Bar&lt;/xml&gt;&amp;message=hello&lt;/code&gt;</pre>
<p>It turns out that rails used to only split params on ampersands, but that rack splits on both ampersands and semi-colons.  We couldn&#8217;t change the legacy system, so we had to remove the semi-colons before the post params got to rails.  </p>
<p><strong>The solution: Rack middleware</strong></p>
<p>Using Rack middleware it&#8217;s was easy to insert code before rails params parsing code executed.  To start, build a class that conforms to the signature of a rack middleware layer, like so:</p>
<pre>&lt;code&gt;
# lib/scrubber.rb
class Scrubber
  def initialize&#40;app, options&#41;
    @app = app
    @routes = options[:routes]
  end

  def call&#40;env&#41;
    scrub&#40;env&#41;
    @app.call&#40;env&#41;
  end

  private
    def scrub&#40;env&#41;
      return unless @routes.include?&#40;env[&quot;PATH_INFO&quot;]&#41;
      rack_input = env[&quot;rack.input&quot;].read
      params = Rack::Utils.parse_query&#40;rack_input, &quot;&amp;&quot;&#41;
      params[&quot;xml&quot;] = Rack::Utils.unescape&#40;params[&quot;xml&quot;]&#41;
      env[&quot;rack.input&quot;] = StringIO.new&#40;Rack::Utils.build_query&#40;params&#41;&#41;
    rescue
    ensure
      env[&quot;rack.input&quot;].rewind
    end
end
&lt;/code&gt;</pre>
<p>Then register the middleware from environment.rb:</p>
<pre>&lt;code&gt;
  config.middleware.insert_before ActionController::ParamsParser,
                                  &quot;Scrubber&quot;,
                                  :routes =&gt; [ &quot;/examples/scrubbed&quot; ]
&lt;/code&gt;</pre>
<p>To verify that this works, use curl to send the request, like so:</p>
<pre>&lt;code&gt;curl -d 'xml=&lt;xml&gt;Foo %26amp; Bar&lt;/xml&gt;&amp;message=hello' http://localhost:3000/examples/scrubbed&lt;/code&gt;</pre>
<p>I&#8217;ve put together a sample app on github that gives a working example of the code above which you can find at <a href="http://github.com/zilkey/params-scrubber/tree/master">http://github.com/zilkey/params-scrubber/tree/master</a>.</p>
<p>The post <a href="http://pivotallabs.com/sanitizing-post-params-with-custom-rack-middleware/">Sanitizing POST params with custom Rack middleware</a> appeared first on <a href="http://pivotallabs.com">Pivotal Labs</a>.</p>]]></content:encoded>
			<wfw:commentRss>http://pivotallabs.com/sanitizing-post-params-with-custom-rack-middleware/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Minified using disk: basic (Feed is rejected)
Page Caching using apc
Database Caching 1/12 queries in 0.007 seconds using apc
Object Caching 576/616 objects using apc

 Served from: pivotallabs.com @ 2013-05-21 21:55:13 by W3 Total Cache -->