thick 0.0.7-java → 0.0.8-java

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 68f8688da128a9ca14f1f2f60bf95a5122957462
4
+ data.tar.gz: 864c08c83fe2016b2c897a2e8f57e372fd38a9d5
5
+ SHA512:
6
+ metadata.gz: 28d72f47efe4c073f6caf4fb7313606698c141a7d93d76791319cbdfbd9f3ac5bdc8ab3daa8479fc3aceb48e24216101dd0beb74ba8854114338aec7f39968f4
7
+ data.tar.gz: 16c7d25a1ec19054110de9c6f2cba2eac8f6b9b3015271157c79bff98c8dcf4d33facf91315ed64f8ec5df55ad78061cf270520b7623d7f1e1e224e4196cd938
data/CHANGELOG.md CHANGED
@@ -1,34 +1,39 @@
1
- ## 0.7 (20.12.2012)
1
+ ## 0.0.8 (XY.01.2013)
2
+
3
+ * Rack handler
4
+ * update versions in CHANGELOG
5
+
6
+ ## 0.0.7 (20.12.2012)
2
7
 
3
8
  * update Netty to 4th version
4
9
  * support for WebSockets
5
10
  * new buffer for uploaded data
6
11
  * simpler interface for async responses
7
12
 
8
- ## 0.6 (01.12.2012)
13
+ ## 0.0.6 (01.12.2012)
9
14
 
10
15
  * some weird version
11
16
 
12
- ## 0.5 (30.11.2012)
17
+ ## 0.0.5 (30.11.2012)
13
18
 
14
19
  * update Netty to 3.5.11
15
20
  * get rid of Loader experiment
16
21
  * update Rake gem (development)
17
22
 
18
- ## 0.4 (29.3.2012)
23
+ ## 0.0.4 (29.3.2012)
19
24
 
20
25
  * make gem Java specific
21
26
  * copy-less request body container
22
27
  * async responses
23
28
 
24
- ## 0.3 (26.3.2012)
29
+ ## 0.0.3 (26.3.2012)
25
30
 
26
31
  Update Netty to 3.4.0.Alpha2
27
32
 
28
- ## 0.2 (26.3.2012)
33
+ ## 0.0.2 (26.3.2012)
29
34
 
30
35
  First public version
31
36
 
32
- ## 0.1 (26.3.2012)
37
+ ## 0.0.1 (26.3.2012)
33
38
 
34
39
  Claim the gem ;)
data/README.md CHANGED
@@ -16,60 +16,122 @@ see PERFORMANCE.md
16
16
 
17
17
  Thick provides interfaces to control it's behaviour.
18
18
 
19
+ ### WebSockets
20
+
21
+ Thick allows to handle WebSocket in a simple and (IMHO) not intrusive way.
22
+
23
+ When a request to WebSocket is received, the server send a PUT request to
24
+
25
+ ```
26
+ /thick/websockets
27
+ ```
28
+ and provides two keys in the environment
29
+
30
+ ```ruby
31
+ env['thick.websocket'].set_handler(Your::Handler)
32
+ env['thick.websocket'].hand_shake("websocket URL")
33
+ ```
34
+
35
+ Your::Handler should subclass *Thick::WebSocket* class. It is used to provide interface
36
+ between your application and the connection. The interface for communication from the
37
+ client to your application looks like
38
+
39
+ ```ruby
40
+ class WebSocket < WebSocketHandler
41
+
42
+ def on_open
43
+ raise NotImplementedError.new("You should implement '#on_open' method.")
44
+ end
45
+
46
+ def on_data(data)
47
+ raise NotImplementedError.new("You should implement '#on_data(data)' method.")
48
+ end
49
+
50
+ def on_close
51
+ raise NotImplementedError.new("You should implement '#on_close' method.")
52
+ end
53
+
54
+ end
55
+ ```
56
+
57
+ Two more methods are available to control communicate back to the client
58
+
59
+ ```ruby
60
+ send("data") # sends data back to client
61
+ close # closes the connection
62
+ ```
63
+
64
+ The *hand_shake("url")* method URL asks the server to finish the hand shake and upgrade
65
+ the connection to WebSocket.
66
+
19
67
  ### Asynchronous responses
20
68
 
21
69
  Asynchronous responses provide functionality to stream response to the client by chunks.
22
70
 
23
71
  To enable streaming, run
24
72
 
25
- env['thick.response'].chunked # For chunked encoded stream
26
- env['thick.response'].streamed # For raw stream
73
+ ```ruby
74
+ env['thick.response'].chunked # For chunked encoded stream
75
+ env['thick.response'].streamed # For raw stream
76
+ ```
27
77
 
28
78
  and define "thick.async" callback in environment, so it reacts to "call" and takes one argument
29
79
 
30
- env['thick.async'] = proc do |response|
31
- # do something here
32
- end
80
+ ```ruby
81
+ env['thick.async'] = proc do |response|
82
+ # do something here
83
+ end
84
+ ```
33
85
 
34
86
  now simply respond as usual. Once the headers and the basic content is sent, the callback will be invoked.
35
87
 
36
88
  To write content to the stream use
37
89
 
38
- response.writeContent("some content")
90
+ ```ruby
91
+ response.writeContent("some content")
92
+ ```
39
93
 
40
94
  and do not forget close the stream once done
41
95
 
42
- response.close
96
+ ```ruby
97
+ response.close
98
+ ```
43
99
 
44
100
  Example using Sinatra
45
101
 
46
- require 'sinatra/base'
102
+ ```ruby
103
+ require 'sinatra/base'
47
104
 
48
- class App < Sinatra::Base
105
+ class App < Sinatra::Base
49
106
 
50
- get '/' do
51
- env['thick.async'] = proc do |response|
52
- (1..10).each do |i|
53
- response.writeContent(i.to_s)
54
- sleep(1)
55
- end
56
- response.close
57
- end
58
- env['thick.response'].chunked
59
- "0"
107
+ get '/' do
108
+ env['thick.async'] = proc do |response|
109
+ (1..10).each do |i|
110
+ response.writeContent(i.to_s)
111
+ sleep(1)
60
112
  end
61
-
113
+ response.close
62
114
  end
115
+ env['thick.response'].chunked
116
+ "0"
117
+ end
118
+
119
+ end
63
120
 
64
- run App
121
+ run App
122
+ ```
65
123
 
66
124
  ## Starting
67
125
 
68
- thick [-o <interface>] [-p <port>] [-E <environment>]
126
+ ```
127
+ thick [-o <interface>] [-p <port>] [-E <environment>]
128
+ ```
69
129
 
70
130
  ## Installation
71
131
 
72
- gem install thick
132
+ ```
133
+ gem install thick
134
+ ```
73
135
 
74
136
  ## License
75
137
 
data/ROADMAP.md CHANGED
@@ -4,8 +4,8 @@
4
4
  * Tests
5
5
  * Code refactorings
6
6
  * Optimizations
7
+ * Keep-alive
7
8
 
8
9
  ## Nice to have
9
10
 
10
- * SPDY support
11
- * WebSockets support
11
+ * SPDY support
Binary file
@@ -0,0 +1,36 @@
1
+ require File.expand_path('../../../thick', __FILE__)
2
+
3
+ module Rack
4
+ module Handler
5
+
6
+ class Thick
7
+
8
+ def self.run(app, options={})
9
+
10
+ env = ::Thick::Java::ServerEnvironment.new
11
+ env.address = options[:Host]
12
+ env.port = options[:Port]
13
+
14
+ env.application = ::Thick::Loader.new({:application => app, :environment => options[:environment]})
15
+
16
+ server = ::Thick::Java::Server.new(env)
17
+
18
+ Kernel.trap(:INT) { server.stop }
19
+
20
+ server.start
21
+
22
+ end
23
+
24
+ end
25
+
26
+ def self.valid_options
27
+ {
28
+ "Host=HOST" => "Hostname to listen on (default: localhost)",
29
+ "Port=PORT" => "Port to listen on (default: 8080)"
30
+ }
31
+ end
32
+
33
+ register 'thick', 'Rack::Handler::Thick'
34
+
35
+ end
36
+ end
data/lib/thick/loader.rb CHANGED
@@ -7,11 +7,10 @@ module Thick
7
7
  def initialize(options)
8
8
  @options = options
9
9
  ENV['RACK_ENV'] ||= ENV['RAILS_ENV'] ||= @options[:environment]
10
- @application = Rack::Builder.parse_file(@options[:file])[0]
10
+ @application = @options[:application] ||= Rack::Builder.parse_file(File.expand_path(@options[:file], @options[:directory]))[0]
11
11
  end
12
12
 
13
13
  def call(env)
14
- # ToDo: Does not work with Netty4 !!
15
14
  env['rack.input'] = Buffer.new(env['rack.input'])
16
15
  env['rack.errors'] = env['rack.errors'].to_io
17
16
 
@@ -23,6 +22,8 @@ module Thick
23
22
 
24
23
  response.setStatus(status)
25
24
 
25
+ hijack = headers.delete('rack.hijack')
26
+
26
27
  headers.each_pair do |name, value|
27
28
  response.setHeader(name, value)
28
29
  end
@@ -32,6 +33,9 @@ module Thick
32
33
  else
33
34
  body.each { |chunk| response.writeContent(chunk.to_s) }
34
35
  response.send
36
+ # Rack Hijack async response
37
+ hijack.call(env['rack.hijakck_io']) if hijack
38
+ # Thick native async response
35
39
  env['thick.async'].call(response) if response.chunked?
36
40
  end
37
41
  rescue => e
data/lib/thick/thick.rb CHANGED
@@ -1,6 +1,7 @@
1
1
  module Thick
2
2
 
3
3
  def self.create(options)
4
+
4
5
  options = {
5
6
  :address => '0.0.0.0',
6
7
  :port => 9292,
@@ -16,6 +17,7 @@ module Thick
16
17
  env.port = options[:port]
17
18
 
18
19
  env.application = Loader.new(options)
20
+
19
21
  Thick::Java::Server.new(env).start
20
22
 
21
23
  end
data/lib/thick/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Thick
2
- VERSION = '0.0.7' unless const_defined?(:VERSION)
2
+ VERSION = '0.0.8' unless const_defined?(:VERSION)
3
3
  end
metadata CHANGED
@@ -1,15 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: thick
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.7
5
- prerelease:
4
+ version: 0.0.8
6
5
  platform: java
7
6
  authors:
8
7
  - Marek Jelen
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2012-12-20 00:00:00.000000000 Z
11
+ date: 2014-01-15 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: rack
@@ -17,48 +16,40 @@ dependencies:
17
16
  requirements:
18
17
  - - '='
19
18
  - !ruby/object:Gem::Version
20
- version: 1.4.1
21
- none: false
19
+ version: 1.5.2
22
20
  requirement: !ruby/object:Gem::Requirement
23
21
  requirements:
24
22
  - - '='
25
23
  - !ruby/object:Gem::Version
26
- version: 1.4.1
27
- none: false
24
+ version: 1.5.2
28
25
  prerelease: false
29
26
  type: :runtime
30
27
  - !ruby/object:Gem::Dependency
31
28
  name: rspec
32
29
  version_requirements: !ruby/object:Gem::Requirement
33
30
  requirements:
34
- - - ! '>='
31
+ - - '>='
35
32
  - !ruby/object:Gem::Version
36
- version: !binary |-
37
- Mg==
38
- none: false
33
+ version: '2'
39
34
  requirement: !ruby/object:Gem::Requirement
40
35
  requirements:
41
- - - ! '>='
36
+ - - '>='
42
37
  - !ruby/object:Gem::Version
43
- version: !binary |-
44
- Mg==
45
- none: false
38
+ version: '2'
46
39
  prerelease: false
47
40
  type: :development
48
41
  - !ruby/object:Gem::Dependency
49
42
  name: rake
50
43
  version_requirements: !ruby/object:Gem::Requirement
51
44
  requirements:
52
- - - ! '>='
45
+ - - '>='
53
46
  - !ruby/object:Gem::Version
54
47
  version: '10'
55
- none: false
56
48
  requirement: !ruby/object:Gem::Requirement
57
49
  requirements:
58
- - - ! '>='
50
+ - - '>='
59
51
  - !ruby/object:Gem::Version
60
52
  version: '10'
61
- none: false
62
53
  prerelease: false
63
54
  type: :development
64
55
  description: Very lightweight web server for JRuby based on Netty library.
@@ -71,48 +62,40 @@ extra_rdoc_files: []
71
62
  files:
72
63
  - bin/thick
73
64
  - lib/thick.rb
74
- - lib/jars/netty-4.0.0.Alpha8.jar
75
- - lib/jars/thick-0.0.1.jar
76
- - lib/thick/buffer.rb
65
+ - lib/rack/handler/thick.rb
66
+ - lib/thick/thick.rb
77
67
  - lib/thick/java.rb
68
+ - lib/thick/websocket.rb
78
69
  - lib/thick/loader.rb
79
- - lib/thick/thick.rb
70
+ - lib/thick/buffer.rb
80
71
  - lib/thick/version.rb
81
- - lib/thick/websocket.rb
72
+ - lib/jars/netty-4.0.0.Alpha8.jar
73
+ - lib/jars/thick-0.0.1.jar
82
74
  - LICENSE
83
75
  - README.md
84
76
  - ROADMAP.md
85
77
  - CHANGELOG.md
86
78
  homepage: http://github.com/marekjelen/thick
87
79
  licenses: []
80
+ metadata: {}
88
81
  post_install_message:
89
82
  rdoc_options: []
90
83
  require_paths:
91
84
  - lib
92
85
  required_ruby_version: !ruby/object:Gem::Requirement
93
86
  requirements:
94
- - - ! '>='
87
+ - - '>='
95
88
  - !ruby/object:Gem::Version
96
- segments:
97
- - 0
98
- version: !binary |-
99
- MA==
100
- hash: 2
101
- none: false
89
+ version: '0'
102
90
  required_rubygems_version: !ruby/object:Gem::Requirement
103
91
  requirements:
104
- - - ! '>='
92
+ - - '>='
105
93
  - !ruby/object:Gem::Version
106
- segments:
107
- - 0
108
- version: !binary |-
109
- MA==
110
- hash: 2
111
- none: false
94
+ version: '0'
112
95
  requirements: []
113
96
  rubyforge_project:
114
- rubygems_version: 1.8.24
97
+ rubygems_version: 2.1.9
115
98
  signing_key:
116
- specification_version: 3
99
+ specification_version: 4
117
100
  summary: Very lightweight web server for JRuby
118
101
  test_files: []