serv 0.1
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.
- data/LICENSE +27 -0
- data/README +1 -0
- data/lib/rack/handler/serv.rb +59 -0
- data/lib/serv.rb +5 -0
- data/serv.gemspec +11 -0
- metadata +83 -0
data/LICENSE
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
copyright (c) 2010 Konstantin Haase. All rights reserved.
|
2
|
+
|
3
|
+
Developed by: Konstantin Haase
|
4
|
+
http://github.com/rkh/serv
|
5
|
+
|
6
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
7
|
+
of this software and associated documentation files (the "Software"), to
|
8
|
+
deal with the Software without restriction, including without limitation the
|
9
|
+
rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
10
|
+
sell copies of the Software, and to permit persons to whom the Software is
|
11
|
+
furnished to do so, subject to the following conditions:
|
12
|
+
1. Redistributions of source code must retain the above copyright notice,
|
13
|
+
this list of conditions and the following disclaimers.
|
14
|
+
2. Redistributions in binary form must reproduce the above copyright
|
15
|
+
notice, this list of conditions and the following disclaimers in the
|
16
|
+
documentation and/or other materials provided with the distribution.
|
17
|
+
3. Neither the name of Konstantin Haase, nor the names of other contributors
|
18
|
+
may be used to endorse or promote products derived from this Software without
|
19
|
+
specific prior written permission.
|
20
|
+
|
21
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
22
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
23
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
24
|
+
CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
25
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
26
|
+
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
27
|
+
WITH THE SOFTWARE.
|
data/README
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
rackup -s Serv
|
@@ -0,0 +1,59 @@
|
|
1
|
+
require 'ruby_http_parser'
|
2
|
+
require 'stringio'
|
3
|
+
require 'socket'
|
4
|
+
require 'rack/utils'
|
5
|
+
|
6
|
+
module Rack
|
7
|
+
module Handler
|
8
|
+
class Serv
|
9
|
+
VERSION = "0.1"
|
10
|
+
def self.run(app, options = {})
|
11
|
+
Thread.abort_on_exception = true
|
12
|
+
@@host, @@port = options[:Host] || '0.0.0.0', options[:Port] || 8080
|
13
|
+
s = TCPServer.new(@@host, @@port)
|
14
|
+
puts "listening #{options.inspect}"
|
15
|
+
loop { Thread.new(s.accept) { |io| new app, io }}
|
16
|
+
end
|
17
|
+
|
18
|
+
def initialize(app, socket)
|
19
|
+
puts "incoming"
|
20
|
+
@app, @socket, @done = app, socket, false
|
21
|
+
parser = Net::HTTP::RequestParser.new
|
22
|
+
@body = ""
|
23
|
+
parser.on_body = proc { |b| @body << b }
|
24
|
+
parser.on_message_complete = self
|
25
|
+
parser << (first_line = @socket.gets)
|
26
|
+
@verb, @path, @http = first_line.split(' ')
|
27
|
+
parser << @socket.gets until @done
|
28
|
+
rescue Net::HTTP::ParseError
|
29
|
+
@socket.close
|
30
|
+
end
|
31
|
+
|
32
|
+
def call(env)
|
33
|
+
@done = true
|
34
|
+
env.merge! \
|
35
|
+
"REQUEST_METHOD" => @verb,
|
36
|
+
"rack.input" => StringIO.new(@body),
|
37
|
+
"rack.version" => Rack::VERSION,
|
38
|
+
"rack.errors" => $stderr,
|
39
|
+
"rack.multithread" => true,
|
40
|
+
"rack.multiprocess" => false,
|
41
|
+
"rack.run_once" => false,
|
42
|
+
"rack.url_scheme" => %w[yes on 1].include?(ENV["HTTPS"]) ? "https" : "http"
|
43
|
+
env["SERVER_NAME"] ||= env["HTTP_HOST"] || @@host
|
44
|
+
env["SERVER_PORT"] ||= @@port.to_s
|
45
|
+
env["QUERY_STRING"] ||= ""
|
46
|
+
status, headers, body = @app.call(env)
|
47
|
+
@socket.puts "#{@http} #{status} #{Rack::Utils::HTTP_STATUS_CODES[status]}"
|
48
|
+
@socket.puts headers.map { |k,v| "#{k}: #{v}" }
|
49
|
+
@socket.puts ''
|
50
|
+
body.each do |line|
|
51
|
+
@socket.print line
|
52
|
+
@socket.flush
|
53
|
+
end
|
54
|
+
body.close if body.respond_to? :close
|
55
|
+
@socket.close
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
data/lib/serv.rb
ADDED
data/serv.gemspec
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
Gem::Specification.new do |s|
|
2
|
+
s.name = 'serv'
|
3
|
+
s.version = '0.1'
|
4
|
+
s.date = '2010-10-20'
|
5
|
+
s.description = 'simple, threaded rack handler (webserver)'
|
6
|
+
s.summary = s.description
|
7
|
+
s.authors = ['Konstantin Haase']
|
8
|
+
s.email = 'k.haase@finn.de'
|
9
|
+
s.files = `git ls-files`.split("\n")
|
10
|
+
s.add_dependency 'ruby_http_parser'
|
11
|
+
end
|
metadata
ADDED
@@ -0,0 +1,83 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: serv
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 9
|
5
|
+
prerelease: false
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 1
|
9
|
+
version: "0.1"
|
10
|
+
platform: ruby
|
11
|
+
authors:
|
12
|
+
- Konstantin Haase
|
13
|
+
autorequire:
|
14
|
+
bindir: bin
|
15
|
+
cert_chain: []
|
16
|
+
|
17
|
+
date: 2010-10-20 00:00:00 +02:00
|
18
|
+
default_executable:
|
19
|
+
dependencies:
|
20
|
+
- !ruby/object:Gem::Dependency
|
21
|
+
name: ruby_http_parser
|
22
|
+
prerelease: false
|
23
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
24
|
+
none: false
|
25
|
+
requirements:
|
26
|
+
- - ">="
|
27
|
+
- !ruby/object:Gem::Version
|
28
|
+
hash: 3
|
29
|
+
segments:
|
30
|
+
- 0
|
31
|
+
version: "0"
|
32
|
+
type: :runtime
|
33
|
+
version_requirements: *id001
|
34
|
+
description: simple, threaded rack handler (webserver)
|
35
|
+
email: k.haase@finn.de
|
36
|
+
executables: []
|
37
|
+
|
38
|
+
extensions: []
|
39
|
+
|
40
|
+
extra_rdoc_files: []
|
41
|
+
|
42
|
+
files:
|
43
|
+
- LICENSE
|
44
|
+
- README
|
45
|
+
- lib/rack/handler/serv.rb
|
46
|
+
- lib/serv.rb
|
47
|
+
- serv.gemspec
|
48
|
+
has_rdoc: true
|
49
|
+
homepage:
|
50
|
+
licenses: []
|
51
|
+
|
52
|
+
post_install_message:
|
53
|
+
rdoc_options: []
|
54
|
+
|
55
|
+
require_paths:
|
56
|
+
- lib
|
57
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
58
|
+
none: false
|
59
|
+
requirements:
|
60
|
+
- - ">="
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
hash: 3
|
63
|
+
segments:
|
64
|
+
- 0
|
65
|
+
version: "0"
|
66
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
67
|
+
none: false
|
68
|
+
requirements:
|
69
|
+
- - ">="
|
70
|
+
- !ruby/object:Gem::Version
|
71
|
+
hash: 3
|
72
|
+
segments:
|
73
|
+
- 0
|
74
|
+
version: "0"
|
75
|
+
requirements: []
|
76
|
+
|
77
|
+
rubyforge_project:
|
78
|
+
rubygems_version: 1.3.7
|
79
|
+
signing_key:
|
80
|
+
specification_version: 3
|
81
|
+
summary: simple, threaded rack handler (webserver)
|
82
|
+
test_files: []
|
83
|
+
|