# Go 1.18 有關 http.Client 的 TLS 變動

## 前言

在 Go 1.17 升到 Go 1.18/1.19 時，對於那些會用到 http.Client 的 code ，有一個關鍵性的變動，那就是 TLS 的 version 預設值的改變。

通常來說，這個變動對於呼叫到比較新的 API 的程式都不太會有影響，但為了避免意外，**Server 是否支援 TLS 1.2 仍然是需要檢查的**。

## 這次有關 TLS 的變動是甚麼

由於 TLS 1.0/1.1 在 2021 年被棄用 ([RFC 8996: Deprecating TLS 1.0 and TLS 1.1](https://www.rfc-editor.org/rfc/rfc8996))，Go HTTP Client 從本來預設 TLS version 1.0 變更為 1.2。假如在想要在 Go 1.18 仍然使用 TLS 1.0 ，可以通過設置環境變數：`GODEBUG=tls10default=1` 來做到，但在 1.19 這個暫時性的方法也會被拔掉。只能在 Source Code 裡面更動。

## 如何確認 Server 的支援版本

可以用 curl 來檢查使用到的 API 是否支援 TLS version ([man page](https://curl.se/docs/manpage.html#--tls-max)): 

```bash
 curl --tls-max 1.2 https://example.com
 curl --tls-max 1.3 --tlsv1.2 https://example.com
```

## Ref

* [Go 1.18 Release Notes](https://tip.golang.org/doc/go1.18)
    
* [RFC 8996](https://www.rfc-editor.org/rfc/rfc8996)
    
* [Curl Man Page](https://curl.se/docs/manpage.html#--tls-max)
