Skip to content

Commit

Permalink
Update the node platform adapter to PUT things other than JSON.
Browse files Browse the repository at this point in the history
  • Loading branch information
airhorns committed Nov 28, 2011
1 parent bfc8eb0 commit 8e56fd0
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 14 deletions.
18 changes: 10 additions & 8 deletions lib/batman.node.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 9 additions & 6 deletions src/batman.node.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,10 @@ Batman.mixin Batman.Request::,
if auth
options.headers["Authorization"] = "Basic #{new Buffer(auth).toString('base64')}"

if options.method in ["PUT", "POST"]
if @get('method') in ["PUT", "POST"]
options.headers["Content-type"] = @get 'contentType'
body = @get 'data'
options.headers["Content-length"] = Buffer.byteLength(body)

request = requestModule.request options, (response) =>

Expand All @@ -78,15 +80,16 @@ Batman.mixin Batman.Request::,
@fire 'error', request
@fire 'loaded'

if @get 'method' is 'POST'
request.write JSON.stringify(@get 'data')
request.end()

request.on 'error', (e) ->
request.on 'error', (error) =>
@set 'response', error
@fire 'error', error
@fire 'loaded'

if @get('method') in ['POST', 'PUT']
request.write body

request.end()

request

module.exports = Batman

0 comments on commit 8e56fd0

Please sign in to comment.