Compare commits

..

No commits in common. "thermokarst_jj_nqtmmyxznqwl" and "main" have entirely different histories.

2 changed files with 4 additions and 21 deletions

View file

@ -5,7 +5,6 @@ a proxy server for github copilot, handling token management and request forward
## requirements
- go 1.20 or later
- a valid github pat set in the `GITHUB_AUTH_TOKEN` environment variable
- (optional) `golangci-lint`
## usage
```bash

24
main.go
View file

@ -35,7 +35,7 @@ type ProxyServer struct {
func NewProxyServer(authToken string) *ProxyServer {
return &ProxyServer{
authToken: authToken,
client: &http.Client{Timeout: 5 * time.Minute},
client: &http.Client{Timeout: 30 * time.Second},
}
}
@ -68,12 +68,7 @@ func (p *ProxyServer) refreshTokenIfNeeded() error {
if err != nil {
return fmt.Errorf("token exchange request failed: %w", err)
}
defer func() {
err := resp.Body.Close()
if err != nil {
log.Fatal(err)
}
}()
defer resp.Body.Close()
if resp.StatusCode != http.StatusOK {
body, _ := io.ReadAll(resp.Body)
@ -110,13 +105,7 @@ func (p *ProxyServer) proxyHandler(w http.ResponseWriter, r *http.Request) {
http.Error(w, "error reading request body", http.StatusBadRequest)
return
}
defer func() {
err := r.Body.Close()
if err != nil {
log.Fatal(err)
}
}()
log.Printf("request: %s", body)
defer r.Body.Close()
targetURL := p.proxyEndpoint + r.URL.Path
if p.proxyEndpoint == "" {
@ -145,12 +134,7 @@ func (p *ProxyServer) proxyHandler(w http.ResponseWriter, r *http.Request) {
http.Error(w, "error forwarding request to copilot", http.StatusBadGateway)
return
}
defer func() {
err := resp.Body.Close()
if err != nil {
log.Fatal(err)
}
}()
defer resp.Body.Close()
for name, values := range resp.Header {
for _, value := range values {