buger / goreplay

GoReplay is an open-source tool for capturing and replaying live HTTP traffic into a test environment in order to continuously test your system with real data. It can be used to increase confidence in code deployments, configuration changes and infrastructure changes.
https://goreplay.org
Other
18.53k stars 13 forks source link

Rewrite multi header can't work? #1118

Open HeartIsBeat opened 2 years ago

HeartIsBeat commented 2 years ago

I use gor1.3.3 wget https://github.com/buger/goreplay/releases/download/1.3.3/gor_1.3.3_x64.tar.gz

gor record traffic like this: image or like this: image

I want to rewrite header: authorization and authorization-virtual. using --http-rewrite-header 'authorization: XDS [a-zA-Z0-9.-_/+/-]+,xxx' --http-rewrite-header 'authorization-virtual: VDS [a-zA-Z0-9.-_/+/-]+,VDS xxx'

authorization can be rewrited. But authorization-virtual can't be rewrited

zoulinz commented 2 years ago

There is a bug here.

    if len(m.config.HeaderRewrite) > 0 {
            for _, f := range m.config.HeaderRewrite {
                    value := proto.Header(payload, f.header)
                    if len(value) == 0 {
                            break    <<<<<<<<<< if header "authorization" is not found, it will not try the left "authorization-virtual"
                    }

                    if f.src.Match(value) {
                            newValue := f.src.ReplaceAll(value, f.target)
                            payload = proto.SetHeader(payload, f.header, newValue)
                    }
            }
    }

I will submit a fix for this.