simpleserver 0.0.2 → 0.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c52b916480aad8c3f8507356ee7f2b370b89b037
4
- data.tar.gz: 55df08d6df1f3b1516cda4723a2ec661591c6f8f
3
+ metadata.gz: fe4f0e502d1837a44eeafccdb044a73478d68f0f
4
+ data.tar.gz: 0898865771aa7a23b20c2820839c7f118fac9a41
5
5
  SHA512:
6
- metadata.gz: f5416b78fc4c8d66116ead945450cd9dd22e12d7b9b4a6d5293418d1e594332a2afd1594a04391c0d7aefe1d03d019383218be38f90718b77b1b02c4b90e1ca0
7
- data.tar.gz: 3f0476b1b4f59504916d5a13358ebece3909195343382596defa67e699d31de054b6f5c991c307e3966d1723576e5d61ba4a0d380bd08d017ec47b5559166be0
6
+ metadata.gz: baaf884abea8760ef7dcff050f62eb9b10c5e6cb3546ed55a2d23c1100bd519c0bda398ba2fcb847dc0f7640a6cdb6d02518829775674052d0c6f676183f39fa
7
+ data.tar.gz: 1d8029bb799daa98f7e343fe430f3cecc3f04e5f36f09b6f68f4e718a21aa40dc825a555dd2a7ccc62a8b494839f3d59614533d82a8442c6ba5c787be3fed649
data/bin/simpleserver CHANGED
@@ -1,28 +1,4 @@
1
1
  #!/usr/bin/env ruby
2
- require 'socket'
2
+ require "simpleserver"
3
3
 
4
- server = TCPServer.new 1337
5
-
6
- loop do
7
- client = server.accept
8
- request = client.gets
9
- verb, path, protocol = request.split(" ")
10
- path = "." + path
11
-
12
- if File.file?(path)
13
- body = File.open(path, "r"){|file| file.read}
14
- status = "200 OK"
15
- else
16
- body = "File not found\n"
17
- status = "404 Not Found"
18
- end
19
-
20
- response = "#{protocol} #{status}\n"
21
- response += "Content-Type: text/html\n"
22
- response += "Content-Length: #{body.length}\n"
23
- response += "Connection: close\n\n"
24
- response += body
25
-
26
- client.puts response
27
- client.close
28
- end
4
+ Simpleserver.run
@@ -1,3 +1,3 @@
1
1
  module Simpleserver
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.4"
3
3
  end
data/lib/simpleserver.rb CHANGED
@@ -1,5 +1,36 @@
1
1
  require "simpleserver/version"
2
+ require 'socket'
2
3
 
3
4
  module Simpleserver
4
- # Your code goes here...
5
+
6
+ def self.run
7
+ server = TCPServer.new 1337
8
+
9
+ loop do
10
+ client = server.accept
11
+ request = client.gets
12
+ verb, path, protocol = request.split(" ")
13
+ path = path.split('?')[0]
14
+ path = "." + path
15
+
16
+ if File.file?(path)
17
+ body = File.open(path, "r"){|file| file.read}
18
+ @status = "200 OK"
19
+ else
20
+ body = "File not found\n"
21
+ @status = "404 Not Found"
22
+ end
23
+
24
+ client.puts buildResponse(protocol, body)
25
+ client.close
26
+ end
27
+ end
28
+
29
+ def buildResponse(protocol, body)
30
+ response = "#{protocol} #{@status}\n"
31
+ response += "Content-Type: text/html\n"
32
+ response += "Content-Length: #{body.length}\n"
33
+ response += "Connection: close\n\n"
34
+ response += body
35
+ end
5
36
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: simpleserver
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alex Lien
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-06-03 00:00:00.000000000 Z
11
+ date: 2014-06-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler