atlas_middleware 0.0.4 → 0.0.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -2,14 +2,22 @@ require 'rack'
2
2
  require 'httparty'
3
3
 
4
4
  class ArcgisServerRestProxy
5
- def call(env)
6
- request = Rack::Request.new(env)
7
- url = request.params.delete('url')
8
- call_proxy(url)
5
+ def call(env)
6
+ call_proxy!(Rack::Request.new(env))
9
7
  end
10
8
 
11
- def call_proxy(url)
12
- response = HTTParty.get(url, :query => { :f => :json })
13
- [response.code, response.headers, response.body]
9
+ def call_proxy!(request)
10
+ url = request.params.delete('url')
11
+ proxy_response = HTTParty.get(url, :query => { :f => :json })
12
+ response = Rack::Response.new(proxy_response.body, proxy_response.code, {})
13
+ # HTTParty returns request headers in lowercase
14
+ if proxy_response.code == 200
15
+ if proxy_response.headers['cache-control']
16
+ response.headers['Cache-Control'] = proxy_response.headers['cache-control'].to_s.sub(/private/, 'public')
17
+ else
18
+ response.headers['Cache-Control'] = "public, max-age=#{1.day}"
19
+ end
20
+ end
21
+ response.to_a
14
22
  end
15
23
  end
data/lib/cgns_search.rb CHANGED
@@ -13,8 +13,9 @@ class CgnsSearch
13
13
 
14
14
  headers = { "Content-Type" => "application/json" }
15
15
  begin
16
- response = Rack::Response.new(find(request.params), 200, headers)
17
- response = maybe_cache_response(response)
16
+ response = Rack::Response.new(find(request.params), 200, headers)
17
+ # set caching information
18
+ response.headers['Cache-Control'] = "public, max-age=#{1.week}"
18
19
  rescue Exception => e
19
20
  response = Rack::Response.new({ :error => e.message }.to_json, 500, headers)
20
21
  end
@@ -26,15 +27,4 @@ class CgnsSearch
26
27
  def find(query = {})
27
28
  CgnsSearch.get('/gnss-srt/api', { :query => query }).to_json
28
29
  end
29
-
30
- def maybe_cache_response(response)
31
- begin
32
- # using rack cache
33
- cached_response = Rack::Cache::Response.new(response.status, response.headers, response.body)
34
- cached_response.max_age = 1.month
35
- cached_response
36
- rescue
37
- response # just return the original response
38
- end
39
- end
40
30
  end
@@ -0,0 +1,14 @@
1
+ # encoding: utf-8
2
+
3
+ class IgnoreExtJsCacheBuster
4
+ def initialize(app, cache_param = '_dc')
5
+ @app = app
6
+ @cache_param = cache_param
7
+ end
8
+
9
+ def call(env)
10
+ env["QUERY_STRING"] = env["QUERY_STRING"].to_s.sub(/#{@cache_param}=\d+/, "#{@cache_param}=")
11
+ @status, @header, @body = @app.call(env)
12
+ [@status, @header, @body]
13
+ end
14
+ end
@@ -9,7 +9,8 @@ class MapServerLegendInfo
9
9
 
10
10
  begin
11
11
  response = Rack::Response.new(get_legends(request), 200, headers)
12
- response = maybe_cache_response(response)
12
+ # set caching information
13
+ response.headers['Cache-Control'] = "public, max-age=#{1.week}"
13
14
  rescue Exception => e
14
15
  response = Rack::Response.new({ :error => e.message }.to_json, 500, headers)
15
16
  end
@@ -24,15 +25,4 @@ class MapServerLegendInfo
24
25
  legend = map_server.get_legend_info(:map_name => map_name, :image_return_url => true)
25
26
  legend.to_json
26
27
  end
27
-
28
- def maybe_cache_response(response)
29
- begin
30
- # using rack cache
31
- cached_response = Rack::Cache::Response.new(response.status, response.headers, response.body)
32
- cached_response.max_age = 1.week
33
- cached_response
34
- rescue
35
- response # just return the original response
36
- end
37
- end
38
28
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: atlas_middleware
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Colin Casey
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-10-14 00:00:00 -03:00
12
+ date: 2009-11-07 00:00:00 -04:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -95,6 +95,7 @@ files:
95
95
  - lib/arcgis_server_rest_proxy.rb
96
96
  - lib/cgns_search.rb
97
97
  - lib/export_map_services.rb
98
+ - lib/ignore_ext_js_cache_buster.rb
98
99
  - lib/map_server_legend_info.rb
99
100
  - lib/postal_code_lookup.rb
100
101
  - lib/print_map/job.rb
@@ -131,7 +132,7 @@ requirements:
131
132
  - If using Ruby - gem install rmagick (2.11.0)
132
133
  - If using JRuby - gem install rmagick4j (0.3.7)
133
134
  rubyforge_project:
134
- rubygems_version: 1.3.4
135
+ rubygems_version: 1.3.5
135
136
  signing_key:
136
137
  specification_version: 3
137
138
  summary: Middleware components for Atlas Projects