iodine 0.1.13 → 0.1.14

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of iodine might be problematic. Click here for more details.

checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7fbbba2f03bc0eb7a52c6516a640eda4094230b7
4
- data.tar.gz: bb2b8b42038b32af81a6fa63b8ee3627fc47ef69
3
+ metadata.gz: e1fd668ed3460e3102fbd0ba91c8be5d89100356
4
+ data.tar.gz: 59416be95eb95921a05f9fa520aa8d61e843388f
5
5
  SHA512:
6
- metadata.gz: c8f093d5101e34538a205a2f4aa996781c6bde02838cde091885ae37c6d8bcfd346590824d6ea15ec825194d713eb30cea0b9cf8d1c256dde8c30da372019cd8
7
- data.tar.gz: e432d26f6af2a463737adff4ffbe8abf54486f61a4d9a475c544ee2c2316c2d8d72fe97fe486a2d701619e73a45afc041c2b2ad2b6bc800901f923192e1a9976
6
+ metadata.gz: 89add89d23f96c6870250a0028dc5298051147233c11d561f970f68b262e548e62454e92f6a78869c9938b46760cc5f4b146070b397e9ed593e5b1ba7704aa3e
7
+ data.tar.gz: 38db9c8b52f4ecf1083c1509f12a7aaa302bdfce668dbb592c09fea19a55a8c08d3d44439e559b116b2a879dedfdeb7ad7dbe56ae880c82dec1844aba90d1a70
data/CHANGELOG.md CHANGED
@@ -8,6 +8,16 @@ Please notice that this change log contains changes for upcoming releases as wel
8
8
 
9
9
  ***
10
10
 
11
+ Change log v.0.1.14
12
+
13
+ **
14
+
15
+ **Update**: the Response now supports `redirect_to` for both permanent and temporary redirection, with an optional `flash` cookie setup.
16
+
17
+ **Performance**: the Protocol class now recycles the data string as a thread global socket buffer (different threads have different buffer strings), preventing excessice `malloc` called by the Ruby interpreter. To keep the `data` (in `on_message(data)`) past the `on_message` method's scope, make sure to duplicate it using `data.dup`, or the string's buffer will be recycled.
18
+
19
+ ***
20
+
11
21
  Change log v.0.1.13
12
22
 
13
23
  **Change**: Session cookie lifetime is now limited to the browser's session. The local data will still persist until the tmp-folder is cleared (when using session file storage).
@@ -16,7 +26,7 @@ Change log v.0.1.13
16
26
 
17
27
  **Fix**: The `flash` cookie-jar will now actively prevent Symbol and String keys from overlapping.
18
28
 
19
- **Compatibility**: minor fixes and changes in preperation for Ruby 2.3.0.
29
+ **Compatibility**: minor fixes and changes in preperation for Ruby 2.3.0. These may affect performance due to slower String initialization times.
20
30
 
21
31
  ***
22
32
 
data/lib/iodine/core.rb CHANGED
@@ -72,7 +72,7 @@ module Iodine
72
72
  def startup use_rescue = false, hide_message = false
73
73
  @force_running = true
74
74
  threads = []
75
- (@thread_count ||= 1).times { threads << Thread.new { cycle } }
75
+ (@thread_count ||= 1).times { threads << Thread.new { Thread.current[:buffer] ||= String.new; cycle } }
76
76
  unless @stop
77
77
  if use_rescue
78
78
  sleep rescue true
@@ -277,7 +277,28 @@ module Iodine
277
277
  def uuid
278
278
  request[:io].id
279
279
  end
280
-
280
+
281
+ # Sets the response to redirect to a different page.
282
+ #
283
+ # The method accepts:
284
+ # url:: a String containing the URL to which the response forwards. `nil` or an empty string will be replaced with: `request.base_url`.
285
+ # options:: an options Hash. Any key-value pairs not supported WILL be used as flash cookie name-value pairs.
286
+ #
287
+ # The option's hash includes the following options:
288
+ # permanent:: a `true`/`false` value stating the redirection type. Defaults to `false` (temporary redirection).
289
+ # *:: remember, all other key-value pairs WILL be used as flash cookie name-value pairs.
290
+ def redirect_to url, options = {}
291
+ raise 'Cannot redirect after headers were sent.' if headers_sent?
292
+ url = "#{@request.base_url}/".freeze if url.nil? || (url.is_a?(String) && url.empty?)
293
+ raise TypeError, 'URL must be a String.' unless url.is_a?(String)
294
+ url = url_for(url) unless url.is_a?(String) || url.nil?
295
+ # redirect
296
+ @status = options.delete(:permanent) ? 301 : 302
297
+ self['location'] = url
298
+ @flash.update options
299
+ true
300
+ end
301
+
281
302
  # response status codes, as defined.
282
303
  STATUS_CODES = {100=>"Continue".freeze,
283
304
  101=>"Switching Protocols".freeze,
@@ -65,6 +65,10 @@ module Iodine
65
65
  def on_open
66
66
  end
67
67
  # This method is called whenever data is received from the IO.
68
+ #
69
+ # The `data` received is a reference to the socket's buffer and it will be cleared and replaced whenever `read`
70
+ # is called or when new IO data comes in (after `on_message` had completed). To presist
71
+ # the data, make sure to duplicate the data String using `data.dup`.
68
72
  def on_message data
69
73
  end
70
74
 
@@ -106,7 +110,7 @@ module Iodine
106
110
  # reads from the IO up to the specified number of bytes (defaults to ~2Mb).
107
111
  def read size = 2_097_152
108
112
  touch
109
- ssl? ? read_ssl(size) : @io.recv_nonblock( size )
113
+ ssl? ? read_ssl(size) : @io.read_nonblock( size , Thread.current[:buffer] )
110
114
  # @io.read_nonblock( size ) # this one is a bit slower...
111
115
  rescue OpenSSL::SSL::SSLErrorWaitReadable, IO::WaitReadable, IO::WaitWritable
112
116
  nil
@@ -181,7 +185,7 @@ module Iodine
181
185
  data = read
182
186
  if data
183
187
  on_message(data)
184
- data.clear
188
+ # data.clear
185
189
  end
186
190
  ensure
187
191
  @locker.unlock
@@ -216,7 +220,7 @@ module Iodine
216
220
  @send_locker.synchronize do
217
221
  data = String.new
218
222
  begin
219
- (data << @io.read_nonblock(size).to_s) until data.bytesize >= size
223
+ (data << @io.read_nonblock(size, Thread.current[:buffer]).to_s) until data.bytesize >= size
220
224
  rescue OpenSSL::SSL::SSLErrorWaitReadable, IO::WaitReadable, IO::WaitWritable
221
225
 
222
226
  rescue IOError
@@ -1,3 +1,3 @@
1
1
  module Iodine
2
- VERSION = "0.1.13"
2
+ VERSION = "0.1.14"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: iodine
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.13
4
+ version: 0.1.14
5
5
  platform: ruby
6
6
  authors:
7
7
  - Boaz Segev
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2015-11-13 00:00:00.000000000 Z
11
+ date: 2015-11-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler