httpme 0.1.6 → 0.2.1

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: fca9b62ba6b59c8f59e9bc8ea35935bdbcd9ab750657dd8d0512d491dd968121
4
+ data.tar.gz: 9783fff85113d96544534a65fe9f3f27d364417161b98c3da68871d4a000d12b
5
5
  SHA512:
6
- metadata.gz: 4979cb2101027aade89204a4b1814be815ff2b2dbbf37c32aedfbafe181095af671f3b6b47d6d4cb0adb10254ca2d33cf95dee14aaca125ef7bdc60983384081
7
- data.tar.gz: 466bc485b93d89984873fde23180255b8ca82b65ae2410aefe0ec419c6f923bb08ddffa43e0cb8411ed3df162caf4f718645d63a20a7482c225ea3279ae6cc1d
6
+ metadata.gz: d78fd7e148046922b7e4b16256b5bce7216b8b9e504be6836c289170baa76cba1d868e4d276f8da20371c661691e206dab7534f4ec48bb5ec7b5916faadcd61a
7
+ data.tar.gz: 23ab313ec7dadec1f0a684214cf54bcefd63147b78317a956ba6c080bf0963fc2ce4f5f36a4211a61cc357c4b8ba17e890f104c51124c88fbdcd4d23cf13c502
data/bin/httpme CHANGED
@@ -9,6 +9,6 @@ begin
9
9
  exit router.run ARGV
10
10
  rescue => e
11
11
  puts e.backtrace.reverse if ENV['DEBUG']
12
- say! "!txtred!#{e.class}: #{e.message}"
12
+ say! "r`#{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.1'
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,15 +1,35 @@
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.1
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: 2023-01-31 00:00:00.000000000 Z
12
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: colsole
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: 0.8.1
20
+ - - "<"
21
+ - !ruby/object:Gem::Version
22
+ version: '2'
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ version: 0.8.1
30
+ - - "<"
31
+ - !ruby/object:Gem::Version
32
+ version: '2'
13
33
  - !ruby/object:Gem::Dependency
14
34
  name: mister_bin
15
35
  requirement: !ruby/object:Gem::Requirement
@@ -25,47 +45,53 @@ dependencies:
25
45
  - !ruby/object:Gem::Version
26
46
  version: '0.7'
27
47
  - !ruby/object:Gem::Dependency
28
- name: colsole
48
+ name: puma
29
49
  requirement: !ruby/object:Gem::Requirement
30
50
  requirements:
31
- - - "~>"
51
+ - - ">="
32
52
  - !ruby/object:Gem::Version
33
- version: '0.7'
53
+ version: '5.6'
54
+ - - "<"
55
+ - !ruby/object:Gem::Version
56
+ version: '7.0'
34
57
  type: :runtime
35
58
  prerelease: false
36
59
  version_requirements: !ruby/object:Gem::Requirement
37
60
  requirements:
38
- - - "~>"
61
+ - - ">="
39
62
  - !ruby/object:Gem::Version
40
- version: '0.7'
63
+ version: '5.6'
64
+ - - "<"
65
+ - !ruby/object:Gem::Version
66
+ version: '7.0'
41
67
  - !ruby/object:Gem::Dependency
42
- name: rack
68
+ name: rack-contrib
43
69
  requirement: !ruby/object:Gem::Requirement
44
70
  requirements:
45
71
  - - "~>"
46
72
  - !ruby/object:Gem::Version
47
- version: '2.2'
73
+ version: '2.3'
48
74
  type: :runtime
49
75
  prerelease: false
50
76
  version_requirements: !ruby/object:Gem::Requirement
51
77
  requirements:
52
78
  - - "~>"
53
79
  - !ruby/object:Gem::Version
54
- version: '2.2'
80
+ version: '2.3'
55
81
  - !ruby/object:Gem::Dependency
56
- name: puma
82
+ name: sinatra
57
83
  requirement: !ruby/object:Gem::Requirement
58
84
  requirements:
59
85
  - - "~>"
60
86
  - !ruby/object:Gem::Version
61
- version: '5.1'
87
+ version: '3.0'
62
88
  type: :runtime
63
89
  prerelease: false
64
90
  version_requirements: !ruby/object:Gem::Requirement
65
91
  requirements:
66
92
  - - "~>"
67
93
  - !ruby/object:Gem::Version
68
- version: '5.1'
94
+ version: '3.0'
69
95
  description: Command line utility for running a web server for static files with basic
70
96
  authentication support
71
97
  email: db@dannyben.com
@@ -79,13 +105,13 @@ files:
79
105
  - lib/httpme.rb
80
106
  - lib/httpme/cli.rb
81
107
  - lib/httpme/command.rb
82
- - lib/httpme/index_redirector.rb
83
108
  - lib/httpme/server.rb
84
109
  - lib/httpme/version.rb
85
110
  homepage: https://github.com/dannyben/httpme
86
111
  licenses:
87
112
  - MIT
88
- metadata: {}
113
+ metadata:
114
+ rubygems_mfa_required: 'true'
89
115
  post_install_message:
90
116
  rdoc_options: []
91
117
  require_paths:
@@ -94,14 +120,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
94
120
  requirements:
95
121
  - - ">="
96
122
  - !ruby/object:Gem::Version
97
- version: 2.6.0
123
+ version: 2.7.0
98
124
  required_rubygems_version: !ruby/object:Gem::Requirement
99
125
  requirements:
100
126
  - - ">="
101
127
  - !ruby/object:Gem::Version
102
128
  version: '0'
103
129
  requirements: []
104
- rubygems_version: 3.3.3
130
+ rubygems_version: 3.4.5
105
131
  signing_key:
106
132
  specification_version: 4
107
133
  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