tus-server 1.0.0 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9dfd9cb38d7ef46fe3ac684a7ee3569f66e97c84
4
- data.tar.gz: 19b75e3d0c222d47c46432f1fd198ab9e27f56bb
3
+ metadata.gz: 0016bea27534678199b2a3631ab710a9bb4bfd71
4
+ data.tar.gz: d2026f565ba010d7e6e64e9ab89bd06a1afc2be0
5
5
  SHA512:
6
- metadata.gz: 48c902ba0c5ff439869a93b3b4fa851fe17644c7a41978b25041f4955b5c0697e9a725ece84a5ee1d294acd7c631ad04b9d4348f327a64c1ca0002549b1db509
7
- data.tar.gz: 482543723d79aeb1df06a9fb429d8f39584e4891905e795c32df660f860413ffcac4408892114a85c67e4b1c867e1d6b9462157d6f495c9399d3d641e921f6b8
6
+ metadata.gz: 0c11c877cad9b293df94ec7859bfea15b40f9401c99ea593a1662e9735ba6c4d216cf986b5f761e8c81d5bee6081ac49686dc3550682f6b695c08c39a7306a9b
7
+ data.tar.gz: 19671d54820222ebb0855df11da3d673975e8e50afa3fe1f3ab30659b23cdaadc45e71100923c132562f348856949d3e216816800278e96d729ce5ff8f88455c
data/README.md CHANGED
@@ -42,7 +42,7 @@ endpoint:
42
42
  // using tus-js-client
43
43
  new tus.Upload(file, {
44
44
  endpoint: "http://localhost:9292/files",
45
- chunkSize: 5*1024*1024, // required unless using Goliath
45
+ chunkSize: 5*1024*1024, // required unless using Goliath or Unicorn
46
46
  // ...
47
47
  })
48
48
  ```
@@ -53,39 +53,62 @@ nicely with tus-ruby-server, see [shrine-tus-demo] for an example integration.
53
53
 
54
54
  ### Goliath
55
55
 
56
- [Goliath] is the ideal web server to run tus-ruby-server on, because by
57
- utilizing [EventMachine] it's asnychronous both in reading the request body and
58
- writing to the response body, so it's not affected by slow clients. Goliath
59
- also allows tus-ruby-server to handle interrupted requests, by saving data that
60
- has been uploaded until the interruption. This means that with Goliath it's
61
- **not** mandatory for client to chunk the upload into multiple requests in
62
- order to achieve resumable uploads, which would be the case for most other web
63
- servers.
56
+ Among all the existing Ruby web servers, [Goliath] is probably the ideal one to
57
+ run tus-ruby-server on. It's built on top of [EventMachine], making it
58
+ asynchronous both in reading the request body and writing to the response body.
59
+ Goliath also allows tus-ruby-server to handle interrupted requests, by saving
60
+ data that has been uploaded until the interruption. This means that with
61
+ Goliath it's **not** mandatory for client to chunk the upload into multiple
62
+ requests in order to achieve resumable upload (which would be the case for most
63
+ other web servers).
64
64
 
65
- Tus-ruby-server ships with Goliath integration, you just need to require it in
66
- a Ruby file and run that file, and that will automatically start up Goliath.
65
+ It's recommended that you use [goliath-rack_proxy] for running your tus server
66
+ app:
67
67
 
68
68
  ```rb
69
69
  # Gemfile
70
70
  gem "tus-server", "~> 1.0"
71
- gem "goliath"
72
- gem "async-rack", ">= 0.5.1"
71
+ gem "goliath-rack_proxy"
73
72
  ```
74
73
  ```rb
75
74
  # tus.rb
76
- require "tus/server/goliath"
75
+ require "tus/server"
76
+ require "goliath/rack_proxy"
77
77
 
78
78
  # any additional Tus::Server configuration you want to put in here
79
+
80
+ class GoliathTusServer < Goliath::RackProxy
81
+ rack_app Tus::Server
82
+ rewindable_input false # set to true if you're using checksums
83
+ end
79
84
  ```
80
85
  ```sh
81
86
  $ ruby tus.rb --stdout # enable logging
82
87
  ```
83
88
 
84
- Any options provided after the Ruby file will be passed in to the Goliath
85
- server, see [this wiki][goliath server options] for all available options that
86
- Goliath supports. As shown above, running tus-ruby-server on Goliath means you
87
- have to run it separately from your main app (unless your main app is also on
88
- Goliath).
89
+ ### Unicorn
90
+
91
+ Like Goliath, Unicorn also support streaming uploads, and tus-ruby-server knows
92
+ how to automatically recover from `Unicorn::ClientShutdown` exceptions during
93
+ upload, storing data that it has received up until that point. Just note that
94
+ in order to achieve streaming uploads, Nginx should be configured **not** to
95
+ buffer incoming requests.
96
+
97
+ But it's also fine to have Nginx buffer requests, just note that in this case
98
+ Nginx won't forward incomplete upload requests to tus-ruby-server, so in order
99
+ for resumable upload to be possible the client needs to send data in multiple
100
+ upload requests (which can then be retried individually).
101
+
102
+ ### Other web servers
103
+
104
+ It's perfectly feasible to run tus-ruby-server on web servers other than
105
+ Goliath or Unicorn (even necessary if you want to run it inside another app).
106
+ Just keep in mind that most other web servers don't support request streaming,
107
+ which means that tus-ruby-server will be able to start processing upload
108
+ requess only once the whole request body has been received. Additionally,
109
+ incomplete upload requests won't be forwarded to tus-ruby-server, so in order
110
+ for resumable upload to be possible the client needs to send data in multiple
111
+ upload requests (which can then be retried individually).
89
112
 
90
113
  ## Storage
91
114
 
@@ -311,4 +334,4 @@ The tus-ruby-server was inspired by [rubytus].
311
334
  [Range requests]: https://tools.ietf.org/html/rfc7233
312
335
  [Goliath]: https://github.com/postrank-labs/goliath
313
336
  [EventMachine]: https://github.com/eventmachine/eventmachine
314
- [goliath server options]: https://github.com/postrank-labs/goliath/wiki/Server
337
+ [goliath-rack_proxy]: https://github.com/janko-m/goliath-rack_proxy
data/lib/tus/checksum.rb CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen-string-literal: true
2
+
1
3
  module Tus
2
4
  class Checksum
3
5
  CHUNK_SIZE = 16*1024
@@ -48,7 +50,7 @@ module Tus
48
50
  require "zlib"
49
51
  require "base64"
50
52
  crc = Zlib.crc32("")
51
- while (data = io.read(CHUNK_SIZE, buffer ||= ""))
53
+ while (data = io.read(CHUNK_SIZE, buffer ||= String.new))
52
54
  crc = Zlib.crc32(data, crc)
53
55
  end
54
56
  Base64.strict_encode64(crc.to_s)
@@ -57,7 +59,7 @@ module Tus
57
59
  def digest(name, io)
58
60
  require "digest"
59
61
  digest = Digest.const_get(name).new
60
- while (data = io.read(CHUNK_SIZE, buffer ||= ""))
62
+ while (data = io.read(CHUNK_SIZE, buffer ||= String.new))
61
63
  digest.update(data)
62
64
  end
63
65
  digest.base64digest
data/lib/tus/errors.rb CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen-string-literal: true
2
+
1
3
  module Tus
2
4
  Error = Class.new(StandardError)
3
5
  NotFound = Class.new(Error)
data/lib/tus/info.rb CHANGED
@@ -1,3 +1,4 @@
1
+ # frozen-string-literal: true
1
2
  require "base64"
2
3
  require "time"
3
4
 
data/lib/tus/input.rb CHANGED
@@ -1,3 +1,4 @@
1
+ # frozen-string-literal: true
1
2
  require "tus/errors"
2
3
 
3
4
  module Tus
data/lib/tus/server.rb CHANGED
@@ -1,3 +1,4 @@
1
+ # frozen-string-literal: true
1
2
  require "roda"
2
3
 
3
4
  require "tus/storage/filesystem"
@@ -1,6 +1,9 @@
1
+ # frozen-string-literal: true
1
2
  require "tus/server"
2
3
  require "goliath"
3
4
 
5
+ warn "Tus::Server::Goliath has been deprecated in favor of goliath-rack_proxy -- https://github.com/janko-m/goliath-rack_proxy"
6
+
4
7
  class Tus::Server::Goliath < Goliath::API
5
8
  # Called as soon as request headers are parsed.
6
9
  def on_headers(env, headers)
@@ -1,3 +1,4 @@
1
+ # frozen-string-literal: true
1
2
  require "tus/errors"
2
3
 
3
4
  require "pathname"
@@ -1,3 +1,4 @@
1
+ # frozen-string-literal: true
1
2
  require "mongo"
2
3
 
3
4
  require "tus/info"
@@ -1,3 +1,4 @@
1
+ # frozen-string-literal: true
1
2
  require "aws-sdk"
2
3
 
3
4
  require "tus/info"
@@ -102,10 +103,15 @@ module Tus
102
103
  chunk = next_chunk or break
103
104
  end
104
105
 
105
- jobs.each do |thread, body|
106
- info["multipart_parts"] << thread.value
107
- bytes_uploaded += body.size
108
- body.close
106
+ begin
107
+ jobs.each do |thread, body|
108
+ info["multipart_parts"] << thread.value
109
+ bytes_uploaded += body.size
110
+ body.close
111
+ end
112
+ rescue Seahorse::Client::NetworkingError => exception
113
+ warn "ERROR: #{exception.inspect} occurred during upload"
114
+ # ignore networking errors and return what client has uploaded so far
109
115
  end
110
116
 
111
117
  bytes_uploaded
@@ -214,6 +220,7 @@ module Tus
214
220
  def copy_parts(objects, multipart_upload)
215
221
  parts = compute_parts(objects, multipart_upload)
216
222
  queue = parts.inject(Queue.new) { |queue, part| queue << part }
223
+ queue.close
217
224
 
218
225
  threads = @thread_count.times.map { copy_part_thread(queue) }
219
226
 
@@ -236,8 +243,7 @@ module Tus
236
243
  Thread.new do
237
244
  begin
238
245
  results = []
239
- loop do
240
- part = queue.deq(true) rescue break
246
+ while part = queue.pop
241
247
  results << copy_part(part)
242
248
  end
243
249
  results
data/tus-server.gemspec CHANGED
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |gem|
2
2
  gem.name = "tus-server"
3
- gem.version = "1.0.0"
3
+ gem.version = "1.1.0"
4
4
 
5
5
  gem.required_ruby_version = ">= 2.1"
6
6
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tus-server
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Janko Marohnić
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-07-17 00:00:00.000000000 Z
11
+ date: 2017-07-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: roda