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.59k stars 17 forks source link

can i recive payload in order of 1、2、3 in middleware #1177

Open fsyj-123 opened 1 year ago

fsyj-123 commented 1 year ago

i am developing a middleware, how can i recive payload in order of 1、2、3 image The above image shows that the order I received is 1, 3, and 2,but i want in order of 1、2、3 below is my command to replay request ./gor --input-file requests_0.gor --input-raw-track-response --middleware "./apps/main" --output-http "http://localhost:85" --output-http-track-response

fsyj-123 commented 1 year ago

the code of middleware is modeled after token_modifier.go

buger commented 1 year ago

Overall it is asyncronious flow, where a lot of goroutines are involved, so hard to guarantee the order. But you can get inspiration on how JS middleware solves it https://github.com/buger/goreplay/tree/master/middleware

// Example of very basic way to compare if replayed traffic have no errors
gor.on("request", function(req) {
    gor.on("response", req.ID, function(resp) {
        gor.on("replay", req.ID, function(repl) {
            if (gor.httpStatus(resp.http) != gor.httpStatus(repl.http)) {
                // Note that STDERR is used for logging, and it actually will be send to `Gor` STDOUT.
                // This trick is used because SDTIN and STDOUT already used for process communication.
                // You can write logger that writes to files insead.
                console.error(`${gor.httpPath(req.http)} STATUS NOT MATCH: 'Expected ${gor.httpStatus(resp.http)}' got '${gor.httpStatus(repl.http)}'`)
            }
            return repl;
        })
        return resp;
    })
    return req
})