vfaronov/httpolice

Best way to integrate with a Node.js stack, "on demand"

fabm22 opened this issue · 3 comments

This is a great project!! Just a quick question.

What are your advice in integrating a linting process of HTTP traffic (with a nodejs stack) ?? Is this a bad idea to always have it running, while developiing ??
If not a bad idea, would simply using "mitmproxy" running constantly the best way to go ?

Thanks for feedback.

This is a big open question for me. I would love to hear from users like you, to know your experience: what works for you, what doesn’t. And then I can work on improving it.

Please note that (1) I am not familiar with Node.js; (2) different people will want different things, depending on their project etc.

Here’s what you can try right now:

  1. Run mitmproxy all the time — this should work, but will be inconvenient. You will have to periodically stop mitmproxy, review the report, and start it again.
  2. Make something like the Django middleware, but for Node.js. For example:
    • dump every request+response into a HAR file (you don’t have to implement the entire HAR spec; here’s a minimal example that is enough for HTTPolice: test/har_data/simple_ok.har);
    • run HTTPolice on this HAR file, producing a text report;
    • check this report for lines starting with “E” (errors) or “C” (comments);
    • if any such lines were found, interrupt the workflow, throw an exception, display the report (maybe create an HTML report), etc.

Here’s what I can do for you in a future release:

  1. A JSON output format (-o json). If you want this, please tell me what information you would like to see in this JSON.
  2. A way to detect errors without parsing the report (via the exit status) — so, for example, you can produce an HTML report and then immediately know if there is anything interesting in that report. This is already in master.
  3. A better mitmproxy integration. Maybe regenerate the report on every request+response instead of waiting until shutdown?
  4. A JSON input format (-i json) that is easier to use and more flexible than HAR.
  5. (your idea here)

Thanks a lot for your feedback and solid answer.
The right now part is kinda what I thought first. This is great start to try and thanks for the details concerning a node.js impl.

And for the second part, I feel HTTPolice fills a gap so having more formats processed and arguably a more used format like JSON can only be a great thing. I'll let you know here if I have more feedback and experience during use.

In the meantime, running HTTPolice as one time process, in some integration tests run phase or not, is already a great tool to improve and detect potential errors in our REST world !

A better mitmproxy integration. Maybe regenerate the report on every request+response instead of waiting until shutdown?

FWIW, this is now featured in mitmproxy-HTTPolice 0.6.0, along with a couple other improvements for interactive use.