Skip to content

Commit 540d170

Browse files
committed
fix(auth): use HTTP/1.1 to avoid Cloudflare Workers EOF
Go's default HTTP/2 client has compatibility issues with Cloudflare Workers causing EOF errors. Force HTTP/1.1 by disabling TLSNextProto.
1 parent cfd3ea7 commit 540d170

1 file changed

Lines changed: 17 additions & 6 deletions

File tree

internal/auth/login.go

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package auth
22

33
import (
44
"bytes"
5+
"crypto/tls"
56
"encoding/json"
67
"fmt"
78
"net/http"
@@ -12,6 +13,14 @@ import (
1213
"github.com/openbootdotdev/openboot/internal/ui"
1314
)
1415

16+
// httpClient uses HTTP/1.1 to avoid HTTP/2 compatibility issues with Cloudflare Workers
17+
var httpClient = &http.Client{
18+
Transport: &http.Transport{
19+
TLSNextProto: make(map[string]func(authority string, c *tls.Conn) http.RoundTripper),
20+
},
21+
Timeout: 30 * time.Second,
22+
}
23+
1524
const DefaultAPIBase = "https://openboot.dev"
1625

1726
// GetAPIBase returns the API base URL, checking the OPENBOOT_API_URL
@@ -92,11 +101,13 @@ func startAuthSession(apiBase, code string) (string, error) {
92101
return "", fmt.Errorf("failed to marshal start request: %w", err)
93102
}
94103

95-
resp, err := http.Post(
96-
fmt.Sprintf("%s/api/auth/cli/start", apiBase),
97-
"application/json",
98-
bytes.NewReader(body),
99-
)
104+
req, err := http.NewRequest("POST", fmt.Sprintf("%s/api/auth/cli/start", apiBase), bytes.NewReader(body))
105+
if err != nil {
106+
return "", fmt.Errorf("failed to create start request: %w", err)
107+
}
108+
req.Header.Set("Content-Type", "application/json")
109+
110+
resp, err := httpClient.Do(req)
100111
if err != nil {
101112
return "", fmt.Errorf("failed to start auth session: %w", err)
102113
}
@@ -125,7 +136,7 @@ func pollForApproval(apiBase, codeID string) (*cliPollResponse, error) {
125136
case <-timeout:
126137
return nil, fmt.Errorf("authentication timed out after 5 minutes")
127138
case <-ticker.C:
128-
resp, err := http.Get(pollURL)
139+
resp, err := httpClient.Get(pollURL)
129140
if err != nil {
130141
continue
131142
}

0 commit comments

Comments
 (0)