adelnor 0.0.4 → 0.0.5

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: 8fd3bdc715084ebccf29d504de4cbba7346dbc8c985f5434c70d8fa4547c3d76
4
- data.tar.gz: 41b0ba8c691e39cc7e2e77f508d450b7f74ec52c2cd75defaa8497982d0a2338
3
+ metadata.gz: 6f634fb86e2eac72d5c27144656ee18cc978787a7afdfce6dcef3f1d16f9c0f6
4
+ data.tar.gz: 8a0f3fbbc2aa790adf6ffe23a3917755aac17137dd582df726d3310dadcf3215
5
5
  SHA512:
6
- metadata.gz: 9756b4e0d68b17cb1dacc39e6eebd4b549b1dd5fe8b820174e865bceaf04a1cee252868bac89e4c8b7f4bfebea7d0421e29cf5e5972eb02dcba0efa32866dce5
7
- data.tar.gz: a8f6604f3167d7dccbb7c4a0853714f2fe1edcd2b35d0c3e9e40b9699bd9f92020a333c0ab55451b891be04f090bf5a5a48676deee6f330494b5113f260707a5
6
+ metadata.gz: 9dba8f7beb9c87a4a85bfbc873238fdb9e5da4303a1a4a29f520762dc9e975d53bc971d867cfe41b9fd9c30aea697706bf0bb7310d6cf988f9a0c4fdcfa3a53d
7
+ data.tar.gz: 49c096d7c9aefcfd4ca6f0798a7d619b36c27a7b4f2d5ddeffac2c68188365a265126b7b58ca7422679029a90d81a7c0834ab8e777fb0be471d53c2a330bab1b
data/Gemfile CHANGED
@@ -1,3 +1,6 @@
1
+ # frozen_string_literal: true
2
+
1
3
  source 'https://rubygems.org'
2
4
 
3
5
  gem 'rack'
6
+ gem 'rubocop', require: false
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
- # Adelnor
1
+ # adelnor
2
2
 
3
- A dead simple, yet Rack-compatible, HTTP server written in Ruby
3
+ ![rubygems](https://badgen.net/rubygems/n/adelnor)
4
+ ![rubygems](https://badgen.net/rubygems/v/adelnor)
5
+ ![rubygems](https://badgen.net/rubygems/dt/adelnor)
4
6
 
5
- ## Running a sample server in development
7
+ ![Build](https://github.com/leandronsp/adelnor/actions/workflows/build.yml/badge.svg)
8
+ [![Ruby Style Guide](https://img.shields.io/badge/code_style-rubocop-brightgreen.svg)](https://github.com/rubocop/rubocop)
9
+ [![Ruby Style Guide](https://img.shields.io/badge/code_style-community-brightgreen.svg)](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
- make bundle.install
9
- make sample.server
26
+ $ gem install adelnor
10
27
  ```
11
28
 
12
- Open `http://localhost:3000`
29
+ ## Development tooling
30
+
31
+ Make and Docker
32
+
33
+ ## Using make
13
34
 
14
- ## Publishing the gem
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 gem.build
18
- make gem.install # locally
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.4'
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(Gemfile Gemfile.lock README.md adelnor.gemspec)
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
@@ -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
- :content_length, :path_info, :query_string
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(/HTTP\/.*?/)
40
+ return unless line.match(%r{HTTP/.*?})
39
41
 
40
- @request_method, @request_path, _ = line.split
42
+ @request_method, @request_path, = line.split
41
43
  @path_info, @query_string = @request_path.split('?')
42
44
  end
43
45
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Adelnor
2
4
  class Response
3
5
  def initialize(status, headers, body)
@@ -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' => request.path_info,
30
- 'QUERY_STRING' => request.query_string,
31
- 'SERVER_PORT' => @port,
32
- 'SERVER_NAME' => request.headers['Host'],
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' => request.headers['Cookie'],
35
- 'rack.input' => StringIO.new(request.body)
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, _ = @socket.accept
43
+ client, = @socket.accept
42
44
 
43
- read_request_message(client)
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
- message += client.gets
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
- <<-WELCOME
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
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Adelnor
2
- VERSION = "0.0.4"
4
+ VERSION = '0.0.5'
3
5
  end
data/lib/adelnor.rb CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require_relative './adelnor/server'
2
4
  require_relative './adelnor/request'
3
5
  require_relative './adelnor/response'
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
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
  - - ">="