Skip to content

Translate,Utils,GoogleTranslate: add HTTPS/TLS support via curl#550

Open
tsaitang404 wants to merge 1 commit into
soimort:developfrom
tsaitang404:fix/https-support-for-tls-engines
Open

Translate,Utils,GoogleTranslate: add HTTPS/TLS support via curl#550
tsaitang404 wants to merge 1 commit into
soimort:developfrom
tsaitang404:fix/https-support-for-tls-engines

Conversation

@tsaitang404

Copy link
Copy Markdown

Problem

trans returns [ERROR] Null response. for all translation requests:

$ trans :en "hello"
[ERROR] Null response.
[ERROR] Oops! Something went wrong and I can not translate it for you :(

Root cause: gawk's /inet/tcp does not support TLS. googleInit() sets HttpProtocol = "http://" on port 80, but translate.googleapis.com now requires HTTPS. The plaintext TCP connection returns an empty response, triggering the null assert.

Direct curl to the same endpoint succeeds:

$ curl -s "https://translate.googleapis.com/translate_a/single?client=gtx&sl=auto&tl=en&dt=t&q=hello"
[[["hello","hello",...]]]

Fix

  • GoogleTranslate: switch to https:// on port 443
  • initHttpService: when HttpProtocol == "https://", set UseHttps = 1 and skip gawk TCP init (which has no TLS support)
  • getResponse: when UseHttps, build the full URL and delegate to new curlGetResponse()
  • postResponse: when UseHttps, delegate to existing curlPost()
  • Utils: add curlGetResponse() with full --proxy / --cookie / --user-agent support, consistent with the existing curl() function

The approach is generic: any other engine requiring HTTPS only needs to set HttpProtocol = "https://" in its *Init() function.

Copyright

I dedicate this contribution to the public domain under the terms of the Unlicense, consistent with this project's license.

gawk's /inet/tcp does not support TLS, causing engines that use HTTPS
endpoints (e.g. translate.googleapis.com) to silently return empty
responses ("Null response" error).

Changes:
- GoogleTranslate: switch HttpProtocol to https:// on port 443
- initHttpService: detect https:// and set UseHttps flag, skip gawk TCP
- getResponse: when UseHttps, delegate to new curlGetResponse()
- postResponse: when UseHttps, delegate to curlPost()
- Utils: add curlGetResponse() supporting proxy/cookie/user-agent

The fix is generic: any future engine requiring HTTPS only needs to set
HttpProtocol = "https://" in its init function.
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

Successfully merging this pull request may close these issues.

1 participant