+util = require('util');
+zlib = require('zlib');
 http = require 'http'
 https = require 'https'
 net = require 'net'


	return deferred.promise

sendHttpRequest = (ctx, responseDst, options, secured, callback) ->
	method = http

	if secured
		method = https

	routeReq = method.request options, (routeRes) ->
		responseDst.status = routeRes.statusCode

		routeRes.on "data", (chunk) ->
                        bufs.push chunk


                #See https://www.exratione.com/2014/07/nodejs-handling-uncertain-http-response-compression/
		routeRes.on "end", ->
                        responseDst.timestamp = new Date()
                        charset = obtainCharset(routeRes.headers)
                        if (routeRes.headers['content-encoding'] == 'gzip')
                                console.log('gzip')
                                zlib.gunzip(
                                        Buffer.concat(bufs),
                                        (gunzipError, buf)->
                                                if (gunzipError) then console.log(gunzipError)
                                                else responseDst.body = buf.toString(charset)
                                )
                        else if (routeRes.headers['content-encoding'] == 'deflate')
                                console.log('deflate')
                                zlib.inflate(
                                        Buffer.concat(bufs),
                                        (inflateError, buf)->
                                                if (inflateError) then console.log(inflateError)
                                                else responseDst.body = buf.toString(charset)
                                )
                        else
                                responseDst.body = Buffer.concat(bufs)
			callback()

	routeReq.on "error", (err) ->
