I am using proximo on a heroku hosting to proxy my requests.
When I send a proximo request through the http
I am able to receive data but it seems to be encrypted. If I use the https
module I get a socket hang up
error.
app.get('/', function (req, res) {
// This is stuff for proximo
var proxy = url.parse("http://url-of-my-proxy.com");
var headers, key, options, val, _ref;
headers = {
"Proxy-Authorization": "Basic " + (new Buffer(proxy.auth).toString("base64")),
"Host": "www.googleapis.com"
};
delete req.headers.host;
_ref = req.headers;
for (key in _ref) {
val = _ref[key];
headers[key] = val;
}
// This is the actual request
options = {
hostname: proxy.hostname,
port : proxy.port || 80,
path : "https://www.googleapis.com/customsearch/v1?key=myKeycx=myKey&q=" + q, // I need this to be in https, else google returns an error
headers : headers
};
var req = http.get(options, function (response) {
response.setEncoding('utf8');
response.on('data', function (data) {
console.log("Answer : ", data); // Here I see only unreadable characters like the answer is encoded
});
})
req.on("error", function (err) {
callback(err, false);
});
}
So I assume that what I receive is pure https data and it needs to be decrypted. But I can't find how.
My initial result was: <Buffer 1f 8b 08 00 [...] 83 ...>
Then I read that I need to use the utf8 encoding and got:
�H�(er : ��1�0�r�:BHP�
�Kv�Le������h��UE�7¹#I�yE�R�
(G�1+'~��rr\�,.�|�F�F�sԄ��h�vw!�b˲��]�$���?�������F�
Is there something I am missing to get the result of my request here?
Edit:
I now know that the content was zipped, so with a little modification I was able to get the data:
var zlib = require('zlib');
var req = https.get(options, function (response) {
response.pipe(zlib.createGunzip()).pipe(process.stdout);
});
Piping the answer to the console. But I get the google error saying that my request needs to be https.
So the problem is still there: If I send an https request I just get no answer for Proximo. Is it that they don't support https
or is there any other way?