From: Sergey Matveev Date: Mon, 6 Sep 2021 18:00:05 +0000 (+0300) Subject: Хабр's full size images X-Git-Tag: v0.1.0~85 X-Git-Url: http://www.git.stargrave.org/?p=tofuproxy.git;a=commitdiff_plain;h=f441bf18ee18ab1ad54de868f736f87727683e0a Хабр's full size images --- diff --git a/doc/index.texi b/doc/index.texi index a860f63..353d2d5 100644 --- a/doc/index.texi +++ b/doc/index.texi @@ -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 a4b8a32..7fd892c 100644 --- 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( - ` -%d %s: %s redirection -Redirection to %s -`, + `%d %s: %s redirection +Redirection to %s`, resp.StatusCode, http.StatusText(resp.StatusCode), redirType, location, location, )))