diff options
| author | mo khan <mo.khan@gmail.com> | 2020-11-21 16:11:45 -0700 |
|---|---|---|
| committer | mo khan <mo.khan@gmail.com> | 2020-11-21 16:11:45 -0700 |
| commit | 73504a6b17408758155da297f4f1d78f31f7c4ca (patch) | |
| tree | 825eaaf2581f653c8142e0a853bef99d5c2c3bf5 /lib/server.rb | |
| parent | be35ec3d45b03e273fadb7b38f3d3f59717887a4 (diff) | |
feat: return 400 (Bad Request) when max blob size is exceeded
Diffstat (limited to 'lib/server.rb')
| -rw-r--r-- | lib/server.rb | 15 |
1 files changed, 10 insertions, 5 deletions
diff --git a/lib/server.rb b/lib/server.rb index 136ffdf..1d4706c 100644 --- a/lib/server.rb +++ b/lib/server.rb @@ -4,7 +4,7 @@ require 'rack' require 'json' class DataStorageServer - MAX_BYTES=1024 + MAX_BYTES=4096 def initialize(storage: {}) @storage = storage @@ -38,14 +38,19 @@ class DataStorageServer # # Status: 201 Created # {size, oid} - # Blobs can have a max size of 1024 bytes. + # Blobs can have a max size of MAX_BYTES bytes. # If a blob exceeds this size then the blob is truncated # and the first 1024 bytes are stored. def put(io) data = io.read(MAX_BYTES) - oid = Digest::SHA256.hexdigest(data) - @storage[oid] = data - ['201', {}, [JSON.generate({ size: data.size, oid: oid })]] + + if io.eof? + oid = Digest::SHA256.hexdigest(data) + @storage[oid] = data + ['201', {}, [JSON.generate({ size: data.size, oid: oid })]] + else + ['400', {}, []] + end end # Delete an Object |
