optional proxy
parent
6698e8100a
commit
36c5577c83
|
|
@ -0,0 +1,3 @@
|
|||
exec-random-redirect
|
||||
random-redirect
|
||||
**/*.sw*
|
||||
19
main.go
19
main.go
|
|
@ -4,6 +4,7 @@ import (
|
|||
"bytes"
|
||||
"flag"
|
||||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"log"
|
||||
"math/rand"
|
||||
|
|
@ -15,8 +16,10 @@ import (
|
|||
func main() {
|
||||
var port int
|
||||
var conf string
|
||||
var proxy bool
|
||||
flag.IntVar(&port, "p", 8080, "port to listen on")
|
||||
flag.StringVar(&conf, "c", "/dev/null", "line delimited file to read urls from")
|
||||
flag.BoolVar(&proxy, "proxy", false, "proxy content rather than redirect, so refresh works")
|
||||
flag.Parse()
|
||||
b, err := ioutil.ReadFile(conf)
|
||||
if err != nil {
|
||||
|
|
@ -31,7 +34,21 @@ func main() {
|
|||
for len(link) == 0 {
|
||||
link = string(links[rand.Intn(len(links))])
|
||||
}
|
||||
http.Redirect(w, r, link, http.StatusTemporaryRedirect)
|
||||
if proxy {
|
||||
resp, err := http.Get(link)
|
||||
if err != nil {
|
||||
http.Error(w, err.Error(), http.StatusBadGateway)
|
||||
}
|
||||
for k, v := range resp.Header {
|
||||
for _, v2 := range v {
|
||||
w.Header().Add(k, v2)
|
||||
}
|
||||
}
|
||||
w.WriteHeader(resp.StatusCode)
|
||||
io.Copy(w, resp.Body)
|
||||
} else {
|
||||
http.Redirect(w, r, link, http.StatusTemporaryRedirect)
|
||||
}
|
||||
})); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue