bossan 0.2.0 → 0.3.0

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,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- NTI5NjNkNTJkYmMwYmY0NDk5OGFkZDIyYzU1NzQxYWU1NGM3ODcxYw==
4
+ ZjFiOTYwNTUwMTUwNGFkYmJjOWQwYzdiMjA3NzVlOGI0NDhkNjMxNg==
5
5
  data.tar.gz: !binary |-
6
- NjBmZmUxYjczNTM0YzllYjRmMmI4MzM3Mzc0MjkyZmQ1MDU2MmI4Ng==
6
+ ODU1NGExMjUxYzVmOTQ2NDE3Y2U3ZDg1YzMwNzY0OTliYjE4ZjU1OA==
7
7
  !binary "U0hBNTEy":
8
8
  metadata.gz: !binary |-
9
- NjJjMzk1YTlhMjM4OTgxYjU4MWUwODY1ZmZhNWQzY2M3YzU4ZjA0N2U0ODIx
10
- MzUzODU0MDYxZmM2YTBhMzlkZjVjNGMyOTU0YjY2MGJiYzlmYTI1YWZlZTZh
11
- M2ZjNjBiZWMxZmRlZjE0YzNlNjNlNjE2ODhkZjMxMzM4MjE1MGE=
9
+ OTUxMWUwMGIxYmM0ZWUwODNjYzNlMTVlYjk5MmE2YTJjMmQ0YzMxMmQ1N2Uz
10
+ NjM5ZjA3MmE4NTAzM2JmNjNmZWQxYjY5MTdiYWMxZjUzYzE5NGNkODRhODlm
11
+ NzhlZjVkNDAwYjhkMDE2MTRiNzdiMzJmMWRkMGVhMjY1YzMwMDM=
12
12
  data.tar.gz: !binary |-
13
- NWQ4YTdkNmNjODVkZTgyZGQxNzdhMjk5NjViYzk1ZjliYjQwODY2OGI1MTI0
14
- MTgxMjlkNDA2MzRkNzJlNDY4MDNmMTViODJmM2ZmNDY4MTFiNjYyNzIyYzlk
15
- MThmNWY4Mjg4NGI5YzgyOWY1OGFhMDlhOGEzYTE2OTRkNzA1ZGE=
13
+ ZjNhZjE4ZDgxZmNmOWQ5M2UyMWVjOTI3OGZiNWU1ZmUyYzg1ZGMxMzQ4OWRk
14
+ ODg4OGE1YWQ1YzU0YmE3Y2FhOTkxZWNhY2YxYzcxYTAzYjFiNTA1NTMwNDYw
15
+ MTU5YTk5MWQ3Y2ZiNzUwOGFlMzRjM2I5NzgyY2FlYjBjMmVmZDg=
@@ -2,7 +2,7 @@
2
2
 
3
3
  ### v0.2.0
4
4
 
5
- (New Feature release. rerelease 2013-05-22)
5
+ (New Feature release. release 2013-05-22)
6
6
 
7
7
  * support keep-alive (use Bossan.set_keepalive)
8
8
 
@@ -10,4 +10,4 @@
10
10
 
11
11
  * add set_backlog (default:1024)
12
12
 
13
- * add set_picoev_max_fd (default:1024)
13
+ * add set_picoev_max_fd (default:4096)
data/TODO CHANGED
@@ -1,5 +1,3 @@
1
- * add picoev_max_fd setter, getter
2
-
3
1
  * set rack.input File-type object, if over 512K
4
2
  - avoid too much use memory
5
3
 
@@ -3,6 +3,7 @@ require 'active_record'
3
3
  require 'erb'
4
4
 
5
5
  enable :sessions
6
+ set :views, File.dirname(__FILE__) + '/views'
6
7
 
7
8
  DATABASE = './db/sinatr.db'
8
9
  SECRET_KEY = 'development_key'
@@ -0,0 +1,18 @@
1
+ require_relative '../lib/bossan'
2
+ require 'parallel'
3
+
4
+ app = ->(env){
5
+ body = ['hello, world!'] # Response body
6
+ [200, # Status code
7
+ { # Response headers
8
+ 'Content-Type' => 'text/html',
9
+ 'Content-Length' => body.join.size.to_s,
10
+ },
11
+ body]
12
+ }
13
+
14
+ Bossan.set_keepalive(10)
15
+ Bossan.listen('localhost', 8000)
16
+ workers = Parallel.each([0,1,2,3]) {|i|
17
+ Bossan.run(app)
18
+ }
@@ -1,13 +1,14 @@
1
1
  require_relative '../lib/bossan'
2
2
 
3
- Bossan.run('127.0.0.1', 8000, proc {|env|
4
- body = 'hello, world!'
5
- [
6
- 200, # Status code
7
- { # Response headers
8
- 'Content-Type' => 'text/html',
9
- 'Content-Length' => body.size.to_s,
10
- },
11
- [body] # Response body
12
- ]
13
- })
3
+ Bossan.listen('127.0.0.1', 8000)
4
+ Bossn.run(proc {|env|
5
+ body = 'hello, world!'
6
+ [
7
+ 200, # Status code
8
+ { # Response headers
9
+ 'Content-Type' => 'text/html',
10
+ 'Content-Length' => body.size.to_s,
11
+ },
12
+ [body] # Response body
13
+ ]
14
+ })
@@ -7,5 +7,6 @@ class App < Sinatra::Base
7
7
  end
8
8
  end
9
9
 
10
- Bossan.run('127.0.0.1', 8000, App)
10
+ Bossan.listen('127.0.0.1', 8000)
11
+ Bossan.run(App)
11
12
 
@@ -0,0 +1,59 @@
1
+ require_relative '../lib/bossan'
2
+ require 'rack'
3
+ require 'tempfile'
4
+
5
+
6
+ def view_file req
7
+ # p req
8
+ # p req.env['rack.input']
9
+
10
+ tempfile = Tempfile.new('raw-upload.')
11
+ req.env['rack.input'].each do |chunk|
12
+ if chunk.respond_to?(:force_encoding)
13
+ tempfile << chunk.force_encoding('UTF-8')
14
+ else
15
+ tempfile << chunk
16
+ end
17
+ end
18
+
19
+ req.env['rack.input'].rewind
20
+
21
+ tempfile.flush
22
+ tempfile.rewind
23
+
24
+ # return Rack::File.new(tempfile)
25
+ return Rack::Multipart::UploadedFile.new(tempfile, req.content_type, true)
26
+ # return Rack::Response.new(req.env["rack.input"],
27
+ # 200,
28
+ # {"Content-Type" => req.content_type})
29
+ end
30
+
31
+
32
+ def upload_file req
33
+ return Rack::Response.new([<<-EOF
34
+ <h1>Upload File</h1>
35
+ <form action="" method="post" enctype="multipart/form-data">
36
+ <input type="file" name="uploaded_file"><input type="submit" value="Upload">
37
+ </form>
38
+ EOF
39
+ ],
40
+ 200,
41
+ ).to_a
42
+ end
43
+
44
+
45
+ app = ->(env) {
46
+ req = Rack::Request.new(env)
47
+ resp = if req.request_method == 'POST'
48
+ view_file req
49
+ else
50
+ upload_file req
51
+ end
52
+ # p resp
53
+ return resp
54
+ }
55
+
56
+
57
+ Bossan.set_max_content_length(1024 * 1024 * 1024)
58
+ Bossan.run('localhost', 8000)
59
+ Bossan.listen(app)
@@ -8,4 +8,5 @@ class App < Sinatra::Base
8
8
  end
9
9
  end
10
10
 
11
- Bossan.run('127.0.0.1', 8000, App)
11
+ Bossan.listen('127.0.0.1', 8000)
12
+ Bossan.run(App)
@@ -27,7 +27,7 @@
27
27
 
28
28
  #define MSG_413 ("HTTP/1.0 413 Request Entity Too Large\r\nContent-Type: text/html\r\nServer: " SERVER "\r\n\r\n<html><head><title>Request Entity Too Large</title></head><body><p>Request Entity Too Large.</p></body></html>")
29
29
 
30
- #define SERVER "bossan/0.2.0"
30
+ #define SERVER "bossan/0.3.0"
31
31
 
32
32
  VALUE server; // Bossan
33
33
 
@@ -1800,18 +1800,18 @@ bossan_access_log(VALUE self, VALUE args)
1800
1800
 
1801
1801
 
1802
1802
  static VALUE
1803
- bossan_run_loop(int argc, VALUE *argv, VALUE self)
1803
+ bossan_listen(int argc, VALUE *argv, VALUE self)
1804
1804
  {
1805
1805
  int ret;
1806
- VALUE args1, args2, args3;
1806
+ VALUE args1, args2;
1807
1807
 
1808
- rb_scan_args(argc, argv, "21", &args1, &args2, &args3);
1808
+ rb_scan_args(argc, argv, "11", &args1, &args2);
1809
1809
 
1810
1810
  if(listen_sock > 0){
1811
1811
  rb_raise(rb_eException, "already set listen socket");
1812
1812
  }
1813
1813
 
1814
- if (argc == 3){
1814
+ if (argc == 2){
1815
1815
  server_name = StringValuePtr(args1);
1816
1816
  server_port = NUM2INT(args2);
1817
1817
 
@@ -1825,11 +1825,9 @@ bossan_run_loop(int argc, VALUE *argv, VALUE self)
1825
1825
  server_port = (short)_port;
1826
1826
 
1827
1827
  ret = inet_listen();
1828
- rack_app = args3;
1829
1828
  } else {
1830
1829
  Check_Type(args1, T_STRING);
1831
1830
  ret = unix_listen(StringValuePtr(args1));
1832
- rack_app = args2;
1833
1831
  }
1834
1832
 
1835
1833
  if(ret < 0){
@@ -1840,6 +1838,14 @@ bossan_run_loop(int argc, VALUE *argv, VALUE self)
1840
1838
  if(listen_sock <= 0){
1841
1839
  rb_raise(rb_eTypeError, "not found listen socket");
1842
1840
  }
1841
+
1842
+ return Qnil;
1843
+ }
1844
+
1845
+ static VALUE
1846
+ bossan_run_loop(VALUE self, VALUE args)
1847
+ {
1848
+ rack_app = args;
1843
1849
 
1844
1850
  /* init picoev */
1845
1851
  picoev_init(max_fd);
@@ -2015,7 +2021,8 @@ Init_bossan_ext(void)
2015
2021
  server = rb_define_module("Bossan");
2016
2022
  rb_gc_register_address(&server);
2017
2023
 
2018
- rb_define_module_function(server, "run", bossan_run_loop, -1);
2024
+ rb_define_module_function(server, "listen", bossan_listen, -1);
2025
+ rb_define_module_function(server, "run", bossan_run_loop, 1);
2019
2026
  rb_define_module_function(server, "stop", bossan_stop, 0);
2020
2027
  rb_define_module_function(server, "shutdown", bossan_stop, 0);
2021
2028
 
@@ -1,7 +1,3 @@
1
1
  require_relative "bossan/version"
2
2
  require_relative "bossan/bossan_ext"
3
3
  require_relative "rack/handler/bossan"
4
-
5
- def run *args
6
- Bossan.run *args
7
- end
@@ -1,3 +1,3 @@
1
1
  module Bossan
2
- VERSION = "0.2.0"
2
+ VERSION = "0.3.0"
3
3
  end
@@ -15,7 +15,8 @@ module Rack
15
15
  options = DEFAULT_OPTIONS.merge(options)
16
16
  puts "* Listening on tcp://#{options[:Host]}:#{options[:Port]}"
17
17
 
18
- ::Bossan.run(options[:Host], options[:Port], app)
18
+ ::Bossan.listen(options[:Host], options[:Port])
19
+ ::Bossan.run(app)
19
20
  end
20
21
 
21
22
  def self.valid_options
@@ -0,0 +1,100 @@
1
+ require_relative '../lib/bossan'
2
+ require 'test/unit'
3
+ require 'socket'
4
+ require 'net/http'
5
+
6
+ class BadHttpMethodTest < Test::Unit::TestCase
7
+
8
+ ASSERT_RESPONSE = "Hello world!"
9
+ RESPONSE = ["Hello ", "world!"].freeze
10
+ DEFAULT_HOST = "localhost"
11
+ DEFAULT_PORT = 8000
12
+ DEFAULT_PATH = "/PATH?ket=value"
13
+ DEFAULT_VERSION = "HTTP/1.0"
14
+ DEFAULT_HEADER = {
15
+ "User-Agent"=> "Mozilla/5.0 (X11; U; Linux i686; ja; rv:1.9.2.7) Gecko/20100715 Ubuntu/10.04 (lucid) Firefox/3.6.7",
16
+ "Accept"=> "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8",
17
+ "Accept-Language"=> "ja,en-us;q=0.7,en;q=0.3",
18
+ "Accept-Encoding"=> "gzip,deflate",
19
+ "Accept-Charset"=> "Shift_JIS,utf-8;q=0.7,*;q=0.7",
20
+ "Keep-Alive"=> "115",
21
+ "Connection"=> "keep-alive",
22
+ "Cache-Control"=> "max-age=0",
23
+ }
24
+
25
+ ERR_400 = "HTTP/1.0 400 Bad Request"
26
+
27
+ class App
28
+ def call env
29
+ body = RESPONSE
30
+ [200,
31
+ {
32
+ 'Content-type'=> 'text/plain',
33
+ 'Content-length'=> RESPONSE.join.size.to_s
34
+ },
35
+ body
36
+ ]
37
+ end
38
+ end
39
+
40
+ def server_is_wake_up? n=100
41
+ n.times {
42
+ begin
43
+ Net::HTTP.start(DEFAULT_HOST, DEFAULT_PORT)
44
+ rescue
45
+ next
46
+ end
47
+ $stderr.puts "*** running success ***"
48
+ return true
49
+ }
50
+ return false
51
+ end
52
+
53
+ private :server_is_wake_up?
54
+
55
+ def send_data method
56
+ begin
57
+ sock = TCPSocket.new DEFAULT_HOST, DEFAULT_PORT
58
+ sock.send("#{method} #{DEFAULT_PATH} #{DEFAULT_VERSION}\r\n", 0)
59
+ sock.send("Host: #{DEFAULT_HOST}\r\n", 0)
60
+ DEFAULT_HEADER.each_pair {|k, v|
61
+ sock.send("#{k}: #{v}\r\n", 0)
62
+ }
63
+ sock.send("\r\n", 0)
64
+
65
+ data = sock.recv(1024 * 2)
66
+ return data
67
+ rescue
68
+ raise
69
+ end
70
+ end
71
+
72
+ def setup
73
+ $stderr.puts RUBY_DESCRIPTION
74
+
75
+ @pid = fork do
76
+ trap(:INT) { Bossan.stop }
77
+ Bossan.listen(DEFAULT_HOST, DEFAULT_PORT)
78
+ Bossan.run(App.new)
79
+ end
80
+ Process.detach @pid
81
+ unless server_is_wake_up?
82
+ $stderr.puts "bossan won't wake up until you love it ..."
83
+ exit 1
84
+ end
85
+ end
86
+
87
+ def test_bad_method1
88
+ response = send_data("")
89
+ assert_equal(response.split("\r\n").first, ERR_400)
90
+ end
91
+
92
+ def test_bad_method2
93
+ response = send_data("GET" * 100)
94
+ assert_equal(response.split("\r\n").first, ERR_400)
95
+ end
96
+
97
+ def teardown
98
+ Process.kill(:INT, @pid)
99
+ end
100
+ end
@@ -1,11 +1,11 @@
1
1
  # -*- coding: utf-8 -*-
2
- require 'bossan'
3
2
  require 'test/unit'
4
3
  require 'pp'
5
4
  require 'net/http'
5
+ require_relative '../lib/bossan'
6
6
 
7
7
 
8
- class RackEnvSimpleTest < Test::Unit::TestCase
8
+ class RackEnvSimpleGetTest < Test::Unit::TestCase
9
9
 
10
10
  RESPONSE = ["Hello ", "world!"].freeze
11
11
  DEFAULT_HOST = "localhost"
@@ -16,8 +16,8 @@ class RackEnvSimpleTest < Test::Unit::TestCase
16
16
  pid = fork do
17
17
  r.close
18
18
  trap(:INT) { Bossan.stop }
19
- Bossan.run(DEFAULT_HOST, DEFAULT_PORT,
20
- proc {|env|
19
+ Bossan.listen(DEFAULT_HOST, DEFAULT_PORT)
20
+ Bossan.run(proc {|env|
21
21
  @env = env.dup
22
22
  # I have no idea how to check this two values..
23
23
  @env.delete "rack.input"
@@ -53,6 +53,9 @@ class RackEnvSimpleTest < Test::Unit::TestCase
53
53
  assert_equal(env["SCRIPT_NAME"], "")
54
54
  assert_equal(env["QUERY_STRING"], "")
55
55
  assert_equal(env["REQUEST_METHOD"], "GET")
56
+ assert_equal(env["SERVER_NAME"], "localhost")
57
+ assert_equal(env["SERVER_PORT"], "8000")
58
+ assert_not_equal(env["HTTP_USER_AGENT"], "")
56
59
  ensure
57
60
  Process.kill(:INT, pid)
58
61
  end
@@ -1,11 +1,11 @@
1
1
  # -*- coding: utf-8 -*-
2
2
  require 'test/unit'
3
3
  require 'pp'
4
- require 'bossan'
5
4
  require 'net/http'
5
+ require_relative '../lib/bossan'
6
6
 
7
7
 
8
- class RackEnvQueryTest < Test::Unit::TestCase
8
+ class RackEnvSimpleQueryTest < Test::Unit::TestCase
9
9
 
10
10
  RESPONSE = ["Hello ", "world!"].freeze
11
11
  DEFAULT_HOST = "localhost"
@@ -16,8 +16,8 @@ class RackEnvQueryTest < Test::Unit::TestCase
16
16
  pid = fork do
17
17
  r.close
18
18
  trap(:INT) { Bossan.stop }
19
- Bossan.run(DEFAULT_HOST, DEFAULT_PORT,
20
- proc {|env|
19
+ Bossan.listen(DEFAULT_HOST, DEFAULT_PORT)
20
+ Bossan.run(proc {|env|
21
21
  @env = env.dup
22
22
  # I have no idea how to check this two values..
23
23
  @env.delete "rack.input"
@@ -0,0 +1,76 @@
1
+ require_relative '../lib/bossan'
2
+ require 'test/unit'
3
+ require 'net/http'
4
+
5
+ class LongUrlTest < Test::Unit::TestCase
6
+
7
+ ASSERT_RESPONSE = "Hello world!"
8
+ RESPONSE = ["Hello ", "world!"].freeze
9
+ DEFAULT_HOST = "localhost"
10
+ DEFAULT_PORT = 8000
11
+
12
+ class App
13
+ def call env
14
+ body = RESPONSE
15
+ [200,
16
+ {
17
+ 'Content-type'=> 'text/plain',
18
+ 'Content-length'=> RESPONSE.join.size.to_s
19
+ },
20
+ body
21
+ ]
22
+ end
23
+ end
24
+
25
+ def server_is_wake_up? n=100
26
+ n.times {
27
+ begin
28
+ Net::HTTP.start(DEFAULT_HOST, DEFAULT_PORT)
29
+ rescue
30
+ next
31
+ end
32
+ $stderr.puts "*** running success ***"
33
+ return true
34
+ }
35
+ return false
36
+ end
37
+
38
+ private :server_is_wake_up?
39
+
40
+ def setup
41
+ $stderr.puts RUBY_DESCRIPTION
42
+
43
+ @pid = fork do
44
+ trap(:INT) { Bossan.stop }
45
+ Bossan.listen(DEFAULT_HOST, DEFAULT_PORT)
46
+ Bossan.run(App.new)
47
+ end
48
+ Process.detach @pid
49
+ unless server_is_wake_up?
50
+ $stderr.puts "bossan won't wake up until you love it ..."
51
+ exit 1
52
+ end
53
+ end
54
+
55
+ def test_long_url1
56
+ response = Net::HTTP.start(DEFAULT_HOST, DEFAULT_PORT) {|http|
57
+ query = "A" * 4095
58
+ http.get("/#{query}")
59
+ }
60
+
61
+ assert_equal("200", response.code)
62
+ end
63
+
64
+ def test_long_url2
65
+ response = Net::HTTP.start(DEFAULT_HOST, DEFAULT_PORT) {|http|
66
+ query = "A" * 4096
67
+ http.get("/#{query}")
68
+ }
69
+
70
+ assert_equal("400", response.code)
71
+ end
72
+
73
+ def teardown
74
+ Process.kill(:INT, @pid)
75
+ end
76
+ end
@@ -1,5 +1,6 @@
1
1
  require_relative '../lib/bossan'
2
2
  require 'test/unit'
3
+ require 'uri'
3
4
  require 'net/http'
4
5
 
5
6
  class RackSpecTest < Test::Unit::TestCase
@@ -42,7 +43,8 @@ class RackSpecTest < Test::Unit::TestCase
42
43
 
43
44
  @pid = fork do
44
45
  trap(:INT) { Bossan.stop }
45
- Bossan.run(DEFAULT_HOST, DEFAULT_PORT, App.new)
46
+ Bossan.listen(DEFAULT_HOST, DEFAULT_PORT)
47
+ Bossan.run(App.new)
46
48
  end
47
49
  Process.detach @pid
48
50
  unless server_is_wake_up?
@@ -51,11 +53,19 @@ class RackSpecTest < Test::Unit::TestCase
51
53
  end
52
54
  end
53
55
 
54
- def test_simple
55
- response = nil
56
- Net::HTTP.start("localhost", 8000){|http|
57
- response = http.get("/")
56
+ def test_simple_get
57
+ response = Net::HTTP.start(DEFAULT_HOST, DEFAULT_PORT) {|http|
58
+ http.get("/")
58
59
  }
60
+
61
+ assert_equal("200", response.code)
62
+ assert_equal(ASSERT_RESPONSE, response.body)
63
+ end
64
+
65
+ def test_simple_post
66
+ response = Net::HTTP.post_form(URI.parse("http://#{DEFAULT_HOST}:#{DEFAULT_PORT}/"),
67
+ {'key1'=> 'value1', 'key2'=> 'value2'})
68
+
59
69
  assert_equal("200", response.code)
60
70
  assert_equal(ASSERT_RESPONSE, response.body)
61
71
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bossan
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Hiroki Noda
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-05-22 00:00:00.000000000 Z
11
+ date: 2013-06-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rack
@@ -48,8 +48,10 @@ files:
48
48
  - examples/blog/views/login.erb
49
49
  - examples/blog/views/show_entries.erb
50
50
  - examples/config.ru
51
+ - examples/fork_sample.rb
51
52
  - examples/hello.rb
52
53
  - examples/sinatra_app.rb
54
+ - examples/uploads.rb
53
55
  - examples/views/index.haml
54
56
  - examples/views_sample.rb
55
57
  - ext/bossan/bossan.h
@@ -70,8 +72,10 @@ files:
70
72
  - lib/bossan.rb
71
73
  - lib/bossan/version.rb
72
74
  - lib/rack/handler/bossan.rb
73
- - test/test_rack_env_query.rb
74
- - test/test_rack_env_simple.rb
75
+ - test/test_rack_bad_http_method.rb
76
+ - test/test_rack_env_simple_get.rb
77
+ - test/test_rack_env_simple_query.rb
78
+ - test/test_rack_long_url.rb
75
79
  - test/test_rack_spec.rb
76
80
  homepage: https://github.com/kubo39/bossan
77
81
  licenses: []