mirror of
https://github.com/lukaszraczylo/graphql-monitoring-proxy.git
synced 2026-06-05 23:03:48 +00:00
fixup! Fix the introduced bug where RO endpoint could've been accidentally used. (#17)
This commit is contained in:
Vendored
+25
@@ -1,6 +1,9 @@
|
|||||||
package libpack_cache
|
package libpack_cache
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bytes"
|
||||||
|
"compress/gzip"
|
||||||
|
"io"
|
||||||
"sync/atomic"
|
"sync/atomic"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@@ -76,6 +79,28 @@ func CacheLookup(hash string) []byte {
|
|||||||
obj, found := config.Client.Get(hash)
|
obj, found := config.Client.Get(hash)
|
||||||
if found {
|
if found {
|
||||||
atomic.AddInt64(&cacheStats.CacheHits, 1)
|
atomic.AddInt64(&cacheStats.CacheHits, 1)
|
||||||
|
// If the cached data is compressed, decompress it
|
||||||
|
if len(obj) > 2 && obj[0] == 0x1f && obj[1] == 0x8b {
|
||||||
|
reader, err := gzip.NewReader(bytes.NewReader(obj))
|
||||||
|
if err != nil {
|
||||||
|
config.Logger.Error(&libpack_logger.LogMessage{
|
||||||
|
Message: "Failed to create gzip reader for cached data",
|
||||||
|
Pairs: map[string]interface{}{"error": err.Error(), "hash": hash},
|
||||||
|
})
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
defer reader.Close()
|
||||||
|
|
||||||
|
decompressed, err := io.ReadAll(reader)
|
||||||
|
if err != nil {
|
||||||
|
config.Logger.Error(&libpack_logger.LogMessage{
|
||||||
|
Message: "Failed to decompress cached data",
|
||||||
|
Pairs: map[string]interface{}{"error": err.Error(), "hash": hash},
|
||||||
|
})
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
return decompressed
|
||||||
|
}
|
||||||
return obj
|
return obj
|
||||||
}
|
}
|
||||||
atomic.AddInt64(&cacheStats.CacheMisses, 1)
|
atomic.AddInt64(&cacheStats.CacheMisses, 1)
|
||||||
|
|||||||
@@ -1,8 +1,11 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bytes"
|
||||||
|
"compress/gzip"
|
||||||
"crypto/tls"
|
"crypto/tls"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"io"
|
||||||
"net/url"
|
"net/url"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@@ -93,6 +96,30 @@ func proxyTheRequest(c *fiber.Ctx, currentEndpoint string) error {
|
|||||||
logDebugResponse(c)
|
logDebugResponse(c)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if c.Response().Header.Peek("Content-Encoding") != nil && string(c.Response().Header.Peek("Content-Encoding")) == "gzip" {
|
||||||
|
reader, err := gzip.NewReader(bytes.NewReader(c.Response().Body()))
|
||||||
|
if err != nil {
|
||||||
|
cfg.Logger.Error(&libpack_logger.LogMessage{
|
||||||
|
Message: "Failed to create gzip reader",
|
||||||
|
Pairs: map[string]interface{}{"error": err.Error()},
|
||||||
|
})
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
defer reader.Close()
|
||||||
|
|
||||||
|
decompressed, err := io.ReadAll(reader)
|
||||||
|
if err != nil {
|
||||||
|
cfg.Logger.Error(&libpack_logger.LogMessage{
|
||||||
|
Message: "Failed to decompress response",
|
||||||
|
Pairs: map[string]interface{}{"error": err.Error()},
|
||||||
|
})
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
c.Response().SetBody(decompressed)
|
||||||
|
c.Response().Header.Del("Content-Encoding")
|
||||||
|
}
|
||||||
|
|
||||||
if c.Response().StatusCode() != 200 {
|
if c.Response().StatusCode() != 200 {
|
||||||
if ifNotInTest() {
|
if ifNotInTest() {
|
||||||
cfg.Monitoring.Increment(libpack_monitoring.MetricsFailed, nil)
|
cfg.Monitoring.Increment(libpack_monitoring.MetricsFailed, nil)
|
||||||
|
|||||||
Reference in New Issue
Block a user