]> Sergey Matveev's repositories - tofuproxy.git/commitdiff
Хабр's full size images
authorSergey Matveev <stargrave@stargrave.org>
Mon, 6 Sep 2021 18:00:05 +0000 (21:00 +0300)
committerSergey Matveev <stargrave@stargrave.org>
Mon, 6 Sep 2021 18:43:32 +0000 (21:43 +0300)
doc/index.texi
main.go

index a860f633086eb1f7e23096661b8ccd6f10564312..353d2d514c42305dac5c7381fd24c00f0cb3fc36 100644 (file)
@@ -66,6 +66,9 @@ creating some kind of complex configuration framework.
 
 @item @code{www.reddit.com} is redirected to @code{old.reddit.com}.
 
+@item @url{https://habr.com/ru/all/, Хабр}'s resolution reduced images
+    are redirected to their full size variants.
+
 @item Various spying domains (advertisement, tracking counters) are
     responded with 404 error.
 
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,
                        )))