tinify / tinify-nodejs

Node.js client for the Tinify API.
https://tinypng.com/developers
MIT License
421 stars 74 forks source link

Add support for proxies in Client.js #4

Closed falvhb closed 8 years ago

falvhb commented 8 years ago

We are behind a company firewall and can not use the package as of now.

I tried to patch the package in Client.js:

options.headers["Host"] = options.host;
options.hostname = 'proxy.de';
options.port = 80;

but this caused an error I do not understand:

Error

Unhandled rejection ConnectionError: Error while connecting: write EPROTO 0:erro
r:140770FC:SSL routines:SSL23_GET_SERVER_HELLO:unknown protocol:openssl\ssl\s23_
clnt.c:782:

Thanks!

rolftimmermans commented 8 years ago

Hi! Thanks for letting us know!

Our compression service is offered only with a secured HTTPS connection. If you are required to use a proxy server, then this is typically done with a CONNECT request (see https://tools.ietf.org/html/rfc2616#section-9.9), which opens a TCP tunnel through the HTTP proxy.

The support for this is not available in our client. If you wish to make this work then you have to do your own HTTP requests. Our HTTP API is simple enough, so that should not be a problem. You can view examples in our Node.js client or on our HTTP API reference page: https://tinypng.com/developers/reference

Support for using HTTPS connections over proxies is available in some generic HTTP client libraries like request (https://github.com/request/request#proxies).

We'd love to hear from you how this goes!

rolftimmermans commented 7 years ago

You might be pleased to know that it is possible as of version 1.4 to configure a proxy with the API client directly.

Tinify.proxy = "http://proxy.de:80"
...