wrapTransportWithEntitlementsCheck adds a middleware to the HTTP transport that checks for entitlement warnings and prints them to the user.
(rt http.RoundTripper, w io.Writer)
| 1574 | // wrapTransportWithEntitlementsCheck adds a middleware to the HTTP transport |
| 1575 | // that checks for entitlement warnings and prints them to the user. |
| 1576 | func wrapTransportWithEntitlementsCheck(rt http.RoundTripper, w io.Writer) http.RoundTripper { |
| 1577 | var once sync.Once |
| 1578 | return roundTripper(func(req *http.Request) (*http.Response, error) { |
| 1579 | res, err := rt.RoundTrip(req) |
| 1580 | if err != nil { |
| 1581 | return res, err |
| 1582 | } |
| 1583 | once.Do(func() { |
| 1584 | for _, warning := range res.Header.Values(codersdk.EntitlementsWarningHeader) { |
| 1585 | _, _ = fmt.Fprintln(w, pretty.Sprint(cliui.DefaultStyles.Warn, warning)) |
| 1586 | } |
| 1587 | }) |
| 1588 | return res, err |
| 1589 | }) |
| 1590 | } |
| 1591 | |
| 1592 | // wrapTransportWithVersionCheck adds a middleware to the HTTP transport |
| 1593 | // that checks the server version and warns about development builds, |