retroserver 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +0 -2
- data/README.md +9 -3
- data/lib/retroserver.rb +0 -25
- data/lib/retroserver/version.rb +1 -1
- data/retroserver.gemspec +3 -3
- metadata +5 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4c2c93d66f5d2e21ee5c0c85c64562750594bc54
|
4
|
+
data.tar.gz: 3e2dadeb180b2216f59a257f79c57ecdbc20583b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: dc414e86fbb9550cc75d15c1e5cd2ad4eff2edbef657b9f2e2edc9cedc8eb49fd715ed12e0cc5ad7132431cb43979fe5bba5e39b6871c329e01120696bb715ba
|
7
|
+
data.tar.gz: e95095af7ab7c31b08237ae0448c8d979acc698d22f0322efd81d6d034b359c7d9c4d7594608ff7a578e45ddc450dc3f16d4e2186ab19cd33e40afa64ce2f104
|
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# Retroserver
|
2
2
|
|
3
|
-
|
3
|
+
Lightweight Ruby Web Server
|
4
4
|
|
5
5
|
## Installation
|
6
6
|
|
@@ -18,12 +18,18 @@ Or install it yourself as:
|
|
18
18
|
|
19
19
|
## Usage
|
20
20
|
|
21
|
-
|
21
|
+
Add this line to your application's primary .rb file
|
22
|
+
|
23
|
+
require 'retroserver'
|
22
24
|
|
23
25
|
## Contributing
|
24
26
|
|
25
|
-
1. Fork it ( http://github.com
|
27
|
+
1. Fork it ( http://github.com/johncjensen/retroserver/fork )
|
26
28
|
2. Create your feature branch (`git checkout -b my-new-feature`)
|
27
29
|
3. Commit your changes (`git commit -am 'Add some feature'`)
|
28
30
|
4. Push to the branch (`git push origin my-new-feature`)
|
29
31
|
5. Create new Pull Request
|
32
|
+
|
33
|
+
## Source
|
34
|
+
|
35
|
+
[practicingruby.com](https://practicingruby.com/articles/implementing-an-http-file-server?u=2c59db4496)
|
data/lib/retroserver.rb
CHANGED
@@ -2,10 +2,8 @@ require "retroserver/version"
|
|
2
2
|
require "socket"
|
3
3
|
require "uri"
|
4
4
|
|
5
|
-
# Files will be served from this directory
|
6
5
|
WEB_ROOT = './public'
|
7
6
|
|
8
|
-
# Map extensions to their content type
|
9
7
|
CONTENT_TYPE_MAPPING = {
|
10
8
|
'html' => 'text/html',
|
11
9
|
'txt' => 'text/plain',
|
@@ -13,47 +11,29 @@ CONTENT_TYPE_MAPPING = {
|
|
13
11
|
'jpg' => 'image/jpeg'
|
14
12
|
}
|
15
13
|
|
16
|
-
# Treat as binary data if content type cannot be found
|
17
14
|
DEFAULT_CONTENT_TYPE = 'application/octet-stream'
|
18
15
|
|
19
|
-
# This helper function parses the extension of the
|
20
|
-
# requested file and then looks up its content type.
|
21
|
-
|
22
16
|
def content_type(path)
|
23
17
|
ext = File.extname(path).split(".").last
|
24
18
|
CONTENT_TYPE_MAPPING.fetch(ext, DEFAULT_CONTENT_TYPE)
|
25
19
|
end
|
26
20
|
|
27
|
-
# This helper function parses the Request-Line and
|
28
|
-
# generates a path to a file on the server.
|
29
|
-
|
30
21
|
def requested_file(request_line)
|
31
22
|
request_uri = request_line.split(" ")[1]
|
32
23
|
path = URI.unescape(URI(request_uri).path)
|
33
24
|
|
34
25
|
clean = []
|
35
26
|
|
36
|
-
# Split the path into components
|
37
27
|
parts = path.split("/")
|
38
28
|
|
39
29
|
parts.each do |part|
|
40
|
-
# skip any empty or current directory (".") path components
|
41
30
|
next if part.empty? || part == '.'
|
42
|
-
# If the path component goes up one directory level (".."),
|
43
|
-
# remove the last clean component.
|
44
|
-
# Otherwise, add the component to the Array of clean components
|
45
31
|
part == '..' ? clean.pop : clean << part
|
46
32
|
end
|
47
33
|
|
48
|
-
# return the web root joined to the clean path
|
49
34
|
File.join(WEB_ROOT, *clean)
|
50
35
|
end
|
51
36
|
|
52
|
-
# Except where noted below, the general approach of
|
53
|
-
# handling requests and generating responses is
|
54
|
-
# similar to that of the "Hello World" example
|
55
|
-
# shown earlier.
|
56
|
-
|
57
37
|
server = TCPServer.new('localhost', 1998)
|
58
38
|
|
59
39
|
loop do
|
@@ -66,8 +46,6 @@ loop do
|
|
66
46
|
|
67
47
|
path = File.join(path, 'index.html') if File.directory?(path)
|
68
48
|
|
69
|
-
# Make sure the file exists and is not a directory
|
70
|
-
# before attempting to open it.
|
71
49
|
if File.exist?(path) && !File.directory?(path)
|
72
50
|
File.open(path, "rb") do |file|
|
73
51
|
socket.print "HTTP/1.1 200 OK\r\n" +
|
@@ -77,13 +55,11 @@ loop do
|
|
77
55
|
|
78
56
|
socket.print "\r\n"
|
79
57
|
|
80
|
-
# write the contents of the file to the socket
|
81
58
|
IO.copy_stream(file, socket)
|
82
59
|
end
|
83
60
|
else
|
84
61
|
message = "File not found\n"
|
85
62
|
|
86
|
-
# respond with a 404 error code to indicate the file does not exist
|
87
63
|
socket.print "HTTP/1.1 404 Not Found\r\n" +
|
88
64
|
"Content-Type: text/plain\r\n" +
|
89
65
|
"Content-Length: #{message.size}\r\n" +
|
@@ -96,4 +72,3 @@ loop do
|
|
96
72
|
|
97
73
|
socket.close
|
98
74
|
end
|
99
|
-
|
data/lib/retroserver/version.rb
CHANGED
data/retroserver.gemspec
CHANGED
@@ -8,9 +8,9 @@ Gem::Specification.new do |spec|
|
|
8
8
|
spec.version = Retroserver::VERSION
|
9
9
|
spec.authors = ["John Jensen"]
|
10
10
|
spec.email = ["johncjensen@hotmail.com"]
|
11
|
-
spec.summary = %q{Lightweight
|
12
|
-
spec.description = %q{Lightweight
|
13
|
-
spec.homepage = ""
|
11
|
+
spec.summary = %q{Lightweight Ruby Web Server}
|
12
|
+
spec.description = %q{Experimental -- Lightweight Ruby Web Server}
|
13
|
+
spec.homepage = "https://rubygems.org/gems/retroserver"
|
14
14
|
spec.license = "MIT"
|
15
15
|
|
16
16
|
spec.files = `git ls-files -z`.split("\x0")
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: retroserver
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- John Jensen
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-02-
|
11
|
+
date: 2014-02-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -38,7 +38,7 @@ dependencies:
|
|
38
38
|
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '0'
|
41
|
-
description: Lightweight
|
41
|
+
description: Experimental -- Lightweight Ruby Web Server
|
42
42
|
email:
|
43
43
|
- johncjensen@hotmail.com
|
44
44
|
executables: []
|
@@ -53,7 +53,7 @@ files:
|
|
53
53
|
- lib/retroserver.rb
|
54
54
|
- lib/retroserver/version.rb
|
55
55
|
- retroserver.gemspec
|
56
|
-
homepage:
|
56
|
+
homepage: https://rubygems.org/gems/retroserver
|
57
57
|
licenses:
|
58
58
|
- MIT
|
59
59
|
metadata: {}
|
@@ -76,5 +76,5 @@ rubyforge_project:
|
|
76
76
|
rubygems_version: 2.2.1
|
77
77
|
signing_key:
|
78
78
|
specification_version: 4
|
79
|
-
summary: Lightweight
|
79
|
+
summary: Lightweight Ruby Web Server
|
80
80
|
test_files: []
|