cachable_url 0.0.1 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -8,7 +8,7 @@ Gem::Specification.new do |s|
8
8
  s.authors = ["Tom Lea"]
9
9
  s.email = ["commit@tomlea.co.uk"]
10
10
  s.homepage = "http://tomlea.co.uk"
11
- s.summary = %q{Hide query strings so caches can't see them.'}
11
+ s.summary = %q{Hide query strings so caches can't see them.}
12
12
  s.description = %q{Replace all '?'s in URLs with '%1F' (the ASCII unit separator char), and a middleware to undo it before your rack app sees.}
13
13
 
14
14
  s.rubyforge_project = "cachable_url"
@@ -2,10 +2,10 @@ require "cachable_url/version"
2
2
 
3
3
  module CachableUrl
4
4
  def self.encode(url)
5
- url.gsub('?', '%1F')
5
+ url.gsub('?', '%1f') if url
6
6
  end
7
7
 
8
8
  def self.decode(url)
9
- url.gsub('%1F', '?')
9
+ url.gsub('%1f', '?') if url
10
10
  end
11
11
  end
@@ -1,6 +1,6 @@
1
1
  require "cachable_url"
2
2
 
3
- class CachableUrl::Midleware
3
+ class CachableUrl::Middleware
4
4
  def initialize(app)
5
5
  @app = app
6
6
  end
@@ -8,10 +8,11 @@ class CachableUrl::Midleware
8
8
  def call(env)
9
9
  if env["QUERY_STRING"] == ''
10
10
  env = env.clone
11
- path, query = env["PATH_INFO"].split("%1F", 2)
11
+ path, query = env["PATH_INFO"].split("%1f", 2)
12
12
  query = CachableUrl.decode(query || "")
13
13
  env["PATH_INFO"] = path
14
14
  env["QUERY_STRING"] = query
15
+ env["REQUEST_URI"] = CachableUrl.decode(env["REQUEST_URI"])
15
16
  @app.call(env)
16
17
  else
17
18
  @app.call(env)
@@ -1,3 +1,3 @@
1
1
  module CachableUrl
2
- VERSION = "0.0.1"
2
+ VERSION = "1.0.0"
3
3
  end
@@ -22,4 +22,16 @@ describe CachableUrl do
22
22
 
23
23
  end
24
24
 
25
+ describe ".encode(nil)" do
26
+ it "is nil" do
27
+ CachableUrl.encode(nil).should be_nil
28
+ end
29
+ end
30
+
31
+ describe ".decode(nil)" do
32
+ it "is nil" do
33
+ CachableUrl.decode(nil).should be_nil
34
+ end
35
+ end
36
+
25
37
  end
@@ -1,42 +1,47 @@
1
1
  require "spec_helper"
2
2
 
3
- describe CachableUrl::Midleware do
3
+ describe CachableUrl::Middleware do
4
4
  include Rack::Test::Methods
5
5
 
6
6
  let(:requests_received){ [] }
7
7
 
8
8
  def app
9
9
  logger_app = lambda{|env| requests_received << env; [200, {"Content-Type" => 'text/plain'}, ["Hello world"]] }
10
- CachableUrl::Midleware.new(logger_app)
10
+ CachableUrl::Middleware.new(logger_app)
11
+ end
12
+
13
+ def get_with_env(path)
14
+ get(path, {}, "REQUEST_URI" => path)
11
15
  end
12
16
 
13
17
  it "should pass through requests with query strings" do
14
- get "/fooooooo%1F?foo=bar"
18
+ get_with_env "/fooooooo%1f?foo=bar"
15
19
 
16
20
  requests_received.size.should == 1
17
21
  requests_received.last["QUERY_STRING"].should == "foo=bar"
18
- requests_received.last["PATH_INFO"].should == "/fooooooo%1F"
22
+ requests_received.last["PATH_INFO"].should == "/fooooooo%1f"
19
23
  end
20
24
 
21
25
  it "should decode requests with no query strings" do
22
- get "/fooooooo%1Ffoo=bar"
26
+ get_with_env "/fooooooo%1ffoo=bar"
23
27
 
24
28
  requests_received.size.should == 1
25
29
  requests_received.last["QUERY_STRING"].should == "foo=bar"
26
30
  requests_received.last["PATH_INFO"].should == "/fooooooo"
31
+ requests_received.last["REQUEST_URI"].should == "/fooooooo?foo=bar"
27
32
  end
28
33
 
29
34
  it "should decode requests with no query strings to the same thing as the query string based request" do
30
- get "/fooooooo%1Ffoo=bar"
31
- get "/fooooooo?foo=bar"
35
+ get_with_env "/fooooooo%1ffoo=bar"
36
+ get_with_env "/fooooooo?foo=bar"
32
37
 
33
38
  requests_received.size.should == 2
34
- a,b = clense_responses(*requests_received.last(2))
39
+ a,b = cleanse_responses(*requests_received.last(2))
35
40
  a.should == b
36
41
  end
37
42
 
38
43
  protected
39
- def clense_responses(*args)
44
+ def cleanse_responses(*args)
40
45
  args.map{|r|
41
46
  r.delete_if{|key, value|
42
47
  ["rack.input", "rack.errors"].include? key
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cachable_url
3
3
  version: !ruby/object:Gem::Version
4
- hash: 29
4
+ hash: 23
5
5
  prerelease:
6
6
  segments:
7
+ - 1
7
8
  - 0
8
9
  - 0
9
- - 1
10
- version: 0.0.1
10
+ version: 1.0.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Tom Lea
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2012-02-20 00:00:00 Z
18
+ date: 2012-02-21 00:00:00 Z
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
21
  requirement: &id001 !ruby/object:Gem::Requirement
@@ -111,7 +111,7 @@ rubyforge_project: cachable_url
111
111
  rubygems_version: 1.8.15
112
112
  signing_key:
113
113
  specification_version: 3
114
- summary: Hide query strings so caches can't see them.'
114
+ summary: Hide query strings so caches can't see them.
115
115
  test_files:
116
116
  - spec/encoder_spec.rb
117
117
  - spec/middleware_spec.rb