From f441bf18ee18ab1ad54de868f736f87727683e0a Mon Sep 17 00:00:00 2001 From: Sergey Matveev Date: Mon, 6 Sep 2021 21:00:05 +0300 Subject: [PATCH] =?utf8?q?=D0=A5=D0=B0=D0=B1=D1=80's=20full=20size=20image?= =?utf8?q?s?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- doc/index.texi | 3 +++ main.go | 16 +++++++++++----- 2 files changed, 14 insertions(+), 5 deletions(-) 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, ))) -- 2.44.0