Translate,Utils,GoogleTranslate: add HTTPS/TLS support via curl#550
Open
tsaitang404 wants to merge 1 commit into
Open
Translate,Utils,GoogleTranslate: add HTTPS/TLS support via curl#550tsaitang404 wants to merge 1 commit into
tsaitang404 wants to merge 1 commit into
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
transreturns[ERROR] Null response.for all translation requests:Root cause:
gawk's/inet/tcpdoes not support TLS.googleInit()setsHttpProtocol = "http://"on port 80, buttranslate.googleapis.comnow requires HTTPS. The plaintext TCP connection returns an empty response, triggering the null assert.Direct
curlto the same endpoint succeeds:Fix
GoogleTranslate: switch tohttps://on port 443initHttpService: whenHttpProtocol == "https://", setUseHttps = 1and skip gawk TCP init (which has no TLS support)getResponse: whenUseHttps, build the full URL and delegate to newcurlGetResponse()postResponse: whenUseHttps, delegate to existingcurlPost()Utils: addcurlGetResponse()with full--proxy/--cookie/--user-agentsupport, consistent with the existingcurl()functionThe 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.