From a886adcc3458ec421b0f8b0268e8d28c602152c1 Mon Sep 17 00:00:00 2001 From: Igor Chubin Date: Mon, 16 Oct 2023 08:29:25 +0200 Subject: [PATCH] Disable PNG queries --- Makefile | 1 + go.mod | 1 + go.sum | 8 ++++++++ srv.go | 16 ++++++++++++++-- 4 files changed, 24 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index 2d7a03f..cbecb05 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,6 @@ srv: srv.go internal/*/*.go internal/*/*/*.go go build -o srv -ldflags '-w -linkmode external -extldflags "-static"' ./ + #go build -o srv ./ go-test: go test ./... diff --git a/go.mod b/go.mod index 0626030..32a5da1 100644 --- a/go.mod +++ b/go.mod @@ -8,6 +8,7 @@ require ( github.com/go-sql-driver/mysql v1.5.0 // indirect github.com/gopherjs/gopherjs v0.0.0-20200217142428-fce0ec30dd00 // indirect github.com/hashicorp/golang-lru v0.6.0 + github.com/itchyny/gojq v0.12.11 // indirect github.com/klauspost/lctime v0.1.0 // indirect github.com/lib/pq v1.8.0 // indirect github.com/mattn/go-colorable v0.1.13 // indirect diff --git a/go.sum b/go.sum index 422eb44..90a0e04 100644 --- a/go.sum +++ b/go.sum @@ -8,11 +8,16 @@ github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSs github.com/denisenkom/go-mssqldb v0.0.0-20200910202707-1e08a3fab204/go.mod h1:xbL0rPBG9cCiLr28tMa8zpbdarY27NDyej4t/EjAShU= github.com/go-sql-driver/mysql v1.5.0/go.mod h1:DCzpHaOWr8IXmIStZouvnhqoel9Qv2LBy8hT2VhHyBg= github.com/golang-sql/civil v0.0.0-20190719163853-cb61b32ac6fe/go.mod h1:8vg3r2VgvsThLBIFL93Qb5yWzgyZWhEmBwUJWevAkK0= +github.com/google/go-cmp v0.5.4/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY= github.com/gopherjs/gopherjs v0.0.0-20200217142428-fce0ec30dd00/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY= github.com/hashicorp/golang-lru v0.6.0 h1:uL2shRDx7RTrOrTCUZEGP/wJUFiUI8QT6E7z5o8jga4= github.com/hashicorp/golang-lru v0.6.0/go.mod h1:iADmTwqILo4mZ8BN3D2Q6+9jd8WM5uGBxy+E8yxSoD4= github.com/hexops/gotextdiff v1.0.3/go.mod h1:pSWU5MAI3yDq+fZBTazCSJysOMbxWL1BSow5/V2vxeg= +github.com/itchyny/gojq v0.12.11 h1:YhLueoHhHiN4mkfM+3AyJV6EPcCxKZsOnYf+aVSwaQw= +github.com/itchyny/gojq v0.12.11/go.mod h1:o3FT8Gkbg/geT4pLI0tF3hvip5F3Y/uskjRz9OYa38g= +github.com/itchyny/timefmt-go v0.1.5 h1:G0INE2la8S6ru/ZI5JecgyzbbJNs5lG1RcBqa7Jm6GE= +github.com/itchyny/timefmt-go v0.1.5/go.mod h1:nEP7L+2YmAbT2kZ2HfSs1d8Xtw9LY8D2stDBckWakZ8= github.com/jtolds/gls v4.20.0+incompatible/go.mod h1:QJZ7F/aHp+rZTRtaJ1ow/lLfFfVYBRgL+9YlvaHOwJU= github.com/klauspost/lctime v0.1.0 h1:nINsuFc860M9cyYhT6vfg6U1USh7kiVBj/s/2b04U70= github.com/klauspost/lctime v0.1.0/go.mod h1:OwdMhr8tbQvusAsnilqkkgDQqivWlqyg0w5cfXkLiDk= @@ -64,8 +69,11 @@ golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8 h1:0A+M6Uqn+Eje4kHMK80dtF3JC golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab h1:2QkjZIsXupsJbJIdSjjUOgWK3aEtzyuh2mPt3l/CkeU= golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.2.0 h1:ljd4t30dBnAvMZaQCevtY0xLLD0A+bRZXbgLMLU1F/A= +golang.org/x/sys v0.2.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/tools v0.0.0-20190328211700-ab21143f2384/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= +golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= diff --git a/srv.go b/srv.go index 92754e5..a4defe2 100644 --- a/srv.go +++ b/srv.go @@ -6,6 +6,7 @@ import ( "io" stdlog "log" "net/http" + "strings" "time" "github.com/alecthomas/kong" @@ -17,7 +18,7 @@ import ( "github.com/chubin/wttr.in/internal/logging" "github.com/chubin/wttr.in/internal/processor" "github.com/chubin/wttr.in/internal/types" - v1 "github.com/chubin/wttr.in/internal/view/v1" + // v1 "github.com/chubin/wttr.in/internal/view/v1" ) //nolint:gochecknoglobals @@ -31,7 +32,7 @@ var cli struct { GeoResolve string `name:"geo-resolve" help:"Resolve location"` LogLevel string `name:"log-level" short:"l" help:"Show log messages with level" default:"info"` - V1 v1.Configuration + // V1 v1.Configuration } const logLineStart = "LOG_LINE_START " @@ -155,6 +156,12 @@ func mainHandler( log.Println(err) } + if checkURLForPNG(r) { + w.Write([]byte("PNG support temporary disabled")) + + return + } + response, err := rp.ProcessRequest(r) if err != nil { log.Println(err) @@ -252,3 +259,8 @@ func setLogLevel(logLevel string) error { return nil } + +func checkURLForPNG(r *http.Request) bool { + url := r.URL.String() + return strings.Contains(url, ".png") +}