httpme 0.1.5 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bin/httpme +1 -1
- data/lib/httpme/command.rb +18 -17
- data/lib/httpme/server.rb +16 -36
- data/lib/httpme/version.rb +2 -2
- data/lib/httpme.rb +5 -1
- metadata +28 -14
- data/lib/httpme/index_redirector.rb +0 -19
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 99af7b72919ce9067c213da74800f672b83bc32c4ed9aaa138b3b054c5e27d87
|
4
|
+
data.tar.gz: 9aab9343681890a51d0a3fa903fa52724866fc6c8829119047b4af62900b204f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a6d80f36f71b0dbc774b15f4d066b3dc55a31ae38e9c10d91796ade658927731cc61f64a1eda16a4fdbc17065b6dc898a1bd1c827ae8af4157d53346500e36c1
|
7
|
+
data.tar.gz: 8b5891bf859b15221a9507c8642d1c065a18f5572c6b5f097f260e60c0fb6cd5c562464d88028906f76e5074d02e769f2f6ca96bc5d368118a0fd83deadd7803
|
data/bin/httpme
CHANGED
data/lib/httpme/command.rb
CHANGED
@@ -1,31 +1,32 @@
|
|
1
1
|
require 'mister_bin'
|
2
2
|
require 'colsole'
|
3
|
+
require 'httpme/version'
|
3
4
|
|
4
5
|
module HTTPMe
|
5
6
|
class Command < MisterBin::Command
|
6
7
|
include Colsole
|
7
8
|
|
8
9
|
version HTTPMe::VERSION
|
9
|
-
summary
|
10
|
+
summary 'httpme - static web server with basic authentication'
|
10
11
|
|
11
|
-
help
|
12
|
+
help 'Options can be set using command line arguments or environment variables'
|
12
13
|
|
13
|
-
usage
|
14
|
-
usage
|
14
|
+
usage 'httpme [PATH] [--port PORT --host HOST --auth AUTH]'
|
15
|
+
usage 'httpme (-h|--help|--version)'
|
15
16
|
|
16
|
-
param
|
17
|
-
option
|
18
|
-
option
|
19
|
-
option
|
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'
|
20
21
|
|
21
|
-
environment 'HTTPME_PATH',
|
22
|
-
environment 'HTTPME_AUTH',
|
23
|
-
environment 'HTTPME_PORT',
|
24
|
-
environment 'HTTPME_HOST',
|
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'
|
25
26
|
|
26
|
-
example
|
27
|
-
example
|
28
|
-
example
|
27
|
+
example 'httpme -p 4000'
|
28
|
+
example 'httpme docs --auth admin:s3cr3t'
|
29
|
+
example 'HTTPME_AUTH=admin:s3cr3t httpme docs # same result as above'
|
29
30
|
|
30
31
|
def run
|
31
32
|
path = args['PATH'] || ENV['HTTPME_PATH'] || '.'
|
@@ -35,8 +36,8 @@ module HTTPMe
|
|
35
36
|
|
36
37
|
raise ArgumentError, "Path not found [#{path}]" unless Dir.exist? path
|
37
38
|
|
38
|
-
|
39
|
-
|
39
|
+
Server.setup path: path, host: host, port: port, auth: auth
|
40
|
+
Server.run!
|
40
41
|
end
|
41
42
|
end
|
42
43
|
end
|
data/lib/httpme/server.rb
CHANGED
@@ -1,51 +1,31 @@
|
|
1
|
-
require 'rack'
|
2
|
-
require '
|
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
|
-
|
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
|
-
|
10
|
-
|
11
|
-
|
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
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
end
|
20
|
+
not_found do
|
21
|
+
content_type :text
|
22
|
+
'404 Not Found'
|
23
|
+
end
|
40
24
|
|
41
|
-
|
25
|
+
use Rack::TryStatic, root: path, urls: %w[/], try: %w[.html index.html /index.html]
|
42
26
|
|
43
|
-
|
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
|
data/lib/httpme/version.rb
CHANGED
@@ -1,3 +1,3 @@
|
|
1
1
|
module HTTPMe
|
2
|
-
VERSION =
|
3
|
-
end
|
2
|
+
VERSION = '0.2.0'
|
3
|
+
end
|
data/lib/httpme.rb
CHANGED
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.
|
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-
|
11
|
+
date: 2022-11-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
|
-
name:
|
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:
|
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:
|
42
|
+
name: puma
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
45
|
- - "~>"
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: '
|
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: '
|
54
|
+
version: '6.0'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
|
-
name:
|
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: '
|
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: '
|
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.
|
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.
|
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
|