Revert "Send content-length header when getting file"

This reverts commit 6f5f7a98fd3ce53091aacc744f43c7704ba73461.
This commit is contained in:
James Allen 2014-05-23 13:57:18 +01:00
parent daf4f1ffd4
commit e529875245
7 changed files with 25 additions and 38 deletions

View file

@ -28,13 +28,12 @@ module.exports =
getFileStream: (location, name, callback = (err, res)->)->
filteredName = filterName name
logger.log location:location, name:filteredName, "getting file"
path = "#{location}/#{filteredName}"
fs.stat path, (error, stat) ->
sourceStream = fs.createReadStream path
sourceStream = fs.createReadStream "#{location}/#{filteredName}"
sourceStream.on 'error', (err) ->
logger.err err:err, location:location, name:name, "Error reading from file"
callback err
callback null, sourceStream, stat.size
callback null,sourceStream
copyFile: (location, fromName, toName, callback = (err)->)->
filteredFromName=filterName fromName

View file

@ -12,7 +12,7 @@ module.exports =
{key, bucket} = req
{format, style} = req.query
logger.log key:key, bucket:bucket, format:format, style:style, "reciving request to get file"
FileHandler.getFile bucket, key, {format:format,style:style}, (err, fileStream, size)->
FileHandler.getFile bucket, key, {format:format,style:style}, (err, fileStream)->
if err?
logger.err err:err, key:key, bucket:bucket, format:format, style:style, "problem getting file"
if !res.finished and res?.send?
@ -22,7 +22,6 @@ module.exports =
res.send 200
else
logger.log key:key, bucket:bucket, format:format, style:style, "sending file to response"
res.header("Content-Length", size)
fileStream.pipe res
insertFile: (req, res)->

View file

@ -22,20 +22,20 @@ module.exports =
(done)-> PersistorManager.deleteFile bucket, convetedKey, done
], callback
getFile: (bucket, key, opts = {}, callback = (err, fileStream, size) ->)->
getFile: (bucket, key, opts = {}, callback)->
logger.log bucket:bucket, key:key, opts:opts, "getting file"
if !opts.format? and !opts.style?
@_getStandardFile bucket, key, opts, callback
else
@_getConvertedFile bucket, key, opts, callback
_getStandardFile: (bucket, key, opts, callback = (err, fileStream, size) ->)->
PersistorManager.getFileStream bucket, key, (err, fileStream, size)->
_getStandardFile: (bucket, key, opts, callback)->
PersistorManager.getFileStream bucket, key, (err, fileStream)->
if err?
logger.err bucket:bucket, key:key, opts:opts, "error getting fileStream"
callback err, fileStream, size
callback err, fileStream
_getConvertedFile: (bucket, key, opts, callback = (err, fileStream, size) ->)->
_getConvertedFile: (bucket, key, opts, callback)->
convetedKey = KeyBuilder.addCachingToKey(key, opts)
PersistorManager.checkIfFileExists bucket, convetedKey, (err, exists)=>
if exists

View file

@ -67,7 +67,7 @@ module.exports =
return callback(err)
@sendFile bucketName, key, fsPath, callback
getFileStream: (bucketName, key, callback = (err, res, size)->)->
getFileStream: (bucketName, key, callback = (err, res)->)->
logger.log bucketName:bucketName, key:key, "getting file from s3"
s3Client = knox.createClient
key: settings.filestore.s3.key
@ -76,7 +76,7 @@ module.exports =
s3Stream = s3Client.get(key)
s3Stream.end()
s3Stream.on 'response', (res) ->
callback null, res, res.headers["content-length"]
callback null, res
s3Stream.on 'error', (err) ->
logger.err err:err, bucketName:bucketName, key:key, "error getting file stream from s3"
callback err

View file

@ -66,12 +66,11 @@ describe "FSPersistorManagerTests", ->
describe "getFileStream", ->
it "should use correct file location", (done) ->
@Fs.createReadStream.returns(@stream = on:->)
@Fs.stat = sinon.stub().callsArgWith(1, null, { size: @size = 42 })
@FSPersistorManager.getFileStream @location, @name1, (err, res, size)=>
@Fs.createReadStream.returns(
on:->
)
@FSPersistorManager.getFileStream @location, @name1, (err,res)=>
@Fs.createReadStream.calledWith("#{@location}/#{@name1Filtered}").should.equal.true
res.should.equal @stream
size.should.equal @size
done()
describe "copyFile", ->

View file

@ -43,16 +43,15 @@ describe "FileController", ->
project_id:@project_id
file_id:@file_id
@res =
header: sinon.stub()
setHeader: ->
@fileStream = {}
describe "getFile", ->
it "should pipe the stream", (done)->
@FileHandler.getFile.callsArgWith(3, null, @fileStream, @size = 42)
@FileHandler.getFile.callsArgWith(3, null, @fileStream)
@fileStream.pipe = (res)=>
res.should.equal @res
res.header.calledWith("Content-Length", @size).should.equal true
done()
@controller.getFile @req, @res

View file

@ -45,20 +45,11 @@ describe "S3PersistorManagerTests", ->
it "should use correct key", (done)->
@response =
headers:
"content-length": @size = 42
@stubbedKnoxClient.get.returns(@stream =
on: (e, callback) =>
if e == "response"
callback(@response)
@stubbedKnoxClient.get.returns(
on:->
end:->
)
@S3PersistorManager.getFileStream @bucketName, @key, (err, res, size) =>
res.should.equal @response
size.should.equal @size
@S3PersistorManager.getFileStream @bucketName, @key, @fsPath, (err)=>
@stubbedKnoxClient.get.calledWith(@key).should.equal true
done()