ijpiantanida / talkback

A simple HTTP proxy that records and playbacks requests
MIT License
284 stars 41 forks source link

New cached responses generated for identical request #4

Closed hanshenrik closed 6 years ago

hanshenrik commented 6 years ago

Talkback keeps generating new cached responses after server restart even though the requests are identical. I thought the expected behaviour was that identical requests would cause the cached response to be returned.

screen shot 2018-05-02 at 12 49 38

I'm guessing differences in meta and res shouldn't cause a new cached response to be generated?

ijpiantanida commented 6 years ago

You're right, identical req should match existing tapes. meta and res are not taken into account during the lookup. Looking at the image I don't see any reason why the tape shouldn't match.

If you're willing to test, I published a new version talkback@beta that adds a debug option. Set it to true, and it will print a lot of debug information. For each saved tape, it will print the reason why it doesn't match a new request.

Thank you

roypa commented 6 years ago

I think I found the bug that makes this happen.

The response for this tape is not considered human readable (meta.resHumanReadable=false) because header value for "content-encoding" is gzip. The request is on the other side considered human readable, which is correct.

In the source file tape.js the method static fromStore(raw, options) checks on the var raw.meta.resHumanReadable for both if tests. The first if test is used for the request and has a bug is on line 22, where it should test the raw.meta.reqHumanReadable instead.

ijpiantanida commented 6 years ago

You're totally right @roypa! Thank you so much.

I just released 1.2.0 that fixes this issue.

roypa commented 6 years ago

Great! Thank you so much for such a quick response.

hanshenrik commented 6 years ago

Yes, great stuff! Thanks!