]> Sergey Matveev's repositories - tofuproxy.git/blobdiff - main.go
Хабр's full size images
[tofuproxy.git] / main.go
diff --git a/main.go b/main.go
index a4b8a32d8516dccf757fb1f30a027893381f2f37..7fd892cd76244e889862fbbdef397fa8d7e80bcf 100644 (file)
--- a/main.go
+++ b/main.go
@@ -135,12 +135,20 @@ func roundTrip(w http.ResponseWriter, req *http.Request) {
                }
        }
 
-       if strings.HasPrefix(req.URL.Host, "www.reddit.com") {
+       if host == "www.reddit.com" {
                req.URL.Host = "old.reddit.com"
                http.Redirect(w, req, req.URL.String(), http.StatusMovedPermanently)
                return
        }
 
+       if host == "habrastorage.org" &&
+               strings.Contains(req.URL.Path, "/webt/") &&
+               !strings.HasPrefix(req.URL.Path, "/webt/") {
+               req.URL.Path = req.URL.Path[strings.Index(req.URL.Path, "/webt/"):]
+               http.Redirect(w, req, req.URL.String(), http.StatusFound)
+               return
+       }
+
        resp, err := transport.RoundTrip(req)
        if err != nil {
                sinkErr <- fmt.Sprintf("%s\t%s", req.URL.Host, err.Error())
@@ -269,10 +277,8 @@ func roundTrip(w http.ResponseWriter, req *http.Request) {
                location := resp.Header.Get("Location")
                w.Write([]byte(
                        fmt.Sprintf(
-                               `<html>
-<head><title>%d %s: %s redirection</title></head>
-<body>Redirection to <a href="%s">%s</a>
-</body></html>`,
+                               `<html><head><title>%d %s: %s redirection</title></head>
+<body>Redirection to <a href="%s">%s</a></body></html>`,
                                resp.StatusCode, http.StatusText(resp.StatusCode),
                                redirType, location, location,
                        )))