Go1.10 Support for HTTPS proxies

Source: Internet
Author: User
This is a creation in Article, where the information may have evolved or changed. Go1.9 6 months after the time, Go1.10 was [released] (https://blog.golang.org/go1.10). The new version brings big and small changes ([release Notes] (https://golang.org/doc/go1.10)), but I want to talk about changes in the ' Net/http ' package. Version 1.10 supports proxies on HTTPS ([commit] (HTTPS://GITHUB.COM/HYANGAH/GO/COMMIT/AB0372D91C17CA97A8258670BEADADC6601D0DA2)), In the original, it can only communicate with the agent by using normal (unencrypted) HTTP. Let's take a look at whether it can really work. # # Server To verify this change, first start a simple HTTP (S) proxy server with Golang. Specific practices can be learned from the following articles. [HTTP (S) Proxy in Golang in less than lines of code] (https://medium.com/@mlowicki/http-s-proxy-in-golang-in-less-than-100-lines-of-code-6a51c2f2c38c) # # Client ' Gopackage mainimport ("Net/url" "Net/http" "Crypto/tls" "Net/http/httputil" "FMT") func main () {u, err: = URL. Parse ("https://localhost:8888") if err! = Nil {panic (err)}tr: = &http. Transport{proxy:http. Proxyurl (U),//Disabled Http/2tlsnextproto:make (Map[string]func (authority string, C *tls. Conn) http. Roundtripper),}client: = &http. CLIENT{TRANSPORT:TR}RESP, Err: = client. Get ("https://google.com") if err! = Nil {panic (err)}defer resp.Body.close () Dump, err: = Httputil. Dumpresponse (RESP, true) if err! = Nil {panic (err)}fmt. Printf ("%q", Dump)} ' ' # # 1.9 vs. 1.10 ' ' >go Versiongo version go1.10 darwin/amd64>go run Proxyclient.go ' http/1.1 20 0 ok\r\ntransfer-encoding:...>go Versiongo version go1.9 darwin/amd64>go run Proxyclient.gopanic:Get https:// Google.com:malformed HTTP Response "\x15\x03\x01\x00\x02\x02\x16" ... "from the first result see, using Go1.10, we pass the proxy server [https// Google.com] (https//google.com) listener [https://localhost:8888] (https://localhost:8888) Gets the correct response. The second result shows that the HTTP client Go1.9 was rejected. If you want to learn more about the Go update, please follow me here or on [Twitter] (Https://twitter.com/mlowicki).

via:https://medium.com/@mlowicki/https-proxies-support-in-go-1-10-b956fb501d6b

Author: Michałłowicki Translator: zhaohj1118 proofreading: Rxcai

This article by GCTT original compilation, go language Chinese network honor launches

This article was originally translated by GCTT and the Go Language Chinese network. Also want to join the ranks of translators, for open source to do some of their own contribution? Welcome to join Gctt!
Translation work and translations are published only for the purpose of learning and communication, translation work in accordance with the provisions of the CC-BY-NC-SA agreement, if our work has violated your interests, please contact us promptly.
Welcome to the CC-BY-NC-SA agreement, please mark and keep the original/translation link and author/translator information in the text.
The article only represents the author's knowledge and views, if there are different points of view, please line up downstairs to spit groove

816 reads
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.