support lieral

master^2
bel 2022-08-31 20:37:28 -06:00
parent e200f2a6eb
commit 9d3da9265c
2 changed files with 25 additions and 14 deletions

15
main.go
View File

@ -9,6 +9,7 @@ import (
"log"
"math/rand"
"net/http"
"strings"
"time"
"golang.org/x/time/rate"
@ -36,6 +37,17 @@ func main() {
for len(link) == 0 {
link = string(links[rand.Intn(len(links))])
}
if strings.HasPrefix(link, "http") {
serveHTTP(w, r, proxy, link)
} else if strings.HasPrefix(link, "literal://") {
w.Write([]byte(strings.TrimPrefix(link, "literal://") + "\n"))
}
})); err != nil {
panic(err)
}
}
func serveHTTP(w http.ResponseWriter, r *http.Request, proxy bool, link string) {
if proxy {
resp, err := http.Get(link)
if err != nil {
@ -51,7 +63,4 @@ func main() {
} else {
http.Redirect(w, r, link, http.StatusTemporaryRedirect)
}
})); err != nil {
panic(err)
}
}

2
testdata/literal vendored Normal file
View File

@ -0,0 +1,2 @@
literal://hello world
literal://foo bar