From 7b8fa3857f4695d1225786dc32c0423af6ca359c Mon Sep 17 00:00:00 2001 From: Your Name Date: Mon, 6 Oct 2014 16:54:20 -0300 Subject: [PATCH] Accept the HTTP 201 (created) status as a valid response from the server If the server responds with a 201 status, it means that it has successfully created the respurce (in this case the file being uploaded) so it should be a success case in the status function. --- src/flow.js | 5 +++-- test/uploadSpec.js | 6 +++--- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/flow.js b/src/flow.js index f5feddfc..6b61fead 100644 --- a/src/flow.js +++ b/src/flow.js @@ -1302,9 +1302,10 @@ // or 'LOADING' - meaning that stuff is happening return 'uploading'; } else { - if (this.xhr.status == 200 || this.xhr.status == 202) { + if (this.xhr.status == 200 || this.xhr.status == 201 || this.xhr.status == 202) { // HTTP 200, perfect - // HTTP 202 Accepted - The request has been accepted for processing, but the processing has not been completed. + // HTTP 201, Created - The request has been fulfilled and resulted in a new resource (in this case the file) being created. + // HTTP 202, Accepted - The request has been accepted for processing, but the processing has not been completed. return 'success'; } else if (this.flowObj.opts.permanentErrors.indexOf(this.xhr.status) > -1 || this.retries >= this.flowObj.opts.maxChunkRetries) { diff --git a/test/uploadSpec.js b/test/uploadSpec.js index d7528ddc..4985a284 100644 --- a/test/uploadSpec.js +++ b/test/uploadSpec.js @@ -76,7 +76,7 @@ describe('upload file', function() { expect(requests[i]).toBeDefined(); expect(file.isComplete()).toBeFalsy(); expect(file.isUploading()).toBeTruthy(); - requests[i].respond(200); + requests[i].respond(202); expect(file.progress()).toBe((i+1) / 10); expect(file.isComplete()).toBeFalsy(); expect(file.isUploading()).toBeTruthy(); @@ -85,7 +85,7 @@ describe('upload file', function() { expect(file.isComplete()).toBeFalsy(); expect(file.isUploading()).toBeTruthy(); expect(file.progress()).toBe(0.9); - requests[i].respond(200); + requests[i].respond(201); expect(file.isComplete()).toBeTruthy(); expect(file.isUploading()).toBeFalsy(); expect(file.progress()).toBe(1); @@ -484,4 +484,4 @@ describe('upload file', function() { expect(fileThird.timeRemaining()).toBe(0); expect(flow.timeRemaining()).toBe(0); }); -}); \ No newline at end of file +});