adelnor 0.0.4 → 0.0.5
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/Gemfile +3 -0
- data/Gemfile.lock +21 -0
- data/README.md +49 -11
- data/adelnor.gemspec +6 -2
- data/lib/adelnor/request.rb +5 -3
- data/lib/adelnor/response.rb +2 -0
- data/lib/adelnor/server.rb +30 -24
- data/lib/adelnor/version.rb +3 -1
- data/lib/adelnor.rb +2 -0
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6f634fb86e2eac72d5c27144656ee18cc978787a7afdfce6dcef3f1d16f9c0f6
|
4
|
+
data.tar.gz: 8a0f3fbbc2aa790adf6ffe23a3917755aac17137dd582df726d3310dadcf3215
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9dba8f7beb9c87a4a85bfbc873238fdb9e5da4303a1a4a29f520762dc9e975d53bc971d867cfe41b9fd9c30aea697706bf0bb7310d6cf988f9a0c4fdcfa3a53d
|
7
|
+
data.tar.gz: 49c096d7c9aefcfd4ca6f0798a7d619b36c27a7b4f2d5ddeffac2c68188365a265126b7b58ca7422679029a90d81a7c0834ab8e777fb0be471d53c2a330bab1b
|
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,13 +1,34 @@
|
|
1
1
|
GEM
|
2
2
|
remote: https://rubygems.org/
|
3
3
|
specs:
|
4
|
+
ast (2.4.2)
|
5
|
+
parallel (1.22.1)
|
6
|
+
parser (3.1.2.0)
|
7
|
+
ast (~> 2.4.1)
|
4
8
|
rack (2.2.3)
|
9
|
+
rainbow (3.1.1)
|
10
|
+
regexp_parser (2.4.0)
|
11
|
+
rexml (3.2.5)
|
12
|
+
rubocop (1.29.1)
|
13
|
+
parallel (~> 1.10)
|
14
|
+
parser (>= 3.1.0.0)
|
15
|
+
rainbow (>= 2.2.2, < 4.0)
|
16
|
+
regexp_parser (>= 1.8, < 3.0)
|
17
|
+
rexml (>= 3.2.5, < 4.0)
|
18
|
+
rubocop-ast (>= 1.17.0, < 2.0)
|
19
|
+
ruby-progressbar (~> 1.7)
|
20
|
+
unicode-display_width (>= 1.4.0, < 3.0)
|
21
|
+
rubocop-ast (1.18.0)
|
22
|
+
parser (>= 3.1.1.0)
|
23
|
+
ruby-progressbar (1.11.0)
|
24
|
+
unicode-display_width (2.1.0)
|
5
25
|
|
6
26
|
PLATFORMS
|
7
27
|
aarch64-linux
|
8
28
|
|
9
29
|
DEPENDENCIES
|
10
30
|
rack
|
31
|
+
rubocop
|
11
32
|
|
12
33
|
BUNDLED WITH
|
13
34
|
2.3.3
|
data/README.md
CHANGED
@@ -1,21 +1,59 @@
|
|
1
|
-
#
|
1
|
+
# adelnor
|
2
2
|
|
3
|
-
|
3
|
+

|
4
|
+

|
5
|
+

|
4
6
|
|
5
|
-
|
7
|
+

|
8
|
+
[](https://github.com/rubocop/rubocop)
|
9
|
+
[](https://rubystyle.guide)
|
10
|
+
``` .___ .__
|
11
|
+
_____ __| _/____ | | ____ ___________
|
12
|
+
\__ \ / __ |/ __ \| | / \ / _ \_ __ \
|
13
|
+
/ __ \_/ /_/ \ ___/| |_| | ( <_> ) | \/
|
14
|
+
(____ /\____ |\___ >____/___| /\____/|__|
|
15
|
+
\/ \/ \/ \/
|
16
|
+
```
|
17
|
+
|
18
|
+
[adelnor](https://rubygems.org/gems/adelnor) is a dead simple, yet Rack-compatible, HTTP server written in Ruby.
|
19
|
+
|
20
|
+
## Requirements
|
6
21
|
|
22
|
+
Ruby
|
23
|
+
|
24
|
+
## Installation
|
7
25
|
```bash
|
8
|
-
|
9
|
-
make sample.server
|
26
|
+
$ gem install adelnor
|
10
27
|
```
|
11
28
|
|
12
|
-
|
29
|
+
## Development tooling
|
30
|
+
|
31
|
+
Make and Docker
|
32
|
+
|
33
|
+
## Using make
|
13
34
|
|
14
|
-
|
35
|
+
```bash
|
36
|
+
$ make help
|
37
|
+
```
|
38
|
+
Output:
|
39
|
+
```
|
40
|
+
Usage: make <target>
|
41
|
+
help Prints available commands
|
42
|
+
sample.server Runs a sample server in the port 3000
|
43
|
+
bundle.install Installs the Ruby gems
|
44
|
+
bash Creates a container Bash
|
45
|
+
run.tests Runs Unit tests
|
46
|
+
rubocop Runs code linter
|
47
|
+
ci Runs Unit tests in CI
|
48
|
+
gem.publish Publishes the gem to https://rubygems.org (auth required)
|
49
|
+
gem.yank Removes a specific version from the Rubygems
|
50
|
+
```
|
51
|
+
|
52
|
+
## Running a sample server in development
|
15
53
|
|
16
54
|
```bash
|
17
|
-
make
|
18
|
-
make
|
19
|
-
make gem.signin # sign in to rubygems.org using owner credentials
|
20
|
-
make gem.push # push gem to rubygems.org
|
55
|
+
$ make bundle.install
|
56
|
+
$ make sample.server
|
21
57
|
```
|
58
|
+
|
59
|
+
Open `http://localhost:3000`
|
data/adelnor.gemspec
CHANGED
@@ -1,11 +1,15 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
Gem::Specification.new do |spec|
|
2
4
|
spec.name = 'adelnor'
|
3
|
-
spec.version = '0.0.
|
5
|
+
spec.version = '0.0.5'
|
4
6
|
spec.summary = 'Adelnor HTTP server'
|
5
7
|
spec.description = 'A dead simple, yet Rack-compatible, HTTP server written in Ruby'
|
6
8
|
spec.authors = ['Leandro Proença']
|
7
9
|
spec.email = 'leandronsp@gmail.com'
|
8
|
-
spec.files = Dir['lib/**/*'] + %w
|
10
|
+
spec.files = Dir['lib/**/*'] + %w[Gemfile Gemfile.lock README.md adelnor.gemspec]
|
9
11
|
spec.homepage = 'https://github.com/leandronsp/adelnor'
|
10
12
|
spec.license = 'MIT'
|
13
|
+
|
14
|
+
spec.required_ruby_version = '~> 3.0'
|
11
15
|
end
|
data/lib/adelnor/request.rb
CHANGED
@@ -1,7 +1,9 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Adelnor
|
2
4
|
class Request
|
3
5
|
attr_reader :request_method, :request_path, :headers, :body,
|
4
|
-
|
6
|
+
:content_length, :path_info, :query_string
|
5
7
|
|
6
8
|
def initialize(message)
|
7
9
|
@message = message
|
@@ -35,9 +37,9 @@ module Adelnor
|
|
35
37
|
private
|
36
38
|
|
37
39
|
def parse_headline!(line)
|
38
|
-
return unless line.match(
|
40
|
+
return unless line.match(%r{HTTP/.*?})
|
39
41
|
|
40
|
-
@request_method, @request_path,
|
42
|
+
@request_method, @request_path, = line.split
|
41
43
|
@path_info, @query_string = @request_path.split('?')
|
42
44
|
end
|
43
45
|
|
data/lib/adelnor/response.rb
CHANGED
data/lib/adelnor/server.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'socket'
|
2
4
|
require 'rack'
|
3
5
|
require 'stringio'
|
@@ -26,40 +28,44 @@ module Adelnor
|
|
26
28
|
def rack_data(request)
|
27
29
|
{
|
28
30
|
'REQUEST_METHOD' => request.request_method,
|
29
|
-
'PATH_INFO'
|
30
|
-
'QUERY_STRING'
|
31
|
-
'SERVER_PORT'
|
32
|
-
'SERVER_NAME'
|
31
|
+
'PATH_INFO' => request.path_info,
|
32
|
+
'QUERY_STRING' => request.query_string,
|
33
|
+
'SERVER_PORT' => @port,
|
34
|
+
'SERVER_NAME' => request.headers['Host'],
|
33
35
|
'CONTENT_LENGTH' => request.content_length,
|
34
|
-
'HTTP_COOKIE'
|
35
|
-
'rack.input'
|
36
|
+
'HTTP_COOKIE' => request.headers['Cookie'],
|
37
|
+
'rack.input' => StringIO.new(request.body)
|
36
38
|
}.merge(request.headers)
|
37
39
|
end
|
38
40
|
|
39
41
|
def run
|
40
42
|
loop do
|
41
|
-
client,
|
43
|
+
client, = @socket.accept
|
42
44
|
|
43
|
-
|
44
|
-
.then { |message| Request.build(message) }
|
45
|
-
.tap { |request| request.parse_body!(client) }
|
46
|
-
.then { |request| rack_data(request) }
|
47
|
-
.then { |data| @rack_app.call(data) }
|
48
|
-
.then { |result| Response.build(*result) }
|
49
|
-
.then { |response| client.puts(response) }
|
45
|
+
handle(client)
|
50
46
|
|
51
47
|
client.close
|
52
48
|
end
|
53
49
|
end
|
54
50
|
|
51
|
+
def handle(client)
|
52
|
+
read_request_message(client)
|
53
|
+
.then { |message| Request.build(message) }
|
54
|
+
.tap { |request| request.parse_body!(client) }
|
55
|
+
.then { |request| rack_data(request) }
|
56
|
+
.then { |data| @rack_app.call(data) }
|
57
|
+
.then { |result| Response.build(*result) }
|
58
|
+
.then { |response| client.puts(response) }
|
59
|
+
end
|
60
|
+
|
55
61
|
def read_request_message(client)
|
56
62
|
message = ''
|
57
63
|
|
58
|
-
|
64
|
+
message += client.gets
|
59
65
|
puts
|
60
66
|
puts "[#{Time.now}] #{message}"
|
61
67
|
|
62
|
-
while line = client.gets
|
68
|
+
while (line = client.gets)
|
63
69
|
break if line == "\r\n"
|
64
70
|
|
65
71
|
message += line
|
@@ -69,17 +75,17 @@ module Adelnor
|
|
69
75
|
end
|
70
76
|
|
71
77
|
def welcome_message
|
72
|
-
|
73
|
-
|\---/|
|
74
|
-
| o_o |
|
75
|
-
|
78
|
+
<<~WELCOME
|
79
|
+
|\---/|
|
80
|
+
| o_o |
|
81
|
+
\_^_/
|
76
82
|
|
77
|
-
adelnor HTTP server
|
83
|
+
adelnor HTTP server
|
78
84
|
|
79
|
-
------------------------------------------------
|
85
|
+
------------------------------------------------
|
80
86
|
|
81
|
-
Adelnor is running at http://0.0.0.0:#{@port}
|
82
|
-
Listening to HTTP connections
|
87
|
+
Adelnor is running at http://0.0.0.0:#{@port}
|
88
|
+
Listening to HTTP connections
|
83
89
|
WELCOME
|
84
90
|
end
|
85
91
|
end
|
data/lib/adelnor/version.rb
CHANGED
data/lib/adelnor.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: adelnor
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Leandro Proença
|
@@ -35,9 +35,9 @@ require_paths:
|
|
35
35
|
- lib
|
36
36
|
required_ruby_version: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- - "
|
38
|
+
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: '0'
|
40
|
+
version: '3.0'
|
41
41
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
42
42
|
requirements:
|
43
43
|
- - ">="
|