hoverfly
hoverfly copied to clipboard
chore(hoverfly): add form processing for requests
Adds support for form processing in Hoverfly.
I recently encountered a case where I needed to parse form data for one of the virtual APIs. This became painful and required me to introduce a middleware.
Using the ParseForm
of GO we can easily extend the request details with this logic.
⚠️ This is a draft, possibly there are other places we could add functionality (e.g. matchers?) ⚠️
To be added:
- Tests
- Extend request matchers (?)
@petkostas I have fixed the tests already, you can try to rebase on the latest master.
Because form present in the request body, I think we should just create a new form matcher for the body like this:
"body": [
{
"matcher": "form",
"value": {
"foo": [
{
"value": "bar",
"matcher": "exact"
}
],
"low": [
{
"value": "bar",
"matcher": "exact"
}
]
}
}
],
what do you think?
related to https://github.com/SpectoLabs/hoverfly/issues/903
@tommysitu I agree with the matcher (that is also why I included it with a ? in the initial post), would help a lot and avoid unnecessary middleware's for this kind of scenarios. Rebasing and will try to get the matcher in today as well.
@tommysitu Haven't abandoned this, I will most probably revisit this next week in order to push the changes.
@tommysitu picked this up again, will modify the matcher to the proposal (I initially performed a separate one, but your suggestion makes more sense).
@tommysitu I have the first draft, though as I am still fresh with GO would be best if you can check and recommend maybe a different way, I had a horrible time (and a lovely GO enlightening experience for a Python developer) finding a proper way to transform the nested Matchers.
Found a small issue with the caching (as it does not include the form data) will make a change to that accordingly as well
@petkostas Seems like a simple elegant solution, all existing tests passed 👍 I will poke around a bit more, hopefully nothing break. I will let you know.
TODO:
- [x] Fix capture mode
- [x] Add form data to concatenate
- [x] Update documentation