httpme 0.1.6 → 0.2.0

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: b6016f8e2721f79749d9432b1bd9489de9307df9f5ff2651e8e12e30cf7633a7
4
- data.tar.gz: 7c6c427e893051b9f67ebcfb203f5400ee776fdf4c0b5e65319e47f8e5e41a96
3
+ metadata.gz: 99af7b72919ce9067c213da74800f672b83bc32c4ed9aaa138b3b054c5e27d87
4
+ data.tar.gz: 9aab9343681890a51d0a3fa903fa52724866fc6c8829119047b4af62900b204f
5
5
  SHA512:
6
- metadata.gz: 4979cb2101027aade89204a4b1814be815ff2b2dbbf37c32aedfbafe181095af671f3b6b47d6d4cb0adb10254ca2d33cf95dee14aaca125ef7bdc60983384081
7
- data.tar.gz: 466bc485b93d89984873fde23180255b8ca82b65ae2410aefe0ec419c6f923bb08ddffa43e0cb8411ed3df162caf4f718645d63a20a7482c225ea3279ae6cc1d
6
+ metadata.gz: a6d80f36f71b0dbc774b15f4d066b3dc55a31ae38e9c10d91796ade658927731cc61f64a1eda16a4fdbc17065b6dc898a1bd1c827ae8af4157d53346500e36c1
7
+ data.tar.gz: 8b5891bf859b15221a9507c8642d1c065a18f5572c6b5f097f260e60c0fb6cd5c562464d88028906f76e5074d02e769f2f6ca96bc5d368118a0fd83deadd7803
data/bin/httpme CHANGED
@@ -11,4 +11,4 @@ rescue => e
11
11
  puts e.backtrace.reverse if ENV['DEBUG']
12
12
  say! "!txtred!#{e.class}: #{e.message}"
13
13
  exit 1
14
- end
14
+ end
@@ -7,26 +7,26 @@ module HTTPMe
7
7
  include Colsole
8
8
 
9
9
  version HTTPMe::VERSION
10
- summary "httpme - static web server with basic authentication"
10
+ summary 'httpme - static web server with basic authentication'
11
11
 
12
- help "Options can be set using command line arguments or environment variables"
12
+ help 'Options can be set using command line arguments or environment variables'
13
13
 
14
- usage "httpme [PATH] [--port PORT --host HOST --auth AUTH]"
15
- usage "httpme (-h|--help|--version)"
14
+ usage 'httpme [PATH] [--port PORT --host HOST --auth AUTH]'
15
+ usage 'httpme (-h|--help|--version)'
16
16
 
17
- param "PATH", "Path to the directory you want to serve [default: .]"
18
- option "-p --port PORT", "Server port (default: 3000)"
19
- option "-o --host HOST", "Server host (default: 0.0.0.0)"
20
- option "-a --auth AUTH", "Specify user:password to enable basic authentication"
17
+ param 'PATH', 'Path to the directory you want to serve [default: .]'
18
+ option '-p --port PORT', 'Server port (default: 3000)'
19
+ option '-o --host HOST', 'Server host (default: 0.0.0.0)'
20
+ option '-a --auth AUTH', 'Specify user:password to enable basic authentication'
21
21
 
22
- environment 'HTTPME_PATH', "Same as the PATH argument"
23
- environment 'HTTPME_AUTH', "Same as the --auth option"
24
- environment 'HTTPME_PORT', "Same as the --port option"
25
- environment 'HTTPME_HOST', "Same as the --host option"
22
+ environment 'HTTPME_PATH', 'Same as the PATH argument'
23
+ environment 'HTTPME_AUTH', 'Same as the --auth option'
24
+ environment 'HTTPME_PORT', 'Same as the --port option'
25
+ environment 'HTTPME_HOST', 'Same as the --host option'
26
26
 
27
- example "httpme -p 4000"
28
- example "httpme docs --auth admin:s3cr3t"
29
- example "HTTPME_AUTH=admin:s3cr3t httpme docs # same result as above"
27
+ example 'httpme -p 4000'
28
+ example 'httpme docs --auth admin:s3cr3t'
29
+ example 'HTTPME_AUTH=admin:s3cr3t httpme docs # same result as above'
30
30
 
31
31
  def run
32
32
  path = args['PATH'] || ENV['HTTPME_PATH'] || '.'
@@ -36,8 +36,8 @@ module HTTPMe
36
36
 
37
37
  raise ArgumentError, "Path not found [#{path}]" unless Dir.exist? path
38
38
 
39
- server = Server.new path: path, host: host, port: port, auth: auth
40
- server.run
39
+ Server.setup path: path, host: host, port: port, auth: auth
40
+ Server.run!
41
41
  end
42
42
  end
43
43
  end
data/lib/httpme/server.rb CHANGED
@@ -1,51 +1,31 @@
1
- require 'rack'
2
- require 'rack/handler/puma'
3
- require 'httpme/index_redirector'
1
+ require 'rack/contrib/try_static'
2
+ require 'sinatra/base'
4
3
 
5
4
  module HTTPMe
6
- class Server
7
- attr_reader :options
5
+ class Server < Sinatra::Application
6
+ class << self
7
+ def setup(port: 3000, host: '0.0.0.0', path: '.', zone: 'Restricted Area', auth: nil)
8
+ reset!
8
9
 
9
- def initialize(options = {})
10
- @options = options
11
- end
12
-
13
- def run
14
- Rack::Handler::Puma.run(app, **rack_options) do |server|
15
- # :nocov: - FIXME: Can we test this?
16
- [:INT, :TERM].each do |sig|
17
- trap(sig) { server.stop }
18
- end
19
- # :nocov:
20
- end
21
- end
22
-
23
- def app
24
- path = options[:path] || '.'
25
- auth = options[:auth]
26
- zone = options[:zone] || 'Restricted Area'
10
+ set :bind, host
11
+ set :port, port
12
+ set :server, %w[puma webrick]
27
13
 
28
- Rack::Builder.new do
29
14
  if auth
30
15
  use Rack::Auth::Basic, zone do |username, password|
31
16
  auth.split(':') == [username, password]
32
17
  end
33
18
  end
34
19
 
35
- use Rack::Static, urls: ["/"], root: path, cascade: true, index: 'index.html'
36
- use IndexRedirector, root: path
37
- run Rack::Directory.new(path)
38
- end
39
- end
20
+ not_found do
21
+ content_type :text
22
+ '404 Not Found'
23
+ end
40
24
 
41
- private
25
+ use Rack::TryStatic, root: path, urls: %w[/], try: %w[.html index.html /index.html]
42
26
 
43
- def rack_options
44
- {
45
- Port: (options[:port] || '3000'),
46
- Host: (options[:host] || '0.0.0.0'),
47
- }
27
+ self
28
+ end
48
29
  end
49
-
50
30
  end
51
31
  end
@@ -1,3 +1,3 @@
1
1
  module HTTPMe
2
- VERSION = "0.1.6"
3
- end
2
+ VERSION = '0.2.0'
3
+ end
data/lib/httpme.rb CHANGED
@@ -1,2 +1,6 @@
1
1
  require 'httpme/server'
2
- require 'byebug' if ENV['BYEBUG']
2
+
3
+ if ENV['BYEBUG']
4
+ require 'byebug'
5
+ require 'lp'
6
+ end
metadata CHANGED
@@ -1,17 +1,17 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: httpme
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.6
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Danny Ben Shitrit
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-05-15 00:00:00.000000000 Z
11
+ date: 2022-11-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: mister_bin
14
+ name: colsole
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
17
  - - "~>"
@@ -25,7 +25,7 @@ dependencies:
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0.7'
27
27
  - !ruby/object:Gem::Dependency
28
- name: colsole
28
+ name: mister_bin
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - "~>"
@@ -39,33 +39,47 @@ dependencies:
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0.7'
41
41
  - !ruby/object:Gem::Dependency
42
- name: rack
42
+ name: puma
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
45
  - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: '2.2'
47
+ version: '6.0'
48
48
  type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
- version: '2.2'
54
+ version: '6.0'
55
55
  - !ruby/object:Gem::Dependency
56
- name: puma
56
+ name: rack-contrib
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '2.3'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '2.3'
69
+ - !ruby/object:Gem::Dependency
70
+ name: sinatra
57
71
  requirement: !ruby/object:Gem::Requirement
58
72
  requirements:
59
73
  - - "~>"
60
74
  - !ruby/object:Gem::Version
61
- version: '5.1'
75
+ version: '3.0'
62
76
  type: :runtime
63
77
  prerelease: false
64
78
  version_requirements: !ruby/object:Gem::Requirement
65
79
  requirements:
66
80
  - - "~>"
67
81
  - !ruby/object:Gem::Version
68
- version: '5.1'
82
+ version: '3.0'
69
83
  description: Command line utility for running a web server for static files with basic
70
84
  authentication support
71
85
  email: db@dannyben.com
@@ -79,13 +93,13 @@ files:
79
93
  - lib/httpme.rb
80
94
  - lib/httpme/cli.rb
81
95
  - lib/httpme/command.rb
82
- - lib/httpme/index_redirector.rb
83
96
  - lib/httpme/server.rb
84
97
  - lib/httpme/version.rb
85
98
  homepage: https://github.com/dannyben/httpme
86
99
  licenses:
87
100
  - MIT
88
- metadata: {}
101
+ metadata:
102
+ rubygems_mfa_required: 'true'
89
103
  post_install_message:
90
104
  rdoc_options: []
91
105
  require_paths:
@@ -94,14 +108,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
94
108
  requirements:
95
109
  - - ">="
96
110
  - !ruby/object:Gem::Version
97
- version: 2.6.0
111
+ version: 2.7.0
98
112
  required_rubygems_version: !ruby/object:Gem::Requirement
99
113
  requirements:
100
114
  - - ">="
101
115
  - !ruby/object:Gem::Version
102
116
  version: '0'
103
117
  requirements: []
104
- rubygems_version: 3.3.3
118
+ rubygems_version: 3.3.26
105
119
  signing_key:
106
120
  specification_version: 4
107
121
  summary: Static files web server with basic authentication
@@ -1,19 +0,0 @@
1
- module HTTPMe
2
- class IndexRedirector
3
- def initialize(app, root: '.')
4
- @app = app
5
- @root = root
6
- end
7
-
8
- def call(env)
9
- path_info = Rack::Utils.unescape env['PATH_INFO']
10
- path = File.join @root, path_info
11
-
12
- if File.directory?(path) and !path_info.end_with? '/'
13
- return [302, { 'Location' => "#{env['PATH_INFO']}/" }, []]
14
- end
15
-
16
- @app.call env
17
- end
18
- end
19
- end