cmis-ruby 0.4.9 → 0.4.10
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.
- checksums.yaml +4 -4
- data/lib/cmis/connection.rb +3 -1
- data/lib/cmis/connection/follow_redirects.rb +137 -0
- data/lib/cmis/type.rb +2 -2
- data/lib/cmis/version.rb +1 -1
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5b3229e8479edca2b61d24a6851296d30cea4f1a
|
4
|
+
data.tar.gz: fad024a8f321c55d7039c05a0e523eba13bd8739
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5204a6e9810c562ea5ce9bcb7edf305289a4426f3c977b884d5f7057fe8ce6b9a0c177e3259356a749e48b67ec3bd94dd8dd14a3dc19fc692a080eaa91a328ed
|
7
|
+
data.tar.gz: 1e75079eb77373630c136a2b8d216fb935c365e1b2aa209ff6ca8da2b67ad28e5d2a4ef57625a2172ed3298416aba1b778ba8f0afc432e9564aaa39a80111cb8
|
data/lib/cmis/connection.rb
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
require 'cmis/connection/follow_redirects'
|
1
2
|
require 'cmis/connection/request_modifier'
|
2
3
|
require 'cmis/connection/response_parser'
|
3
4
|
require 'cmis/version'
|
@@ -19,6 +20,7 @@ module CMIS
|
|
19
20
|
end
|
20
21
|
|
21
22
|
builder.adapter (options[:adapter] || :net_http).to_sym
|
23
|
+
builder.use FollowRedirects
|
22
24
|
builder.response :logger if options[:log_requests]
|
23
25
|
builder.use ResponseParser
|
24
26
|
end
|
@@ -31,7 +33,7 @@ module CMIS
|
|
31
33
|
url = infer_url(repository_id, params[:objectId])
|
32
34
|
|
33
35
|
if params[:cmisaction]
|
34
|
-
@http.post(url, params, headers)
|
36
|
+
@http.post(url, params, headers) { |req| req.params = query }
|
35
37
|
else
|
36
38
|
@http.get(url, params.merge(query), headers)
|
37
39
|
end
|
@@ -0,0 +1,137 @@
|
|
1
|
+
require 'faraday'
|
2
|
+
require 'set'
|
3
|
+
|
4
|
+
module CMIS
|
5
|
+
class Connection
|
6
|
+
# Based on https://github.com/lostisland/faraday_middleware/blob/master/lib/faraday_middleware/response/follow_redirects.rb
|
7
|
+
# Modified ALLOWED_METHODS to only include :get
|
8
|
+
|
9
|
+
# Public: Exception thrown when the maximum amount of requests is exceeded.
|
10
|
+
class RedirectLimitReached < Faraday::Error::ClientError
|
11
|
+
attr_reader :response
|
12
|
+
|
13
|
+
def initialize(response)
|
14
|
+
super "too many redirects; last one to: #{response['location']}"
|
15
|
+
@response = response
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
# Public: Follow HTTP 301, 302, 303, and 307 redirects.
|
20
|
+
#
|
21
|
+
# For HTTP 301, 302, and 303, the original GET, POST, PUT, DELETE, or PATCH
|
22
|
+
# request gets converted into a GET. With `:standards_compliant => true`,
|
23
|
+
# however, the HTTP method after 301/302 remains unchanged. This allows you
|
24
|
+
# to opt into HTTP/1.1 compliance and act unlike the major web browsers.
|
25
|
+
#
|
26
|
+
# This middleware currently only works with synchronous requests; i.e. it
|
27
|
+
# doesn't support parallelism.
|
28
|
+
class FollowRedirects < Faraday::Middleware
|
29
|
+
# HTTP methods for which 30x redirects can be followed
|
30
|
+
ALLOWED_METHODS = Set.new [:get]
|
31
|
+
|
32
|
+
# HTTP redirect status codes that this middleware implements
|
33
|
+
REDIRECT_CODES = Set.new [301, 302, 303, 307]
|
34
|
+
|
35
|
+
# Keys in env hash which will get cleared between requests
|
36
|
+
ENV_TO_CLEAR = Set.new [:status, :response, :response_headers]
|
37
|
+
|
38
|
+
# Default value for max redirects followed
|
39
|
+
FOLLOW_LIMIT = 3
|
40
|
+
|
41
|
+
# Public: Initialize the middleware.
|
42
|
+
#
|
43
|
+
# options - An options Hash (default: {}):
|
44
|
+
# :limit - A Numeric redirect limit (default: 3)
|
45
|
+
# :standards_compliant - A Boolean indicating whether to respect
|
46
|
+
# the HTTP spec when following 301/302
|
47
|
+
# (default: false)
|
48
|
+
# :cookies - An Array of Strings (e.g.
|
49
|
+
# ['cookie1', 'cookie2']) to choose
|
50
|
+
# cookies to be kept, or :all to keep
|
51
|
+
# all cookies (default: []).
|
52
|
+
def initialize(app, options = {})
|
53
|
+
super(app)
|
54
|
+
@options = options
|
55
|
+
|
56
|
+
@convert_to_get = Set.new [303]
|
57
|
+
@convert_to_get << 301 << 302 unless standards_compliant?
|
58
|
+
end
|
59
|
+
|
60
|
+
def call(env)
|
61
|
+
perform_with_redirection(env, follow_limit)
|
62
|
+
end
|
63
|
+
|
64
|
+
private
|
65
|
+
|
66
|
+
def convert_to_get?(response)
|
67
|
+
![:head, :options].include?(response.env[:method]) &&
|
68
|
+
@convert_to_get.include?(response.status)
|
69
|
+
end
|
70
|
+
|
71
|
+
def perform_with_redirection(env, follows)
|
72
|
+
request_body = env[:body]
|
73
|
+
response = @app.call(env)
|
74
|
+
|
75
|
+
response.on_complete do |env|
|
76
|
+
if follow_redirect?(env, response)
|
77
|
+
raise RedirectLimitReached, response if follows.zero?
|
78
|
+
env = update_env(env, request_body, response)
|
79
|
+
response = perform_with_redirection(env, follows - 1)
|
80
|
+
end
|
81
|
+
end
|
82
|
+
response
|
83
|
+
end
|
84
|
+
|
85
|
+
def update_env(env, request_body, response)
|
86
|
+
env[:url] += response['location']
|
87
|
+
if @options[:cookies]
|
88
|
+
cookies = keep_cookies(env)
|
89
|
+
env[:request_headers][:cookies] = cookies unless cookies.nil?
|
90
|
+
end
|
91
|
+
|
92
|
+
if convert_to_get?(response)
|
93
|
+
env[:method] = :get
|
94
|
+
env[:body] = nil
|
95
|
+
else
|
96
|
+
env[:body] = request_body
|
97
|
+
end
|
98
|
+
|
99
|
+
ENV_TO_CLEAR.each {|key| env.delete key }
|
100
|
+
|
101
|
+
env
|
102
|
+
end
|
103
|
+
|
104
|
+
def follow_redirect?(env, response)
|
105
|
+
ALLOWED_METHODS.include? env[:method] and
|
106
|
+
REDIRECT_CODES.include? response.status
|
107
|
+
end
|
108
|
+
|
109
|
+
def follow_limit
|
110
|
+
@options.fetch(:limit, FOLLOW_LIMIT)
|
111
|
+
end
|
112
|
+
|
113
|
+
def keep_cookies(env)
|
114
|
+
cookies = @options.fetch(:cookies, [])
|
115
|
+
response_cookies = env[:response_headers][:cookies]
|
116
|
+
cookies == :all ? response_cookies : selected_request_cookies(response_cookies)
|
117
|
+
end
|
118
|
+
|
119
|
+
def selected_request_cookies(cookies)
|
120
|
+
selected_cookies(cookies)[0...-1]
|
121
|
+
end
|
122
|
+
|
123
|
+
def selected_cookies(cookies)
|
124
|
+
"".tap do |cookie_string|
|
125
|
+
@options[:cookies].each do |cookie|
|
126
|
+
string = /#{cookie}=?[^;]*/.match(cookies)[0] + ';'
|
127
|
+
cookie_string << string
|
128
|
+
end
|
129
|
+
end
|
130
|
+
end
|
131
|
+
|
132
|
+
def standards_compliant?
|
133
|
+
@options.fetch(:standards_compliant, false)
|
134
|
+
end
|
135
|
+
end
|
136
|
+
end
|
137
|
+
end
|
data/lib/cmis/type.rb
CHANGED
data/lib/cmis/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cmis-ruby
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
4
|
+
version: 0.4.10
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kenneth Geerts
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2014-04-
|
12
|
+
date: 2014-04-15 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: faraday
|
@@ -48,6 +48,7 @@ files:
|
|
48
48
|
- lib/cmis-ruby.rb
|
49
49
|
- lib/cmis/children.rb
|
50
50
|
- lib/cmis/connection.rb
|
51
|
+
- lib/cmis/connection/follow_redirects.rb
|
51
52
|
- lib/cmis/connection/request_modifier.rb
|
52
53
|
- lib/cmis/connection/response_parser.rb
|
53
54
|
- lib/cmis/document.rb
|
@@ -101,7 +102,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
101
102
|
version: '0'
|
102
103
|
requirements: []
|
103
104
|
rubyforge_project:
|
104
|
-
rubygems_version: 2.2.
|
105
|
+
rubygems_version: 2.2.2
|
105
106
|
signing_key:
|
106
107
|
specification_version: 4
|
107
108
|
summary: Ruby client for CMIS
|
@@ -115,4 +116,3 @@ test_files:
|
|
115
116
|
- spec/config.yml
|
116
117
|
- spec/rspec.opts
|
117
118
|
- spec/spec_helper.rb
|
118
|
-
has_rdoc: false
|