Skip to content

Instantly share code, notes, and snippets.

@phanirithvij
Created May 9, 2025 11:45
Show Gist options
  • Save phanirithvij/b518f3e2738a5ea0e727bef864cd8d9e to your computer and use it in GitHub Desktop.
Save phanirithvij/b518f3e2738a5ea0e727bef864cd8d9e to your computer and use it in GitHub Desktop.
seedr.cc webseed proxy
package main
import (
"fmt"
"io"
"log"
"net/http"
"net/url"
)
// It can be improved by using some seedr.cc API
// but it is generic enough for now
// generated by claude.ai initially, hand modified
const (
folder = "some-folder-name"
file1URL = "some-hard-coded-url"
)
func getProxyUrlForURL(u *url.URL) string {
fmt.Println(u.String())
switch u.String() {
case "/" + folder + "/file1.ext":
return file1URL
}
return ""
}
func main() {
proxyHandler := func(w http.ResponseWriter, r *http.Request) {
// Create the proxy request
proxyURL := getProxyUrlForURL(r.URL)
req, err := http.NewRequest(r.Method, proxyURL, r.Body)
if err != nil {
http.Error(w, "Bad request", http.StatusBadRequest)
return
}
// Copy headers
req.Header = r.Header.Clone()
// Send the request
resp, err := http.DefaultClient.Do(req)
if err != nil {
http.Error(w, "Failed to reach upstream server", http.StatusBadGateway)
return
}
defer resp.Body.Close()
// Copy the response headers and body
for k, v := range resp.Header {
for _, vv := range v {
w.Header().Add(k, vv)
}
}
w.WriteHeader(resp.StatusCode)
io.Copy(w, resp.Body)
}
http.HandleFunc("/", proxyHandler)
log.Println("Proxy server listening on http://localhost:3832")
log.Fatal(http.ListenAndServe(":3832", nil))
}
@phanirithvij
Copy link
Author

phanirithvij commented May 9, 2025

go run main.go

add http://localhost:3832/ in http sources/webseeds section, re-run with updated filenames. re-add url to webseeds section

LICENSE: WTFPL

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment