ws 0.3.0 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. data/README.md +2 -3
  2. data/bin/ws +1 -1
  3. data/lib/ws.rb +18 -16
  4. metadata +1 -1
data/README.md CHANGED
@@ -1,9 +1,8 @@
1
- ws(3) -- Simple Local Web Server
2
- =============================
1
+ # ws(3) -- Simple Local Web Server
3
2
 
4
3
  ## SYNOPSIS
5
4
  :::text
6
- ws [-v | --verbose] [-d | --directory DIRECTORY] [-p | --port PORT] [-h | --help]
5
+ ws [-v | --verbose] [-d | --directory DIRECTORY] [-p | --port PORT] [-i | --index INDEXFILE] [-h | --help]
7
6
 
8
7
  ## INSTALLTION
9
8
 
data/bin/ws CHANGED
@@ -49,7 +49,7 @@ require dest_path
49
49
 
50
50
  # Trap Interrupts
51
51
  trap("INT") do
52
- puts "Shutting down..."
52
+ puts "\nShutting down..."
53
53
  exit
54
54
  end
55
55
 
data/lib/ws.rb CHANGED
@@ -3,23 +3,25 @@ require "socket"
3
3
  module WS
4
4
  def self.start_server(options)
5
5
  server = TCPServer.new("127.0.0.1", options[:port])
6
- while (conn = server.accept)
7
- file = conn.gets.scan(/(?<=\/).*(?=\sHTTP)/)[0].split("/")
8
- file_path = File.join(options[:directory], file)
9
- file_path = File.join(file_path, options[:index]) if File.directory? file_path
10
- mime_type = get_mime_type file_path
11
- begin
12
- file_handle = File.open(file_path, "r")
13
- puts "#{Time.now.inspect}: Sending #{file_path} to client." if options[:verbose]
14
- conn.print get_header("200/OK", mime_type)
15
- conn.print file_handle.read()
16
- file_handle.close
17
- rescue Errno::ENOENT
18
- puts "#{Time.now.inspect}: Not Found: #{file_path}" if options[:verbose]
19
- conn.print get_header("404/NOT FOUND", "text/html")
20
- conn.print "404: File not found."
6
+ loop do
7
+ Thread.start(server.accept) do |conn|
8
+ file = conn.gets.scan(/(?<=\/).*(?=\sHTTP)/)[0].split("/")
9
+ file_path = File.join(options[:directory], file)
10
+ file_path = File.join(file_path, options[:index]) if File.directory? file_path
11
+ mime_type = get_mime_type file_path
12
+ begin
13
+ file_handle = File.open(file_path, "r")
14
+ puts "#{Time.now.inspect}: Sending #{file_path} to client." if options[:verbose]
15
+ conn.print get_header("200/OK", mime_type)
16
+ conn.print file_handle.read()
17
+ file_handle.close
18
+ rescue Errno::ENOENT
19
+ puts "#{Time.now.inspect}: Not Found: #{file_path}" if options[:verbose]
20
+ conn.print get_header("404/NOT FOUND", "text/html")
21
+ conn.print "404: File not found."
22
+ end
23
+ conn.close
21
24
  end
22
- conn.close
23
25
  end
24
26
  end
25
27
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ws
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.4.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: