Skip to content

Commit

Permalink
Bump github.com/mailru/easyjson from 0.7.7 to 0.9.0 (#77)
Browse files Browse the repository at this point in the history
Bumps [github.com/mailru/easyjson](https://github.com/mailru/easyjson)
from 0.7.7 to 0.9.0.
<details>
<summary>Release notes</summary>
<p><em>Sourced from <a
href="https://github.com/mailru/easyjson/releases">github.com/mailru/easyjson's
releases</a>.</em></p>
<blockquote>
<h2>v0.9.0</h2>
<p>up go version and bugfixes</p>
<h2>v0.8.0</h2>
<p>stable version before go version bump</p>
</blockquote>
</details>
<details>
<summary>Commits</summary>
<ul>
<li><a
href="https://github.com/mailru/easyjson/commit/5e854fb809ec83ff18eb74554fd5c693e28eaadb"><code>5e854fb</code></a>
Merge pull request <a
href="https://github.com/mailru/easyjson/issues/388">#388</a>
from testwill/string</li>
<li><a
href="https://github.com/mailru/easyjson/commit/78171e8003c8117a9183b1b7260239a615ace8a6"><code>78171e8</code></a>
Merge pull request <a
href="https://github.com/mailru/easyjson/issues/396">#396</a>
from SolidShake/fix-null-map-key</li>
<li><a
href="https://github.com/mailru/easyjson/commit/907f46a3eb29e4817ffd234da48438fb0d3cb5b6"><code>907f46a</code></a>
up go version to 1.20</li>
<li><a
href="https://github.com/mailru/easyjson/commit/0e683d55cb7f288d05824e1f01c7a54041db29d1"><code>0e683d5</code></a>
only default tests</li>
<li><a
href="https://github.com/mailru/easyjson/commit/8ef38d7618660af569e7e673c9c052d31faa94bc"><code>8ef38d7</code></a>
upd test version</li>
<li><a
href="https://github.com/mailru/easyjson/commit/c2f6bad9b578ab0fe911dfd58ae80182d803dadf"><code>c2f6bad</code></a>
Merge pull request <a
href="https://github.com/mailru/easyjson/issues/405">#405</a>
from IakovLeven/patch-1</li>
<li><a
href="https://github.com/mailru/easyjson/commit/d48874ae4a005fe308cf62551e7babf7cee61514"><code>d48874a</code></a>
Merge pull request <a
href="https://github.com/mailru/easyjson/issues/381">#381</a>
from niallnsec/master</li>
<li><a
href="https://github.com/mailru/easyjson/commit/46715aab064260bc137b2ee412802f7dee5a6be0"><code>46715aa</code></a>
Fix Unmarshaler interface description</li>
<li><a
href="https://github.com/mailru/easyjson/commit/32296272946138958f1507179d341a69a878e902"><code>3229627</code></a>
Fix null key in map</li>
<li><a
href="https://github.com/mailru/easyjson/commit/34d2f3ad1a4848da7c1422bce917f14038fcee8b"><code>34d2f3a</code></a>
Only add tags to run command if set</li>
<li>Additional commits viewable in <a
href="https://github.com/mailru/easyjson/compare/v0.7.7...v0.9.0">compare
view</a></li>
</ul>
</details>
<br />


[![Dependabot compatibility
score](https://dependabot-badges.githubapp.com/badges/compatibility_score?dependency-name=github.com/mailru/easyjson&package-manager=go_modules&previous-version=0.7.7&new-version=0.9.0)](https://docs.github.com/en/github/managing-security-vulnerabilities/about-dependabot-security-updates#about-compatibility-scores)

Dependabot will resolve any conflicts with this PR as long as you don't
alter it yourself. You can also trigger a rebase manually by commenting
`@dependabot rebase`.

[//]: # (dependabot-automerge-start)
[//]: # (dependabot-automerge-end)

---

<details>
<summary>Dependabot commands and options</summary>
<br />

You can trigger Dependabot actions by commenting on this PR:
- `@dependabot rebase` will rebase this PR
- `@dependabot recreate` will recreate this PR, overwriting any edits
that have been made to it
- `@dependabot merge` will merge this PR after your CI passes on it
- `@dependabot squash and merge` will squash and merge this PR after
your CI passes on it
- `@dependabot cancel merge` will cancel a previously requested merge
and block automerging
- `@dependabot reopen` will reopen this PR if it is closed
- `@dependabot close` will close this PR and stop Dependabot recreating
it. You can achieve the same result by closing it manually
- `@dependabot show <dependency name> ignore conditions` will show all
of the ignore conditions of the specified dependency
- `@dependabot ignore this major version` will close this PR and stop
Dependabot creating any more for this major version (unless you reopen
the PR or upgrade to it yourself)
- `@dependabot ignore this minor version` will close this PR and stop
Dependabot creating any more for this minor version (unless you reopen
the PR or upgrade to it yourself)
- `@dependabot ignore this dependency` will close this PR and stop
Dependabot creating any more for this dependency (unless you reopen the
PR or upgrade to it yourself)


</details>
  • Loading branch information
MindHunter86 authored Jan 27, 2025
2 parents d03f3c9 + b3c1d23 commit e887549
Show file tree
Hide file tree
Showing 8 changed files with 120 additions and 12 deletions.
6 changes: 3 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ require (
github.com/allegro/bigcache/v3 v3.1.0
github.com/gofiber/fiber/v2 v2.52.5
github.com/gofiber/storage/bbolt/v2 v2.0.0
github.com/jedib0t/go-pretty/v6 v6.6.0
github.com/jedib0t/go-pretty/v6 v6.6.1
github.com/klauspost/compress v1.17.11
github.com/mailru/easyjson v0.7.7
github.com/mailru/easyjson v0.9.0
github.com/oschwald/maxminddb-golang v1.13.1
github.com/redis/go-redis/v9 v9.6.1
github.com/redis/go-redis/v9 v9.7.0
github.com/rs/zerolog v1.33.0
github.com/urfave/cli/v2 v2.27.5
github.com/valyala/bytebufferpool v1.0.0
Expand Down
12 changes: 6 additions & 6 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,14 @@ github.com/gofiber/utils/v2 v2.0.0-beta.3 h1:pfOhUDDVjBJpkWv6C5jaDyYLvpui7zQ97zp
github.com/gofiber/utils/v2 v2.0.0-beta.3/go.mod h1:jsl17+MsKfwJjM3ONCE9Rzji/j8XNbwjhUVTjzgfDCo=
github.com/google/uuid v1.5.0 h1:1p67kYwdtXjb0gL0BPiP1Av9wiZPo5A8z2cWkTZ+eyU=
github.com/google/uuid v1.5.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/jedib0t/go-pretty/v6 v6.6.0 h1:wmZVuAcEkZRT+Aq1xXpE8IGat4vE5WXOMmBpbQqERXw=
github.com/jedib0t/go-pretty/v6 v6.6.0/go.mod h1:zbn98qrYlh95FIhwwsbIip0LYpwSG8SUOScs+v9/t0E=
github.com/jedib0t/go-pretty/v6 v6.6.1 h1:iJ65Xjb680rHcikRj6DSIbzCex2huitmc7bDtxYVWyc=
github.com/jedib0t/go-pretty/v6 v6.6.1/go.mod h1:zbn98qrYlh95FIhwwsbIip0LYpwSG8SUOScs+v9/t0E=
github.com/josharian/intern v1.0.0 h1:vlS4z54oSdjm0bgjRigI+G1HpF+tI+9rE5LLzOg8HmY=
github.com/josharian/intern v1.0.0/go.mod h1:5DoeVV0s6jJacbCEi61lwdGj/aVlrQvzHFFd8Hwg//Y=
github.com/klauspost/compress v1.17.11 h1:In6xLpyWOi1+C7tXUUWv2ot1QvBjxevKAaI6IXrJmUc=
github.com/klauspost/compress v1.17.11/go.mod h1:pMDklpSncoRMuLFrf1W9Ss9KT+0rH90U12bZKk7uwG0=
github.com/mailru/easyjson v0.7.7 h1:UGYAvKxe3sBsEDzO8ZeWOSlIQfWFlxbzLZe7hwFURr0=
github.com/mailru/easyjson v0.7.7/go.mod h1:xzfreul335JAWq5oZzymOObrkdz5UnU4kGfJJLY9Nlc=
github.com/mailru/easyjson v0.9.0 h1:PrnmzHw7262yW8sTBwxi1PdJA3Iw/EKBa8psRf7d9a4=
github.com/mailru/easyjson v0.9.0/go.mod h1:1+xMtQp2MRNVL/V1bOzuP3aP8VNwRW55fQUto+XFtTU=
github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA=
github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg=
github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM=
Expand All @@ -43,8 +43,8 @@ github.com/philhofer/fwd v1.1.2 h1:bnDivRJ1EWPjUIRXV5KfORO897HTbpFAQddBdE8t7Gw=
github.com/philhofer/fwd v1.1.2/go.mod h1:qkPdfjR2SIEbspLqpe1tO4n5yICnr2DY7mqEx2tUTP0=
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/redis/go-redis/v9 v9.6.1 h1:HHDteefn6ZkTtY5fGUE8tj8uy85AHk6zP7CpzIAM0y4=
github.com/redis/go-redis/v9 v9.6.1/go.mod h1:0C0c6ycQsdpVNQpxb1njEQIqkx5UcsM8FJCQLgE9+RA=
github.com/redis/go-redis/v9 v9.7.0 h1:HhLSs+B6O021gwzl+locl0zEDnyNkxMtf/Z3NNBMa9E=
github.com/redis/go-redis/v9 v9.7.0/go.mod h1:f6zhXITC7JUJIlPEiBOTXxJgPLdZcA93GewI7inzyWw=
github.com/rivo/uniseg v0.2.0 h1:S1pD9weZBuJdFmowNwbpi7BJ8TNftyUImj/0WQi72jY=
github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc=
github.com/rs/xid v1.5.0/go.mod h1:trrq9SKmegXys3aeAKXMUTdJsYXVwGY3RLcfgqegfbg=
Expand Down
2 changes: 1 addition & 1 deletion internal/cache/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ func (m *Cache) Write(country, key string, w io.Writer) error {
}

func (m *Cache) setCompressed(zone cacheZone, key string, payload []byte) error {
cmp := s2.Encode(nil, payload)
cmp := s2.EncodeSnappyBetter(nil, payload)

if zerolog.GlobalLevel() <= zerolog.DebugLevel {
m.log.Trace().Msgf("compressed from %d to %d bytes", len(payload), len(cmp))
Expand Down
5 changes: 5 additions & 0 deletions internal/proxy/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (

func (m *Proxy) IsRequestCached(c *fiber.Ctx) (ok bool) {
if m.IsCacheBypass(c) {
c.Response().Header.Set("X-Alice-Cache", "BYPASS")
return true
}

Expand Down Expand Up @@ -37,6 +38,8 @@ func (m *Proxy) HandleProxyToDst(c *fiber.Ctx) (e error) {
}

func (m *Proxy) HandleRandomRelease(c *fiber.Ctx) (e error) {
c.Response().Header.Set("X-Alice-Cache", "FAILED")

if m.randomizer == nil {
return fiber.NewError(fiber.StatusServiceUnavailable, "BUG! randomizer is not initialized")
}
Expand All @@ -47,6 +50,8 @@ func (m *Proxy) HandleRandomRelease(c *fiber.Ctx) (e error) {
"an error occurred in randomizer, maybe it's not ready yet")
}

c.Response().Header.Set("X-Alice-Cache", "HIT")

if bytes.Equal(c.Request().PostArgs().Peek("js"), []byte("1")) {
fmt.Fprintln(c, release)
return respondPlainWithStatus(c, fiber.StatusOK)
Expand Down
4 changes: 4 additions & 0 deletions internal/proxy/key.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,7 @@ func (m *Key) UnsafeString() string {
func (m *Key) Put(key []byte) {
m.key = append(m.key[:0], key...)
}

func (m *Key) UnsafeHeadersKey() string {
return "headers:::" + futils.UnsafeString(m.key)
}
5 changes: 5 additions & 0 deletions internal/proxy/middlewares.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,15 @@ func (m *Proxy) MiddlewareValidation(c *fiber.Ctx) (e error) {
return fiber.NewError(fiber.StatusBadRequest, e.Error())
}

// set ALICE cache status
c.Response().Header.Set("X-Alice-Cache", "MISS")

// hijack all query=random_release queries
if v.IsQueryEqual([]byte("random_release")) {
if m.randomizer != nil {
if release := m.randomizer.Randomize(); release != "" {
if e = utils.RespondWithRandomRelease(release, c); e == nil {
c.Response().Header.Set("X-Alice-Cache", "HIT")
return respondPlainWithStatus(c, fiber.StatusOK)
}
rlog(c).Error().Msg("could not respond on random release query - " + e.Error())
Expand Down
65 changes: 63 additions & 2 deletions internal/proxy/proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package proxy

import (
"context"
"encoding/json"
"errors"
"fmt"

Expand All @@ -13,6 +14,7 @@ import (
futils "github.com/gofiber/fiber/v2/utils"
"github.com/rs/zerolog"
"github.com/urfave/cli/v2"
"github.com/valyala/bytebufferpool"
"github.com/valyala/fasthttp"
)

Expand Down Expand Up @@ -86,6 +88,10 @@ func (*Proxy) IsCacheBypass(c *fiber.Ctx) bool {
return key.Len() == 0
}

//
//
//

func (m *Proxy) acquireRewritedRequest(c *fiber.Ctx) *fasthttp.Request {
req := fasthttp.AcquireRequest()
c.Context().Request.CopyTo(req)
Expand Down Expand Up @@ -120,8 +126,11 @@ func (m *Proxy) doRequest(c *fiber.Ctx, req *fasthttp.Request, rsp *fasthttp.Res
return
}

// copy all response headers (like Set-Cookie and etc)
rsp.Header.CopyTo(&c.Response().Header)
if len(rsp.Header.Peek("Set-Cookie")) != 0 {
key := c.Context().UserValue(utils.UVCacheKey).(*Key)
key.Reset()
c.Response().Header.Set("X-Alice-Cache", "BYPASS")
}

var ok bool
if ok, e = m.unmarshalApiResponse(c, rsp); e != nil {
Expand Down Expand Up @@ -180,10 +189,39 @@ func (m *Proxy) cacheResponse(c *fiber.Ctx, rsp *fasthttp.Response) (e error) {
rlog(c).Trace().Msgf("Key: %s", key.UnsafeString())
}

// cache response body
if e = m.cache.Cache(country, key.UnsafeString(), rsp.Body()); e != nil {
return
}

// get modified headers for further caching V2
headers := utils.AcquireHeaderCache()
defer utils.ReleaseHeaderCache(headers)

rsp.Header.VisitAll(func(k, v []byte) {
if len(c.Response().Header.PeekBytes(k)) != 0 {
return
}

if _, ok := utils.HeadersIgnoreList[futils.UnsafeString(k)]; ok {
return
}

headers[futils.UnsafeString(k)] = v
})

buf := bytebufferpool.Get()
defer bytebufferpool.Put(buf)
defer buf.Reset()

if buf.B, e = json.Marshal(headers); e != nil {
return
}

if e = m.cache.Cache(country, key.UnsafeHeadersKey(), buf.Bytes()); e != nil {
return
}

return
}

Expand All @@ -202,19 +240,42 @@ func (m *Proxy) canRespondFromCache(c *fiber.Ctx) (_ bool, e error) {

var ok bool
if ok, e = m.cache.IsCached(country, key.UnsafeString()); e != nil {
c.Response().Header.Set("X-Alice-Cache", "FAILED")
rlog(c).Warn().Msg("there is problems with cache driver")
return
} else if !ok {
c.Response().Header.Set("X-Alice-Cache", "MISS")
return
}

c.Response().Header.Set("X-Alice-Cache", "HIT")
return true, e
}

func (m *Proxy) respondFromCache(c *fiber.Ctx) (e error) {
key := c.Context().UserValue(utils.UVCacheKey).(*Key)
country := m.countryByRemoteIP(c)

buf := bytebufferpool.Get()
defer bytebufferpool.Put(buf)
defer buf.Reset()

if e = m.cache.Write(country, key.UnsafeHeadersKey(), buf); e != nil {
return
}

headers := utils.AcquireHeaderCache()
defer utils.ReleaseHeaderCache(headers)

if e = json.Unmarshal(buf.B, &headers); e != nil {
return
}

for name, value := range headers {
c.Response().Header.SetBytesKV(futils.UnsafeBytes(name), value)
}

// get body from cache
if e = m.cache.Write(country, key.UnsafeString(), c); e != nil {
return
}
Expand Down
33 changes: 33 additions & 0 deletions internal/utils/headers.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package utils

import "sync"

var HeaderCache = sync.Pool{
New: func() any {
return map[string][]byte{}
},
}

func AcquireHeaderCache() map[string][]byte {
return HeaderCache.Get().(map[string][]byte)
}

func ReleaseHeaderCache(hcache map[string][]byte) {
for key := range hcache {
delete(hcache, key)
}

HeaderCache.Put(hcache)
}

var HeadersIgnoreList = map[string]interface{}{
"X-Accel-Expires": nil,
"Expires": nil,
"Cache-Control": nil,
"Set-Cookie": nil,
"Vary": nil,
"X-Accel-Redirect": nil,
"X-Accel-Limit-Rate": nil,
"X-Accel-Buffering": nil,
"X-Accel-Charset": nil,
}

0 comments on commit e887549

Please sign in to comment.