ijpiantanida / talkback

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

Flag to sort the request body by key names #8

Closed arzmir closed 6 years ago

arzmir commented 6 years ago

Possibly Covered In Issue #7

Your proposal on how to handle partial body matching might also cover this issue. As one could maybe supply a deep match or body sorting function.

Problem

During some readability refactoring I wanted to sort some lines of code alphabetically, but because these were setting values for a request payload, it caused a cache miss in Talkback.

What I assume is the issue here is the payload object is unsorted when stringified. Which probably is in everyones interest for most situations in a performance perspective. But here it causes a cache miss for equal data with different ordering.

Working around the issue is no worse than rebuilding the Talkback request-response pair, but it may be tedious for bigger rounds of refactoring.

Proposal

A configuration flag for choosing to sort the body by key names. Opting for a flag as It will undoubtedly be a performance hit.

Flag Name Value Description Default
sortRequestBody Boolean Whether or not to sort the request body before building a cache. This removes the need for specific ordering in request payloads. false
ijpiantanida commented 6 years ago

Hi @arzmir. As you mentioned, for now I'd cover this scenario with my proposal of leaving this to the user by providing a custom bodymatcher function (should be out soon).

I'm trying to avoid having to parse the body contents, if possible.

Thank you for the idea though!

ijpiantanida commented 6 years ago

@arzmir I just release v1.5.0, which adds the bodyMatcher option. There's an example on how to use it in the README.

Hope it helps!

arzmir commented 6 years ago

Wonderful. Will take it for a test run soon.