         transaction.test = test
         return callback()
 
-  isMultipart: (requestOptions) ->
-    caseInsensitiveRequestHeaders = {}
-    for key, value of requestOptions.headers
-      caseInsensitiveRequestHeaders[key.toLowerCase()] = value
-    caseInsensitiveRequestHeaders['content-type']?.indexOf("multipart") > -1
-
-  replaceLineFeedInBody: (transaction, requestOptions) ->
-    if transaction.request['body'].indexOf('\r\n') == -1
-      transaction.request['body'] = transaction.request['body'].replace(/\n/g, '\r\n')
-      transaction.request['headers']['Content-Length'] = Buffer.byteLength(transaction.request['body'], 'utf8')
-      requestOptions.headers = transaction.request['headers']
+  isMultipart: (headers) ->
+    contentType = caseless(headers).get('Content-Type')
+    return false unless contentType
+    return contentType.indexOf('multipart') > -1
+
+  # Finds newlines not preceeded by carriage returns and replaces them by
+  # newlines preceeded by carriage returns.
+  #
+  # See https://github.com/apiaryio/api-blueprint/issues/401
+  fixApiBlueprintMultipartBody: (body) ->
+    body.replace(/\r?\n/g, '\r\n')
 
 
 module.exports = TransactionRunner

          return callback(@hookHandlerError) if @hookHandlerError

          @validateTransaction test, transaction, callback


    if transaction.request['body'] and @isMultipart requestOptions
      @replaceLineFeedInBody transaction, requestOptions

    try
      @performRequest(requestOptions, handleRequest)

  # An actual HTTP request, before validation hooks triggering
  # and the response validation is invoked here
  performRequestAndValidate: (test, transaction, hooks, callback) ->
    if transaction.request.body and @isMultipart(transaction.request.headers)
      transaction.request.body = @fixApiBlueprintMultipartBody(transaction.request.body)

    @setContentLength(transaction)
    requestOptions = @getRequestOptionsFromTransaction(transaction)

