Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Please add support to HTTP proxy #22

Closed
m13253 opened this issue Aug 24, 2014 · 3 comments
Closed

Please add support to HTTP proxy #22

m13253 opened this issue Aug 24, 2014 · 3 comments

Comments

@m13253
Copy link
Contributor

m13253 commented Aug 24, 2014

I can not establish a direct connection to translate.google.com:80, so I need to use a HTTP proxy.

Could you please add support to HTTP proxy? Either by using $http_proxy or by specifying --proxy in command line.

By the way, is it difficult to use HTTPS instead of HTTP? I think it may be more secure.

Thanks.

@soimort
Copy link
Owner

soimort commented Aug 25, 2014

I guess it would be possible to handle HTTP proxies in gawk, though it was not implemented yet.

For HTTPS: one possible solution is to create a gawk binding of any existing SSL/TLS library (e.g. OpenSSL). Compared to "modern" scripting languages like Python and Ruby (which have almost everything in their standard libraries), that is indeed more difficult.

Using cURL to replace gawk's network layer is a more viable solution and it's on the future plan.

@m13253
Copy link
Contributor Author

m13253 commented Aug 30, 2014

I just read your source code. It seems that you manage TCP connections manually.
That will be pretty easy.

Just see these HTTP headers:
Without proxy:

GET /translate_a HTTP/1.1
Host: www.google.com

With proxy:

GET http://www.google.com/translate_a HTTP/1.1
Host: www.google.com

The proxy support can be implemented at Translate.awk:getResponse.
I am not good at awk. So I would be grateful if you can help me do that.

BTW, how do you use translate-shell in China?

@soimort
Copy link
Owner

soimort commented Aug 30, 2014

@m13253 That's not correct. The actual request is GET http://www.google.com/translate_a/..., not GET /translate_a. If you pay attention to the HttpProtocol HttpHost part:

url = HttpProtocol HttpHost "/translate_a/t?client=t"       \
        "&ie=UTF-8&oe=UTF-8"                                    \
        "&text=" preprocess(text) "&sl=" sl "&tl=" tl "&hl=" hl

print "GET " url |& HttpService

The problem is that gawk isn't aware of proxy. Not that only HTTP request line matters.

FYI. I don't use it in China since I don't live in China. Is http://www.google.com inaccessible to you?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants