Skip to content

Commit

Permalink
easier fix for Content-Length issue.
Browse files Browse the repository at this point in the history
  • Loading branch information
johnnycrab committed Jun 12, 2015
1 parent 24ac455 commit a7b61d7
Showing 1 changed file with 2 additions and 3 deletions.
5 changes: 2 additions & 3 deletions lib/vimeo.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,6 @@ Vimeo.prototype.access_token = null;
Vimeo.prototype.request = function vimeo_request (options, callback) {
var client = null;
var writeBody = null;
var needsContentLength = false;

// if a url was provided, build an options object
if (typeof options === "string") {
Expand All @@ -104,7 +103,6 @@ Vimeo.prototype.request = function vimeo_request (options, callback) {

// Write the request body
if (['POST','PATCH','PUT','DELETE'].indexOf(request_options.method) !== -1) {
needsContentLength = true;
if (request_options.headers['Content-Type'] === 'application/json') {
writeBody = JSON.stringify(options.query);
} else {
Expand All @@ -113,7 +111,7 @@ Vimeo.prototype.request = function vimeo_request (options, callback) {

}

if (needsContentLength) request_options.headers['Content-Length'] = writeBody ? Buffer.byteLength(writeBody, 'utf8') : 0;
if (writeBody) request_options.headers['Content-Length'] = Buffer.byteLength(writeBody, 'utf8');

// Locate the proper client from the request protocol
client = request_options.protocol === 'https:' ? https_module : http_module;
Expand Down Expand Up @@ -192,6 +190,7 @@ Vimeo.prototype._buildRequestOptions = function (options) {
// Set proper headers for POST, PATCH and PUT bodies
if (['POST','PATCH','PUT','DELETE'].indexOf(request_options.method) !== -1 && !request_options.headers['Content-Type']) {
request_options.headers['Content-Type'] = 'application/json';
request_options.headers['Content-Length'] = 0;

This comment has been minimized.

Copy link
@johnnycrab

johnnycrab Jun 12, 2015

Author Owner

Ignore the other changes. Was a former fix, but this only line does the job just as well.


// Apply parameters to the url for GET requests
} else if (request_options.method === 'GET') {
Expand Down

0 comments on commit a7b61d7

Please sign in to comment.