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.

Home Page:https://goreplay.org

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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

fsyj-123 opened this issue · comments

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

the code of middleware is modeled after token_modifier.go

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
})