itsi-server 0.2.5 → 0.2.6

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e905bf6be508587ee73d0f537d422cb9dac5649529784b9009d7b206f4e1f338
4
- data.tar.gz: 850add0021ebbace5ff48a990ddbef13154355cc9009d09275d9ebf3d11064dd
3
+ metadata.gz: 5e35db14d9bab3c6242ac77ed848ced5bc848d9d46b4113029859c2e1d984773
4
+ data.tar.gz: 0a3c7930f80c67ea454ee29fff76906c70465f8f6e36ec903196f89d799dc4de
5
5
  SHA512:
6
- metadata.gz: a0569596062fafb1a7613e6dad2db993c99b9e0bec881eedb068938cba60a4646d0b8cd91ff9b74e2bbb25fb2ec6698e58f566265cb6a89a65d088cffbc66b3d
7
- data.tar.gz: 8f0d9a03c1997da8c03752453af45b7732c13dcf44e6c939b7ad010b919052851f411269c6a0b7427ec53c4a1cbf2fd73f0d8a778e5e1ddc715e4c287c009d92
6
+ metadata.gz: 6e76c2016dc1d48492193bafa6e6d8af88a04affb4826745932a3060b8cf11351b84d06e12c87599cfc854a954dd17a628f8838affb4e9290937a829b5f22a31
7
+ data.tar.gz: b4f0b820e974710250ce2c776ebf7b8911668be9f9b6ade947023ebd3fb7f9770e6a07df348aaf38d385624771befaf531522d4bf44cb61c504356f8db960945
data/Cargo.lock CHANGED
@@ -1644,7 +1644,7 @@ checksum = "4a5f13b858c8d314ee3e8f639011f7ccefe71f97f96e50151fb991f267928e2c"
1644
1644
 
1645
1645
  [[package]]
1646
1646
  name = "itsi-server"
1647
- version = "0.2.5"
1647
+ version = "0.2.6"
1648
1648
  dependencies = [
1649
1649
  "argon2",
1650
1650
  "async-channel",
@@ -1,6 +1,6 @@
1
1
  [package]
2
2
  name = "itsi-scheduler"
3
- version = "0.2.5"
3
+ version = "0.2.6"
4
4
  edition = "2021"
5
5
  authors = ["Wouter Coppieters <wc@pico.net.nz>"]
6
6
  license = "MIT"
@@ -1,6 +1,6 @@
1
1
  [package]
2
2
  name = "itsi-server"
3
- version = "0.2.5"
3
+ version = "0.2.6"
4
4
  edition = "2021"
5
5
  authors = ["Wouter Coppieters <wc@pico.net.nz>"]
6
6
  license = "MIT"
@@ -662,7 +662,7 @@ impl StaticFileServer {
662
662
  let range_length = end - start + 1;
663
663
  let limited_reader = tokio::io::AsyncReadExt::take(file, range_length);
664
664
  let path_clone = path.clone();
665
- let stream = ReaderStream::new(limited_reader)
665
+ let stream = ReaderStream::with_capacity(limited_reader, 64 * 1024)
666
666
  .map_ok(Frame::data)
667
667
  .map_err(move |e| {
668
668
  warn!("Error streaming file {}: {}", path_clone.display(), e);
@@ -681,7 +681,7 @@ impl StaticFileServer {
681
681
  match File::open(&path).await {
682
682
  Ok(file) => {
683
683
  let path_clone = path.clone();
684
- let stream = ReaderStream::new(file)
684
+ let stream = ReaderStream::with_capacity(file, 64 * 1024)
685
685
  .map_ok(Frame::data)
686
686
  .map_err(move |e| {
687
687
  warn!("Error streaming file {}: {}", path_clone.display(), e);
@@ -25,56 +25,73 @@ module Itsi
25
25
  hm.default_proc = proc { |_, key| "HTTP_#{key.upcase.gsub(/-/, "_")}" }
26
26
  end
27
27
 
28
+ RACK_ENV_TEMPLATE = {
29
+ "SERVER_SOFTWARE" => "Itsi",
30
+ "rack.errors" => $stderr,
31
+ "rack.multithread" => true,
32
+ "rack.multiprocess" => true,
33
+ "rack.run_once" => false,
34
+ "rack.hijack?" => true,
35
+ "rack.multipart.buffer_size" => 16_384,
36
+ "SCRIPT_NAME" => "",
37
+ "REQUEST_METHOD" => "",
38
+ "PATH_INFO" => "",
39
+ "REQUEST_PATH" => "",
40
+ "QUERY_STRING" => "",
41
+ "REMOTE_ADDR" => "",
42
+ "SERVER_PORT" => "",
43
+ "SERVER_NAME" => "",
44
+ "SERVER_PROTOCOL" => "",
45
+ "HTTP_HOST" => "",
46
+ "HTTP_VERSION" => "",
47
+ "itsi.request" => "",
48
+ "itsi.response" => "",
49
+ "rack.version" => [nil],
50
+ "rack.url_scheme" => "",
51
+ "rack.input" => "",
52
+ "rack.hijack" => "",
53
+ "CONTENT_TYPE" => nil,
54
+ "CONTENT_LENGTH" => nil
55
+ }.freeze
56
+
28
57
  def to_rack_env
29
58
  path = self.path
30
59
  host = self.host
31
60
  version = self.version
32
-
33
- {
34
- "SERVER_SOFTWARE" => "Itsi",
35
- "SCRIPT_NAME" => script_name,
36
- "REQUEST_METHOD" => request_method,
37
- "PATH_INFO" => path,
38
- "REQUEST_PATH" => path,
39
- "QUERY_STRING" => query_string,
40
- "REMOTE_ADDR" => remote_addr,
41
- "SERVER_PORT" => port.to_s,
42
- "SERVER_NAME" => host,
43
- "SERVER_PROTOCOL" => version,
44
- "HTTP_HOST" => host,
45
- "HTTP_VERSION" => version,
46
- "itsi.request" => self,
47
- "itsi.response" => response,
48
- "rack.version" => [version],
49
- "rack.url_scheme" => scheme,
50
- "rack.input" => build_input_io,
51
- "rack.errors" => $stderr,
52
- "rack.multithread" => true,
53
- "rack.multiprocess" => true,
54
- "rack.run_once" => false,
55
- "rack.hijack?" => true,
56
- "rack.multipart.buffer_size" => 16_384,
57
- "rack.hijack" => method(:hijack)
58
- }.tap do |r|
59
- headers.each do |(k, v)|
60
- r[case k
61
- when "content-type" then "CONTENT_TYPE"
62
- when "content-length" then "CONTENT_LENGTH"
63
- when "accept" then "HTTP_ACCEPT"
64
- when "accept-encoding" then "HTTP_ACCEPT_ENCODING"
65
- when "accept-language" then "HTTP_ACCEPT_LANGUAGE"
66
- when "user-agent" then "HTTP_USER_AGENT"
67
- when "referer" then "HTTP_REFERER"
68
- when "origin" then "HTTP_ORIGIN"
69
- when "cookie" then "HTTP_COOKIE"
70
- when "authorization" then "HTTP_AUTHORIZATION"
71
- when "x-forwarded-for" then "HTTP_X_FORWARDED_FOR"
72
- when "x-forwarded-proto" then "HTTP_X_FORWARDED_PROTO"
73
- else RACK_HEADER_MAP[k]
74
- end
75
- ] = v
76
- end
61
+ env = RACK_ENV_TEMPLATE.dup
62
+ env["SCRIPT_NAME"] = script_name
63
+ env["REQUEST_METHOD"] = request_method
64
+ env["REQUEST_PATH"] = env["PATH_INFO"] = path
65
+ env["QUERY_STRING"] = query_string
66
+ env["REMOTE_ADDR"] = remote_addr
67
+ env["SERVER_PORT"] = port.to_s
68
+ env["HTTP_HOST"] = env["SERVER_NAME"] = host
69
+ env["HTTP_VERSION"] = env["SERVER_PROTOCOL"] = version
70
+ env["itsi.request"] = self
71
+ env["itsi.response"] = response
72
+ env["rack.version"][0] = version
73
+ env["rack.url_scheme"] = scheme
74
+ env["rack.input"] = build_input_io
75
+ env["rack.hijack"] = method(:hijack)
76
+ headers.each do |(k, v)|
77
+ env[case k
78
+ when "content-type" then "CONTENT_TYPE"
79
+ when "content-length" then "CONTENT_LENGTH"
80
+ when "accept" then "HTTP_ACCEPT"
81
+ when "accept-encoding" then "HTTP_ACCEPT_ENCODING"
82
+ when "accept-language" then "HTTP_ACCEPT_LANGUAGE"
83
+ when "user-agent" then "HTTP_USER_AGENT"
84
+ when "referer" then "HTTP_REFERER"
85
+ when "origin" then "HTTP_ORIGIN"
86
+ when "cookie" then "HTTP_COOKIE"
87
+ when "authorization" then "HTTP_AUTHORIZATION"
88
+ when "x-forwarded-for" then "HTTP_X_FORWARDED_FOR"
89
+ when "x-forwarded-proto" then "HTTP_X_FORWARDED_PROTO"
90
+ else RACK_HEADER_MAP[k]
91
+ end
92
+ ] = v
77
93
  end
94
+ env
78
95
  end
79
96
 
80
97
  def respond(
@@ -13,7 +13,6 @@ Under the covers it:
13
13
  3. Automatically enables `gRPC` reflection (so client like `evans`, `grpcurl` or `Postman` can discover your service endpoints without needing access to raw `.proto` files).
14
14
  4. Supports optional per‑call compression (`none`, `deflate`, `gzip`) and a non‑blocking execution mode.
15
15
 
16
- ---
17
16
 
18
17
  ## Usage
19
18
 
@@ -97,8 +96,7 @@ require_relative 'echo_service_impl'
97
96
 
98
97
  bind "https://localhost:3000"
99
98
  grpc EchoServiceImpl.new,
100
- nonblocking: false,
101
- compression: 'gzip' do
99
+ nonblocking: false do
102
100
  # Nested middleware still works:
103
101
  response_headers additions: { 'X-Service' => ['Echo'] }
104
102
  end
@@ -48,7 +48,7 @@ end
48
48
  ```ruby {filename="Itsi.rb"}
49
49
  # Match on non-route options.
50
50
  # Redirect http requests to https requests
51
- location protocols: ["http"]
51
+ location schemes: ["http"]
52
52
  redirect type: :permanent, to: "https://{host}{path_and_query}"
53
53
  end
54
54
  ```
@@ -101,7 +101,7 @@ Pass these to the location block using keyword arguments, e.g.
101
101
 
102
102
  ```ruby
103
103
  # Redirect all http JSON requests to use https exclusively.
104
- location protocols: ["http"], content_types: ["application/json"]
104
+ location schemes: ["http"], content_types: ["application/json"]
105
105
  redirect type: :permanent, to: "https://{host}{path_and_query}"
106
106
  end
107
107
  ```
@@ -21,7 +21,7 @@ log_requests \
21
21
  ```
22
22
 
23
23
 
24
- The log statement can populated with several different placeholders.
24
+ The log statement can populated with several different placeholders, using [String Rewrite](/middleware/string_rewrite) functionality.
25
25
  Available values are:
26
26
 
27
27
  ### `before` Format String
@@ -46,6 +46,8 @@ Available values are:
46
46
  * `response_time` - The response time in milliseconds
47
47
  * `<Header-Name>`: Any existing response header. For example `{Content-Type}` or `{Set-Cookie}` will be replaced with its current value.
48
48
 
49
+ See [String Rewrite](/middleware/string_rewrite) for more advanced string manipulation options.
50
+
49
51
 
50
52
  ### Path Attributes
51
53
  In addition to this, any capture groups referenced by container location blocks
@@ -9,13 +9,13 @@ The Reverse Proxy middleware enables reverse proxying by forwarding incoming HTT
9
9
 
10
10
  ```ruby
11
11
  proxy \
12
- to: "http://backend.example.com/api{path}{query}", \
13
- backends: ["127.0.0.1:3001", "127.0.0.1:3002"], \
14
- backend_priority: "round_robin", \
15
- headers: { "X-Forwarded-For" => { rewrite: "{addr}" } }, \
16
- verify_ssl: false, \
17
- timeout: 30, \
18
- tls_sni: true, \
12
+ to: "http://backend.example.com/api{path}{query}",
13
+ backends: ["127.0.0.1:3001", "127.0.0.1:3002"],
14
+ backend_priority: "round_robin",
15
+ headers: { "X-Forwarded-For" => { rewrite: "{addr}" } },
16
+ verify_ssl: false,
17
+ timeout: 30,
18
+ tls_sni: true,
19
19
  error_response: "bad_gateway"
20
20
  ```
21
21
  ## Options
@@ -6,6 +6,8 @@ url: /options/reuse_address
6
6
  Configures whether the server should bind to the underlying socket using the `SO_REUSEADDR` option.
7
7
  This option determines whether the server allows the reuse of local addresses during binding. This can be useful in scenarios where a socket needs to be quickly rebound without waiting for the operating system to release the address.
8
8
 
9
+ The default value is `false`.
10
+
9
11
  ## Configuration
10
12
  ```ruby {filename=Itsi.rb}
11
13
  reuse_address true
@@ -10,7 +10,7 @@ module Itsi
10
10
  detail "Configures whether the server should set the reuse_address option on the underlying socket."
11
11
 
12
12
  schema do
13
- (Bool() & Required()).default(true)
13
+ (Bool() & Required()).default(false)
14
14
  end
15
15
 
16
16
  end
@@ -6,6 +6,8 @@ url: /options/reuse_port
6
6
  Configures whether the server should bind to the underlying socket using the `SO_REUSEPORT` option.
7
7
  This option determines whether multiple sockets can listen on the same IP and port combination, which can improve load balancing and fault tolerance in multi-threaded or multi-process server applications.
8
8
 
9
+ The default value is `false`.
10
+
9
11
  ## Configuration
10
12
  ```ruby {filename=Itsi.rb}
11
13
  reuse_port true
@@ -10,7 +10,7 @@ module Itsi
10
10
  detail "Configures whether the server should set the reuse_port option on the underlying socket."
11
11
 
12
12
  schema do
13
- (Bool() & Required()).default(true)
13
+ (Bool() & Required()).default(false)
14
14
  end
15
15
 
16
16
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Itsi
4
4
  class Server
5
- VERSION = "0.2.5"
5
+ VERSION = "0.2.6"
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: itsi-server
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.5
4
+ version: 0.2.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Wouter Coppieters