proxy_request 0.0.1 → 0.0.2

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.
Files changed (2) hide show
  1. data/lib/proxy_request.rb +43 -23
  2. metadata +19 -3
data/lib/proxy_request.rb CHANGED
@@ -1,35 +1,55 @@
1
1
  # coding: utf-8
2
- module ActionDispatch
3
- module Routing
4
- class Mapper
5
- module HttpHelpers
6
-
7
- def proxy_request(path)
8
2
 
9
- lambda do |env|
3
+ require 'httpclient'
10
4
 
11
- req = Request.new(env)
5
+ def _proxy_request(env,path,args = {})
12
6
 
13
- path_params = path.to_s % Hash[req.params.map{|a| [a.first.to_sym, a.last]}]
7
+ req = ActionDispatch::Request.new(env)
14
8
 
15
- if path_params.starts_with?("http:/")
16
- path_params.gsub!('http:/','http://')
17
- end
18
-
9
+ if not args[:skip_csrf] and env['rack.session']['_csrf_token'] != req.headers["X-CSRF-Token"]
10
+ return [
11
+ 403,
12
+ {'Content-Type' => 'text/html', 'Content-Length' => '3'},
13
+ ['403']
14
+ ]
15
+ end
19
16
 
20
- if req.params['format']
21
- path_params += "." + req.params['format']
22
- end
17
+ path_params = path.to_s % Hash[req.params.map{|a| [a.first.to_sym, a.last]}]
23
18
 
24
- uri = URI.parse( path_params )
19
+ if path_params.starts_with?("http:/")
20
+ path_params.gsub!('http:/','http://')
21
+ end
22
+
23
+ if req.params['format']
24
+ path_params += "." + req.params['format']
25
+ end
25
26
 
26
- http_req = HTTPClient.new
27
+ uri = URI.parse( path_params )
27
28
 
28
- elapsed_time = Benchmark.ms do
29
- @response = http_req.request(req.method,uri.to_s)
30
- end
31
-
32
- [ @response.status, {'Content-Type' => @response.header.contenttype }, [@response.body.content] ]
29
+ http_req = HTTPClient.new
30
+
31
+ elapsed_time = Benchmark.ms do
32
+ @response = http_req.request(req.method,uri.to_s)
33
+ end
34
+
35
+ [
36
+ @response.status,
37
+ {
38
+ 'Content-Type' => @response.header.contenttype
39
+ },
40
+ [@response.body.content]
41
+ ]
42
+
43
+ end
44
+
45
+ module ActionDispatch
46
+ module Routing
47
+ class Mapper
48
+ module HttpHelpers
49
+
50
+ def proxy_request(path,args = {})
51
+ lambda do |env|
52
+ _proxy_request(env,path,args)
33
53
  end
34
54
  end
35
55
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: proxy_request
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,8 +9,24 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-08-29 00:00:00.000000000 Z
13
- dependencies: []
12
+ date: 2012-08-31 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: httpclient
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
14
30
  description: Proxy request helper for yours Rails routes.
15
31
  email: kamil.zaleski@gmail.com
16
32
  executables: []