Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
fsyj-123 opened this issue May 11, 2023 · 2 comments
Open

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

fsyj-123 opened this issue May 11, 2023 · 2 comments

Comments

@fsyj-123
Copy link

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
Copy link
Author

the code of middleware is modeled after token_modifier.go

@buger
Copy link
Owner

buger commented May 13, 2023

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants