Skip to content

Commit

Permalink
Multipart form requests need to use \r\n instead of only \n #74
Browse files Browse the repository at this point in the history
Added function that replaces line feeds \n with carriage return \r in body. It also recalcultes the content length header.
  • Loading branch information
Rikard Qvarforth committed Nov 6, 2014
1 parent 9dec2cc commit 8f400bf
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion src/transaction-runner.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ logger = require './logger'


String::startsWith = (str) ->
return this.slice(0, str.length) is str
return this.slice(0, str.length) is str

class TransactionRunner
constructor: (@configuration) ->
Expand Down Expand Up @@ -193,11 +193,23 @@ class TransactionRunner

transport = if transaction.protocol is 'https:' then https else http
try

if transaction.request['body'] != ''
@replaceLineFeedInBody transaction, requestOptions

req = transport.request requestOptions, handleRequest
req.write transaction.request['body'] if transaction.request['body'] != ''
req.end()
catch error
configuration.emitter.emit 'test error', error, test if error
return callback()

replaceLineFeedInBody: (transaction, requestOptions) =>
logger.debug 'Content-Length before: ' + requestOptions['headers']['Content-Length']
transaction.request['body'] = transaction.request['body'].replace(/\n/g, '\r\n')
transaction.request['headers']['Content-Length'] = transaction.request['body'].length
requestOptions.headers = transaction.request['headers']
logger.debug 'Content-Length after: ' + requestOptions['headers']['Content-Length']


module.exports = TransactionRunner

0 comments on commit 8f400bf

Please sign in to comment.