macaw_framework 1.4.1 → 1.4.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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +3 -0
- data/README.md +3 -10
- data/lib/macaw_framework/core/common/server_base.rb +0 -15
- data/lib/macaw_framework/core/thread_server.rb +0 -1
- data/lib/macaw_framework/version.rb +1 -1
- metadata +1 -3
- data/lib/macaw_framework/errors/too_many_requests_error.rb +0 -4
- data/lib/macaw_framework/middlewares/rate_limiter_middleware.rb +0 -31
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: b99afc6c030d78802a79875fad25f4739d0a5cc6789ad02d42faaa5699320e43
|
|
4
|
+
data.tar.gz: e1e3f6b720367cab7767b09d7c7169db61ccd38cac5c0acfaf15c9e8f475b7e7
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 1f27c7790bde337380fe1a103a4512c3eda23258e8394bbea25fec07c3f30b6dbf3daa43956d84e7c4608d6a5d0d485c81cac06c4c3bb7bec5510b6b7f6abace
|
|
7
|
+
data.tar.gz: 93d87525ce2a24d16b46ce2e5377917facf98cb52dc2d63e4858d397a80fa5c53c7f7c1406e6b9b29488c711cb0e6f57ec43c688aa770483b2c279b0fa84dd58
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
|
@@ -15,7 +15,7 @@ MacawFramework provides developers with the essential tools to quickly build and
|
|
|
15
15
|
+ [Basic routing: Define routes with support for GET, POST, PUT, PATCH, and DELETE HTTP methods](#basic-routing-define-routes-with-support-for-get-post-put-patch-and-delete-http-methods)
|
|
16
16
|
+ [Caching: Improve performance by caching responses and configuring cache invalidation](#caching-improve-performance-by-caching-responses-and-configuring-cache-invalidation)
|
|
17
17
|
+ [Session management: Handle user sessions securely with server-side in-memory storage](#session-management-handle-user-sessions-securely-with-server-side-in-memory-storage)
|
|
18
|
-
+ [Configuration: Customize various aspects of the framework through the application.json configuration file, such as
|
|
18
|
+
+ [Configuration: Customize various aspects of the framework through the application.json configuration file, such as SSL support and Prometheus integration](#configuration-customize-various-aspects-of-the-framework-through-the-applicationjson-configuration-file-such-as-ssl-support-and-prometheus-integration)
|
|
19
19
|
+ [Monitoring: Easily monitor your application performance and metrics with built-in Prometheus support](#monitoring-easily-monitor-your-application-performance-and-metrics-with-built-in-prometheus-support)
|
|
20
20
|
+ [Routing for "public" Folder: Serve Static Assets](#routing-for-public-folder-serve-static-assets)
|
|
21
21
|
+ [Periodic Jobs](#periodic-jobs)
|
|
@@ -29,7 +29,7 @@ MacawFramework provides developers with the essential tools to quickly build and
|
|
|
29
29
|
- Simple routing with support for GET, POST, PUT, PATCH, and DELETE HTTP methods
|
|
30
30
|
- Caching middleware for improved performance
|
|
31
31
|
- Session management with server-side in-memory storage
|
|
32
|
-
-
|
|
32
|
+
- SSL support
|
|
33
33
|
- Prometheus integration for monitoring and metrics
|
|
34
34
|
- Less than 26Kb
|
|
35
35
|
- Easy to learn
|
|
@@ -154,7 +154,7 @@ m.get('/dashboard') do |context|
|
|
|
154
154
|
end
|
|
155
155
|
```
|
|
156
156
|
|
|
157
|
-
### Configuration: Customize various aspects of the framework through the application.json configuration file, such as
|
|
157
|
+
### Configuration: Customize various aspects of the framework through the application.json configuration file, such as SSL support and Prometheus integration
|
|
158
158
|
|
|
159
159
|
```json
|
|
160
160
|
{
|
|
@@ -168,10 +168,6 @@ end
|
|
|
168
168
|
"prometheus": {
|
|
169
169
|
"endpoint": "/metrics"
|
|
170
170
|
},
|
|
171
|
-
"rate_limiting": {
|
|
172
|
-
"window": 10,
|
|
173
|
-
"max_requests": 3
|
|
174
|
-
},
|
|
175
171
|
"ssl": {
|
|
176
172
|
"min": "SSL3",
|
|
177
173
|
"max": "TLS1.3",
|
|
@@ -271,9 +267,6 @@ m.threads = 300
|
|
|
271
267
|
|
|
272
268
|
- The default number of virtual threads in the thread pool is 200.
|
|
273
269
|
|
|
274
|
-
- Rate Limit window should also be specified in seconds. Rate limit will be activated only if the `rate_limiting` config
|
|
275
|
-
exists inside `application.json`.
|
|
276
|
-
|
|
277
270
|
- If the SSL configuration is provided in the `application.json` file with valid certificate and key files, the TCP server
|
|
278
271
|
will be wrapped with HTTPS security using the provided certificate.
|
|
279
272
|
|
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
3
|
require_relative '../../middlewares/memory_invalidation_middleware'
|
|
4
|
-
require_relative '../../middlewares/rate_limiter_middleware'
|
|
5
4
|
require_relative '../../data_filters/response_data_filter'
|
|
6
|
-
require_relative '../../errors/too_many_requests_error'
|
|
7
5
|
require_relative '../../utils/supported_ssl_versions'
|
|
8
6
|
require_relative '../../aspects/prometheus_aspect'
|
|
9
7
|
require_relative '../../aspects/logging_aspect'
|
|
@@ -41,7 +39,6 @@ module ServerBase
|
|
|
41
39
|
def handle_client(client)
|
|
42
40
|
_path, method_name, headers, body, parameters = RequestDataFiltering.parse_request_data(client, @macaw.routes)
|
|
43
41
|
raise EndpointNotMappedError unless @macaw.respond_to?(method_name)
|
|
44
|
-
raise TooManyRequestsError unless @rate_limit.nil? || @rate_limit.allow?(client.peeraddr[3])
|
|
45
42
|
|
|
46
43
|
client_data = get_client_data(body, headers, parameters)
|
|
47
44
|
session_id = declare_client_session(client_data[:headers], @macaw.secure_header) if @macaw.session
|
|
@@ -56,8 +53,6 @@ module ServerBase
|
|
|
56
53
|
client.puts ResponseDataFilter.mount_response(status, response_headers, message)
|
|
57
54
|
rescue IOError, Errno::EPIPE => e
|
|
58
55
|
@macaw_log&.error("Error writing to client: #{e.message}")
|
|
59
|
-
rescue TooManyRequestsError
|
|
60
|
-
client.print "HTTP/1.1 429 Too Many Requests\r\n\r\n"
|
|
61
56
|
rescue EndpointNotMappedError
|
|
62
57
|
client.print "HTTP/1.1 404 Not Found\r\n\r\n"
|
|
63
58
|
rescue StandardError => e
|
|
@@ -78,15 +73,6 @@ module ServerBase
|
|
|
78
73
|
session_id
|
|
79
74
|
end
|
|
80
75
|
|
|
81
|
-
def set_rate_limiting
|
|
82
|
-
return unless @macaw.config&.dig('macaw', 'rate_limiting')
|
|
83
|
-
|
|
84
|
-
@rate_limit = RateLimiterMiddleware.new(
|
|
85
|
-
@macaw.config['macaw']['rate_limiting']['window'].to_i || 1,
|
|
86
|
-
@macaw.config['macaw']['rate_limiting']['max_requests'].to_i || 60
|
|
87
|
-
)
|
|
88
|
-
end
|
|
89
|
-
|
|
90
76
|
def set_ssl
|
|
91
77
|
ssl_config = @macaw.config['macaw']['ssl'] if @macaw.config&.dig('macaw', 'ssl')
|
|
92
78
|
ssl_config ||= nil
|
|
@@ -127,7 +113,6 @@ module ServerBase
|
|
|
127
113
|
|
|
128
114
|
def set_features
|
|
129
115
|
@is_shutting_down = false
|
|
130
|
-
set_rate_limiting
|
|
131
116
|
set_session
|
|
132
117
|
set_ssl
|
|
133
118
|
end
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: macaw_framework
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 1.4.
|
|
4
|
+
version: 1.4.2
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Aria Diniz
|
|
@@ -53,11 +53,9 @@ files:
|
|
|
53
53
|
- lib/macaw_framework/data_filters/request_data_filtering.rb
|
|
54
54
|
- lib/macaw_framework/data_filters/response_data_filter.rb
|
|
55
55
|
- lib/macaw_framework/errors/endpoint_not_mapped_error.rb
|
|
56
|
-
- lib/macaw_framework/errors/too_many_requests_error.rb
|
|
57
56
|
- lib/macaw_framework/macaw.rb
|
|
58
57
|
- lib/macaw_framework/middlewares/memory_invalidation_middleware.rb
|
|
59
58
|
- lib/macaw_framework/middlewares/prometheus_middleware.rb
|
|
60
|
-
- lib/macaw_framework/middlewares/rate_limiter_middleware.rb
|
|
61
59
|
- lib/macaw_framework/utils/http_status_code.rb
|
|
62
60
|
- lib/macaw_framework/utils/supported_ssl_versions.rb
|
|
63
61
|
- lib/macaw_framework/version.rb
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
##
|
|
4
|
-
# Middleware responsible for implementing
|
|
5
|
-
# rate limiting
|
|
6
|
-
class RateLimiterMiddleware
|
|
7
|
-
attr_reader :window_size, :max_requests
|
|
8
|
-
|
|
9
|
-
def initialize(window_size, max_requests)
|
|
10
|
-
@window_size = window_size
|
|
11
|
-
@max_requests = max_requests
|
|
12
|
-
@client_timestamps = Hash.new { |key, value| key[value] = [] }
|
|
13
|
-
@mutex = Mutex.new
|
|
14
|
-
end
|
|
15
|
-
|
|
16
|
-
def allow?(client_id)
|
|
17
|
-
@mutex.synchronize do
|
|
18
|
-
now = Time.now.to_i
|
|
19
|
-
timestamps = @client_timestamps[client_id]
|
|
20
|
-
|
|
21
|
-
timestamps.reject! { |timestamp| timestamp <= now - window_size }
|
|
22
|
-
|
|
23
|
-
if timestamps.length < max_requests
|
|
24
|
-
timestamps << now
|
|
25
|
-
true
|
|
26
|
-
else
|
|
27
|
-
false
|
|
28
|
-
end
|
|
29
|
-
end
|
|
30
|
-
end
|
|
31
|
-
end
|