alufers / mitmproxy2swagger

Automagically reverse-engineer REST APIs via capturing traffic
5.05k stars 217 forks source link

Parsing HAR does not always show the correct status code (200 instead of 4xx) #176

Open android-t709 opened 1 month ago

android-t709 commented 1 month ago

I'm using mitmproxy2swagger 0.13.0 to parse .har files generated by HTTP toolkit. I noticed that all the API endpoints showed 200 OK in the examples. This seems to be because the code tries to parse the response as json (or msgpack) https://github.com/alufers/mitmproxy2swagger/blob/d9abbb5a8dc6c72920cec4b8e37214e62a4ae97c/mitmproxy2swagger/mitmproxy2swagger.py#L291-L293

get_response_body is often https://github.com/alufers/mitmproxy2swagger/blob/d9abbb5a8dc6c72920cec4b8e37214e62a4ae97c/mitmproxy2swagger/har_capture_reader.py#L104

I tested this also with chrome, to get 404/400 codes in a .har. Anyway, when the response body isn't json, the default response code of 200 is given. This happened a few times on 400 Bad Request on an API I was testing. I'm not sure if this works differently with mitmproxy vs chrome, and this certainly isn't a priority for me. I just thought it was worth noting because it tripped me up a little.