Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 0 additions & 29 deletions internal/http/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import (
"html/template"
"io"
"net/http"
"os"
"runtime"
"strconv"
"strings"
Expand Down Expand Up @@ -264,28 +263,14 @@ func UploadPackDiscoveryHandler(c *gin.Context) {
owner := c.Param("owner")
repo := c.Param("repo")

token := os.Getenv("GITHUB_TOKEN")
if token == "" {
c.AbortWithStatusJSON(http.StatusInternalServerError, gin.H{"error": "GITHUB_TOKEN not set"})
return
}

githubURL := fmt.Sprintf("https://github.com/%s/%s.git/info/refs?service=git-upload-pack", owner, repo)
req, err := http.NewRequest("GET", githubURL, nil)
if err != nil {
c.AbortWithStatusJSON(http.StatusInternalServerError, gin.H{"error": "failed to build request"})
return
}
req.Header.Set("Authorization", "Basic "+basicAuth("x-access-token", token))
req.Header.Set("User-Agent", "git/2.0")

// Si Git llega sin Authorization, responder 401 para que negocie credenciales.
if c.GetHeader("Authorization") == "" {
c.Writer.Header().Set("WWW-Authenticate", `Basic realm="gitgost"`)
c.Writer.WriteHeader(http.StatusUnauthorized)
return
}

resp, err := uploadPackClient.Do(req)
if err != nil {
utils.Log("UploadPackDiscovery error: %v", err)
Expand All @@ -306,12 +291,6 @@ func UploadPackHandler(c *gin.Context) {
owner := c.Param("owner")
repo := c.Param("repo")

token := os.Getenv("GITHUB_TOKEN")
if token == "" {
c.AbortWithStatusJSON(http.StatusInternalServerError, gin.H{"error": "GITHUB_TOKEN not set"})
return
}

const maxUploadBytes = 50 * 1024 * 1024 // 50 MB
c.Request.Body = http.MaxBytesReader(c.Writer, c.Request.Body, maxUploadBytes)
body, err := io.ReadAll(c.Request.Body)
Expand All @@ -330,7 +309,6 @@ func UploadPackHandler(c *gin.Context) {
c.AbortWithStatusJSON(http.StatusInternalServerError, gin.H{"error": "failed to build request"})
return
}
req.Header.Set("Authorization", "Basic "+basicAuth("x-access-token", token))
req.Header.Set("Content-Type", "application/x-git-upload-pack-request")
req.Header.Set("User-Agent", "git/2.0")

Expand All @@ -342,13 +320,6 @@ func UploadPackHandler(c *gin.Context) {
}
defer resp.Body.Close()

// Si Git llega sin Authorization, responder 401 para que negocie credenciales.
if c.GetHeader("Authorization") == "" {
c.Writer.Header().Set("WWW-Authenticate", `Basic realm="gitgost"`)
c.Writer.WriteHeader(http.StatusUnauthorized)
return
}

c.Writer.Header().Set("Content-Type", "application/x-git-upload-pack-result")
c.Writer.WriteHeader(resp.StatusCode)
if _, err := io.Copy(c.Writer, resp.Body); err != nil {
Expand Down
1 change: 0 additions & 1 deletion web/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -981,7 +981,6 @@ <h1>gitGost</h1>
<span class="success">→</span> Anonymized commit + PR opened as @gitgost-anonymous</div>
</div>
<div class="terminal" id="terminal-fetch" style="display:none;"><div class="terminal-titlebar"><span class="terminal-btn close"></span><span class="terminal-btn min"></span><span class="terminal-btn max"></span></div><div class="terminal-body"><span class="comment"># Clone or fetch anonymously — no GitHub account needed.</span>
<span class="comment"># Use anon: prefix to skip credential prompt</span>
<span class="prompt">$</span> git clone https://anon:@gitgost.leapcell.app/v1/gh/torvalds/linux
<span class="comment"># Or add as remote and fetch/pull later</span>
<span class="prompt">$</span> git remote add gost https://anon:@gitgost.leapcell.app/v1/gh/torvalds/linux
Expand Down