mirror of
https://github.com/aljazceru/njump.git
synced 2025-12-17 06:14:22 +01:00
32 lines
636 B
Go
32 lines
636 B
Go
package main
|
|
|
|
import (
|
|
"net/http"
|
|
"net/http/httputil"
|
|
"net/url"
|
|
)
|
|
|
|
func proxy(w http.ResponseWriter, r *http.Request) {
|
|
w.Header().Set("Cache-Control", "max-age=604800")
|
|
|
|
src := r.URL.Query().Get("src")
|
|
urlParsed, err := url.Parse(src)
|
|
if err != nil {
|
|
http.Error(w, "Invalid URL", http.StatusBadRequest)
|
|
return
|
|
}
|
|
if urlParsed.Scheme != "http" && urlParsed.Scheme != "https" {
|
|
http.Error(w, "The URL scheme is neither HTTP nor HTTPS", http.StatusBadRequest)
|
|
return
|
|
}
|
|
|
|
proxy := httputil.ReverseProxy{
|
|
Director: func(r *http.Request) {
|
|
r.URL = urlParsed
|
|
r.Host = urlParsed.Host
|
|
},
|
|
}
|
|
|
|
proxy.ServeHTTP(w, r)
|
|
}
|