Created
December 2, 2011 22:25
-
-
Save smathy/1425125 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
https = require 'https' | |
module.exports.request = ( options, success_handler, error_handler) -> | |
req_data = if options.data? then JSON.stringify options.data else "" | |
options['headers']['Content-length'] = req_data.length | |
req = https.request options, (res) -> | |
data = '' | |
res.on 'data', (c) -> | |
data += c | |
res.on 'end', -> | |
if 200 <= res.statusCode < 300 | |
if success_handler? and data? | |
success_handler JSON.parse data | |
else | |
if error_handler? | |
error_handler res | |
else | |
console.log "Error: #{res.statusCode}\n#{data}" | |
req.write(req_data) | |
req.end() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
There I fixed it: https://gist.github.com/raw/1425125/17df8e90fb8d9731a5abc278cdf749de52588ef8/web_helper.coffee