<?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>rails 2.2.2 | Spiffy Stores Blog</title>
	<atom:link href="https://www.spiffystores.com.au/blog/tag/rails-222/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.spiffystores.com.au/blog</link>
	<description>Checkout - The Spiffy Stores Blog</description>
	<lastBuildDate>Tue, 31 Aug 2021 21:08:59 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.8.3</generator>
<site xmlns="com-wordpress:feed-additions:1">241205771</site>	<item>
		<title>Rails 2.2.2 memoization gotchas</title>
		<link>https://www.spiffystores.com.au/blog/2008/12/17/rails-222-memoization-gotchas/</link>
		
		<dc:creator><![CDATA[Brian]]></dc:creator>
		<pubDate>Wed, 17 Dec 2008 07:33:28 +0000</pubDate>
				<category><![CDATA[Geek stuff]]></category>
		<category><![CDATA[Show All]]></category>
		<category><![CDATA[1.3]]></category>
		<category><![CDATA[2.2.2]]></category>
		<category><![CDATA[apache]]></category>
		<category><![CDATA[apache 1.3]]></category>
		<category><![CDATA[memoize]]></category>
		<category><![CDATA[rails]]></category>
		<category><![CDATA[rails 2.2.2]]></category>
		<category><![CDATA[ruby]]></category>
		<category><![CDATA[ssl]]></category>
		<guid isPermaLink="false">http://spiffystores.com.au/blog/?p=147</guid>

					<description><![CDATA[<p>For various reasons, we are still running on Apache 1.3 which is fine, except for the fact that there is no easy way of determining whether a request is via an SSL session or not. Unfortunately, this process was broken &#8230; <a href="https://www.spiffystores.com.au/blog/2008/12/17/rails-222-memoization-gotchas/">Continue reading <span class="meta-nav">&#8594;</span></a></p>
The post <a href="https://www.spiffystores.com.au/blog/2008/12/17/rails-222-memoization-gotchas/">Rails 2.2.2 memoization gotchas</a> first appeared on <a href="https://www.spiffystores.com.au/blog">Spiffy Stores Blog</a>.]]></description>
										<content:encoded><![CDATA[<div style='display:none;' class='shareaholic-canvas' data-app='share_buttons' data-title='Rails 2.2.2 memoization gotchas' data-link='https://www.spiffystores.com.au/blog/2008/12/17/rails-222-memoization-gotchas/' data-app-id-name='category_above_content'></div>
<p>For various reasons, we are still running on Apache 1.3 which is fine, except for the fact that there is no easy way of determining whether a request is via an SSL session or not.</p>



<p>Unfortunately, this process was broken by the upgrade to Rails 2.2.2.</p>



<span id="more-147"></span>



<p>No probs. We just rewrite the URL to add an &#8220;ssl&#8221; prefix before it gets passed to the Rails engine.</p>



<pre class="wp-block-code"><code lang="apacheconf" class="language-apacheconf">RewriteEngine On
RewriteCond %{DOCUMENT_ROOT}/%{REQUEST_FILENAME} !-f
RewriteRule ^/(.*)$ http://127.0.0.1:8000/ssl/$1 [P,L]
ProxyPassReverse / http://127.0.0.1:8000/ssl/</code></pre>



<p>From there, a simple route will pass the request on to our SSL Proxy controller.</p>



<pre class="wp-block-code"><code lang="ruby" class="language-ruby">map.connect 'ssl/*suburi',
            :controller => 'ssl_proxy',
            :action => 'reprocess'</code></pre>



<p>Now all our &#8216;reprocess&#8217; method has to do is take the request, rewrite the URI to its original form, and set an environment variable to let us know it&#8217;s an SSL request.</p>



<pre class="wp-block-code"><code lang="ruby" class="language-ruby line-numbers">class SslProxyController &lt; ActionController::Base
  def reprocess
    request.env["REQUEST_URI"] = "/#{params[:suburi].join('/')}"
    request.env["HTTPS"] = "on"

    controller = ActionController::Routing::Routes.recognize(request)
    controller.process(request, response)
    @performed_render = true
  end
end</code></pre>



<p>This all broke down with the upgrade to Rails 2.2.2.</p>



<p>One of the new features of 2.2.2 is the addition of memoization to various system classes, including the &#8216;request&#8217; object. This means that &#8216;request_uri&#8217; is now memoized, and that even if we update the environment variable &#8216;REQUEST_URI&#8217;, the memoized value doesn&#8217;t change. When the route is recognized, it resolves to &#8216;reprocess&#8217; again, and we end up in an endless loop.</p>



<p>The answer turns to reasonably easy to implement. All we need to do is add the following line at the start of the &#8216;reprocess&#8217; method.</p>



<pre class="wp-block-code"><code lang="ruby" class="language-ruby">request.unmemoize_all if request.respond_to? :unmemoize_all</code></pre>



<p>This code simply clears all the memoized variables, so they can all be loaded again using our new, proper URI.</p>
<div style='display:none;' class='shareaholic-canvas' data-app='share_buttons' data-title='Rails 2.2.2 memoization gotchas' data-link='https://www.spiffystores.com.au/blog/2008/12/17/rails-222-memoization-gotchas/' data-app-id-name='category_below_content'></div><div style='display:none;' class='shareaholic-canvas' data-app='recommendations' data-title='Rails 2.2.2 memoization gotchas' data-link='https://www.spiffystores.com.au/blog/2008/12/17/rails-222-memoization-gotchas/' data-app-id-name='category_below_content'></div>The post <a href="https://www.spiffystores.com.au/blog/2008/12/17/rails-222-memoization-gotchas/">Rails 2.2.2 memoization gotchas</a> first appeared on <a href="https://www.spiffystores.com.au/blog">Spiffy Stores Blog</a>.]]></content:encoded>
					
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">147</post-id>	</item>
	</channel>
</rss>
