Skip to content

Commit

Permalink
router ingest: enable gzip compression
Browse files Browse the repository at this point in the history
  • Loading branch information
absorbb committed Jan 26, 2024
1 parent 669c132 commit fd9a1af
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 11 deletions.
3 changes: 2 additions & 1 deletion go.work.sum
Original file line number Diff line number Diff line change
Expand Up @@ -713,6 +713,8 @@ github.com/alexflint/go-filemutex v1.2.0 h1:1v0TJPDtlhgpW4nJ+GvxCLSlUDC3+gW0CQQv
github.com/alexflint/go-filemutex v1.2.0/go.mod h1:mYyQSWvw9Tx2/H2n9qXPb52tTYfE0pZAWcBq5mK025c=
github.com/andreyvit/diff v0.0.0-20170406064948-c7f18ee00883 h1:bvNMNQO63//z+xNgfBlViaCIJKLlCJ6/fmUseuG0wVQ=
github.com/andreyvit/diff v0.0.0-20170406064948-c7f18ee00883/go.mod h1:rCTlJbsFo29Kk6CurOXKm700vrz8f0KW0JNfpkRJY/8=
github.com/andybalholm/brotli v1.1.0 h1:eLKJA0d02Lf0mVpIDgYnqXcUn0GqVmEFny3VuID1U3M=
github.com/andybalholm/brotli v1.1.0/go.mod h1:sms7XGricyQI9K10gOSf56VKKWS4oLer58Q+mhRPtnY=
github.com/antihax/optional v1.0.0 h1:xK2lYat7ZLaVVcIuj82J8kIro4V6kDe0AUDFboUCwcg=
github.com/antlr/antlr4/runtime/Go/antlr v1.4.10 h1:yL7+Jz0jTC6yykIK/Wh74gnTJnrGr5AyrNMXuA0gves=
github.com/antlr/antlr4/runtime/Go/antlr v1.4.10/go.mod h1:F7bn7fEU90QkQ3tnmaTx3LTKLEDqnwWODIYppRQ5hnY=
Expand Down Expand Up @@ -1138,7 +1140,6 @@ github.com/jackc/pgservicefile v0.0.0-20221227161230-091c0ba34f0a/go.mod h1:5TJZ
github.com/jackc/pgx/v5 v5.3.1/go.mod h1:t3JDKnCBlYIc0ewLF0Q7B8MXmoIaBOZj/ic7iHozM/8=
github.com/jackc/pgx/v5 v5.4.1/go.mod h1:q6iHT8uDNXWiFNOlRqJzBTaSH3+2xCXkokxHZC5qWFY=
github.com/jackc/pgx/v5 v5.4.3/go.mod h1:Ig06C2Vu0t5qXC60W8sqIthScaEnFvojjj9dSljmHRA=
github.com/jackc/pgx/v5 v5.5.1 h1:5I9etrGkLrN+2XPCsi6XLlV5DITbSL/xBZdmAxFcXPI=
github.com/jackc/pgx/v5 v5.5.1/go.mod h1:Ig06C2Vu0t5qXC60W8sqIthScaEnFvojjj9dSljmHRA=
github.com/jackc/puddle/v2 v2.1.2 h1:0f7vaaXINONKTsxYDn4otOAiJanX/BMeAtY//BXqzlg=
github.com/jackc/puddle/v2 v2.2.0/go.mod h1:vriiEXHvEE654aYKXXjOvZM39qJ0q+azkZFrfEOc3H4=
Expand Down
21 changes: 11 additions & 10 deletions ingest/router_ingest_handler.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package main

import (
"compress/gzip"
"encoding/json"
"fmt"
"github.com/gin-gonic/gin"
Expand Down Expand Up @@ -115,16 +116,16 @@ func (r *Router) IngestHandler(c *gin.Context) {
}
resp := r.processSyncDestination(ingestMessage, stream, ingestMessageBytes)
if resp != nil {
//if r.ShouldCompress(c.Request) {
// c.Header("Content-Encoding", "gzip")
// c.Header("Content-Type", "application/json")
// c.Header("Vary", "Accept-Encoding")
// gz := gzip.NewWriter(c.Writer)
// _ = json.NewEncoder(gz).Encode(resp)
// _ = gz.Close()
//} else {
c.JSON(http.StatusOK, resp)
//}
if r.ShouldCompress(c.Request) {
c.Header("Content-Encoding", "gzip")
c.Header("Content-Type", "application/json")
c.Header("Vary", "Accept-Encoding")
gz := gzip.NewWriter(c.Writer)
_ = json.NewEncoder(gz).Encode(resp)
_ = gz.Close()
} else {
c.JSON(http.StatusOK, resp)
}
} else {
c.JSON(http.StatusOK, gin.H{"ok": true})
}
Expand Down

0 comments on commit fd9a1af

Please sign in to comment.