tsurezure 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/tsurezure.rb +1 -3
- data/lib/utils/http_utils.rb +3 -1
- data/lib/utils/response.rb +22 -20
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ea5a7cacb68e7a40425ab3e5bd34441a9c332011af18eb29c17d1b4efb558c57
|
4
|
+
data.tar.gz: 64375f61e8060485b344f9b25bb5e2f5287f974b0e5accad0d6f2f08a37db621
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 30f7604ff09e33af954dfba8ce4ff1d42ddcee8fe7d876060045b8519587467d0dab1ae907b3d911426f3195dceca4299c57bd27ee0f8556278675b415228b2b
|
7
|
+
data.tar.gz: 81f2b015395092371bb8452169ec4231987788bc28feb9a41c7f826bd3b0fa6a4a67ad52ef6174f7ceeae3e5e21ca088137e9d173da71f001d04492dff848533
|
data/lib/tsurezure.rb
CHANGED
@@ -86,7 +86,7 @@ class Tsurezure
|
|
86
86
|
|
87
87
|
def get_correct_middleware(request_object)
|
88
88
|
@middleware.keys.select do |pat|
|
89
|
-
HTTPUtils::URLUtils.matches_url_regex(pat, request_object[:url]) ||
|
89
|
+
HTTPUtils::URLUtils.matches_url_regex?(pat, request_object[:url]) ||
|
90
90
|
pat == '*'
|
91
91
|
end
|
92
92
|
end
|
@@ -111,8 +111,6 @@ class Tsurezure
|
|
111
111
|
res[:message].bytesize
|
112
112
|
)
|
113
113
|
|
114
|
-
# pp res
|
115
|
-
|
116
114
|
responder.respond res[:message], res[:options] || {}, res[:status], type
|
117
115
|
end
|
118
116
|
|
data/lib/utils/http_utils.rb
CHANGED
@@ -25,6 +25,8 @@ module HTTPUtils
|
|
25
25
|
end
|
26
26
|
|
27
27
|
def self.url_path_matches?(url, path)
|
28
|
+
return true if url == path
|
29
|
+
|
28
30
|
split_url = url.split '/'
|
29
31
|
split_path = path.split '/'
|
30
32
|
|
@@ -49,7 +51,7 @@ module HTTPUtils
|
|
49
51
|
hash_with_variables
|
50
52
|
end
|
51
53
|
|
52
|
-
def self.matches_url_regex(url, regex)
|
54
|
+
def self.matches_url_regex?(url, regex)
|
53
55
|
return unless url_path_matches? url, regex
|
54
56
|
|
55
57
|
matches = url.scan %r{((?<=\/):[^\/]+)}
|
data/lib/utils/response.rb
CHANGED
@@ -2,6 +2,19 @@
|
|
2
2
|
|
3
3
|
require_relative './http_utils' # mainly used to create http responses.
|
4
4
|
|
5
|
+
VALID_METHODS = %w[
|
6
|
+
CONNECT COPY DELETE GET HEAD
|
7
|
+
LINK LOCK MKCOL MOVE OPTIONS
|
8
|
+
PATCH POST PROPFIND PROPPATCH
|
9
|
+
PURGE PUT TRACE UNLINK UNLOCK
|
10
|
+
VIEW
|
11
|
+
].freeze
|
12
|
+
|
13
|
+
CHECK_METHOD_WARNING = "not found. \
|
14
|
+
please ensure you're using the right method!"
|
15
|
+
|
16
|
+
INVALID_METHOD_WARNING = 'an invalid method was used!'
|
17
|
+
|
5
18
|
##
|
6
19
|
# module for handling all incoming requests to the server
|
7
20
|
# stands for TsurezureResponse
|
@@ -9,36 +22,24 @@ module TResponse
|
|
9
22
|
include HTTPUtils
|
10
23
|
# anything that will be needed to create responses
|
11
24
|
class Utils
|
25
|
+
attr_reader :valid_methods
|
26
|
+
|
12
27
|
def initialize
|
13
|
-
@valid_methods =
|
14
|
-
CONNECT COPY DELETE GET HEAD
|
15
|
-
LINK LOCK MKCOL MOVE OPTIONS
|
16
|
-
OPTIONS PATCH POST PROPFIND
|
17
|
-
PROPPATCH PURGE PUT TRACE
|
18
|
-
UNLINK UNLOCK VIEW
|
19
|
-
]
|
28
|
+
@valid_methods = VALID_METHODS
|
20
29
|
end
|
21
30
|
|
22
|
-
attr_reader :valid_methods
|
23
|
-
|
24
31
|
def self.validate_request(request_params)
|
25
32
|
# make sure the user has provided a valid http
|
26
33
|
# method, a valid uri, and a valid response /
|
27
34
|
# response type
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
OPTIONS PATCH POST PROPFIND
|
32
|
-
PROPPATCH PURGE PUT TRACE
|
33
|
-
UNLINK UNLOCK VIEW
|
34
|
-
]
|
35
|
-
|
36
|
-
return false unless valid_methods.include? request_params[:method]
|
35
|
+
return true if VALID_METHODS.include? request_params[:method]
|
36
|
+
|
37
|
+
Logbook::Dev.log(INVALID_METHOD_WARNING)
|
37
38
|
end
|
38
39
|
|
39
40
|
def self.get_correct_endpoint(request_object, endpoints)
|
40
41
|
endpoints.keys.select do |pat|
|
41
|
-
HTTPUtils::URLUtils.matches_url_regex(pat, request_object[:url])
|
42
|
+
HTTPUtils::URLUtils.matches_url_regex?(pat, request_object[:url])
|
42
43
|
end
|
43
44
|
end
|
44
45
|
|
@@ -61,8 +62,9 @@ module TResponse
|
|
61
62
|
@endpoints = endpoints[request[:method]]
|
62
63
|
|
63
64
|
# if no endpoint, respond with root endpoint or 404 middleware
|
64
|
-
|
65
65
|
unless Utils.ensure_response(request, @endpoints) == true
|
66
|
+
Logbook::Dev.log(CHECK_METHOD_WARNING)
|
67
|
+
|
66
68
|
return { options: { content_type: 'application/json' },
|
67
69
|
code: 22, status: 404,
|
68
70
|
message: { status: 404, message: 'undefined endpoint' }.to_json }
|