Skip to content

Commit

Permalink
#881 add X-RPCX-CompressType to indicate whether the bodu has been co…
Browse files Browse the repository at this point in the history
…mpressed
  • Loading branch information
smallnest committed Jan 28, 2025
1 parent 90032e5 commit da8106c
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
11 changes: 11 additions & 0 deletions server/converter.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ const (
XOneway = "X-RPCX-Oneway"
XMessageStatusType = "X-RPCX-MessageStatusType"
XSerializeType = "X-RPCX-SerializeType"
XCompressType = "X-RPCX-CompressType"
XMessageID = "X-RPCX-MessageID"
XServicePath = "X-RPCX-ServicePath"
XServiceMethod = "X-RPCX-ServiceMethod"
Expand Down Expand Up @@ -58,6 +59,16 @@ func HTTPRequest2RpcxRequest(r *http.Request) (*protocol.Message, error) {
req.SetSerializeType(protocol.SerializeType(rst))
}

compressType := h.Get(XCompressType)
if compressType != "" {
ct, err := strconv.Atoi(compressType)
if err != nil {
return nil, err
}

req.SetCompressType(protocol.CompressType(ct))
}

meta := h.Get(XMeta)
if meta != "" {
metadata, err := url.ParseQuery(meta)
Expand Down
6 changes: 6 additions & 0 deletions server/gateway.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"bufio"
"context"
"errors"
"fmt"
"io"
"net"
"net/http"
Expand Down Expand Up @@ -273,6 +274,11 @@ func (s *Server) handleGatewayRequest(w http.ResponseWriter, r *http.Request, pa
meta.Add(k, v)
}
wh.Set(XMeta, meta.Encode())

if res.CompressType() != protocol.None {
wh.Set(XCompressType, fmt.Sprintf("%d", res.CompressType()))
}

w.Write(res.Payload)
s.Plugins.DoPostWriteResponse(newCtx, req, res, err)
}

0 comments on commit da8106c

Please sign in to comment.