Skip to content

Commit

Permalink
Merge pull request #86 from singchia/fix/hijack_panic
Browse files Browse the repository at this point in the history
fix: hijack panic while pattern not set
  • Loading branch information
singchia authored Feb 25, 2024
2 parents 3842313 + 57d2d8a commit 0cb6819
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
4 changes: 3 additions & 1 deletion application/rpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,9 @@ func (sm *stream) CallAsync(ctx context.Context, method string, req geminio.Requ
}

func (sm *stream) Hijack(rpc geminio.HijackRPC, opts ...*options.HijackOptions) error {
pRPC := &patternRPC{}
pRPC := &patternRPC{
match: true,
}
fo := options.MergeHijackOptions(opts...)
if fo.Pattern != nil {
reg, err := regexp.Compile(*fo.Pattern)
Expand Down
4 changes: 4 additions & 0 deletions application/stream.go
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,10 @@ func (sm *stream) handleInRequestPacket(pkt *packet.RequestPacket) iodefine.IORe
}
// hijack exist
if sm.hijackRPC != nil {
if sm.hijackRPC.pattern == nil {
sm.doRPC(pkt, methodRPC(sm.hijackRPC.rpc), method, ctx, req, rsp, true)
return iodefine.IOSuccess
}
matched := sm.hijackRPC.pattern.Match([]byte(method))
if (sm.hijackRPC.match && matched) || (!sm.hijackRPC.match && !matched) {
// do RPC and cancel the context
Expand Down

0 comments on commit 0cb6819

Please sign in to comment.