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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1dd0633006bc7ba5837c37817e78d1f7a1fdc38520557c10a528fd40acff2573
4
- data.tar.gz: 420c2cc0bd0387c24cbe5d12b40aad574edd1e4e0f2a4bbf6b39eeb323ccdaec
3
+ metadata.gz: ea5a7cacb68e7a40425ab3e5bd34441a9c332011af18eb29c17d1b4efb558c57
4
+ data.tar.gz: 64375f61e8060485b344f9b25bb5e2f5287f974b0e5accad0d6f2f08a37db621
5
5
  SHA512:
6
- metadata.gz: 358fbcfcd4504ea64c5afad8b80f5600a4bab693e48bcf536700315ce6766b54988bf4b25e8e6aeeb71facf7773515bdf0bb0bf4c2c1fc27687f984562af0ad1
7
- data.tar.gz: 6a581bcabeb9556e2649c6893b9cfdf7553e27726f86446e35feaaba48f19126b124f0019ad45090d095704102a00e3b5834908e3ab045c70c1d11913a021636
6
+ metadata.gz: 30f7604ff09e33af954dfba8ce4ff1d42ddcee8fe7d876060045b8519587467d0dab1ae907b3d911426f3195dceca4299c57bd27ee0f8556278675b415228b2b
7
+ data.tar.gz: 81f2b015395092371bb8452169ec4231987788bc28feb9a41c7f826bd3b0fa6a4a67ad52ef6174f7ceeae3e5e21ca088137e9d173da71f001d04492dff848533
@@ -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
 
@@ -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{((?<=\/):[^\/]+)}
@@ -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 = %w[
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
- valid_methods = %w[
29
- CONNECT COPY DELETE GET HEAD
30
- LINK LOCK MKCOL MOVE OPTIONS
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 }
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tsurezure
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - jpegzilla