robotframework-requests icon indicating copy to clipboard operation
robotframework-requests copied to clipboard

Check body size from headers before logging

Open jyurdal opened this issue 3 years ago • 4 comments

passing large response.text to function and calculating len() of it takes a lot of time (and CPU) when a application/zip is returned. This results in test timeouts and hence failures

jyurdal avatar May 11 '21 14:05 jyurdal

Interesting the approach of looking at headers for the length. By the way I don't think your implementation is clean enough to be merged and if the size is higher than limit no message of body truncated will be shown.

lucagiove avatar May 11 '21 15:05 lucagiove

I think the fact that the logging of data (that is not necessarily desired) uses one 100% of one CPU core for a time way longer then the test itself is an issue. My first idea was to add boolean parameter log_body to get_on_session and post_on_session ( with default set to True). User could disable logging of the body for video, audio, application/zip and/or other binary files. Would that be acceptable solution for you @lucagiove ?

jyurdal avatar May 11 '21 16:05 jyurdal

No it's not acceptable as well but I'll think about it, maybe logging could be disabled by a global library property definitely not for each keyword. I'll think about it but maybe looking at the size is feasible only in a different way.

lucagiove avatar May 11 '21 16:05 lucagiove

That would be great if that was resolved. I have experienced that any processing on response.text takes a long time, including passing it to a function (In our case it response.text was 7M of size). Maybe that can be somehow optimized?

I still think that per function parameter with a default would work well. In our case vast majority of the POST/GET are application/json and disabling the logging would be required on just few API non json calls. I image when developers write test cases they would have the knowledge on which API calls should be fully logged.

One more option would be logging text body only (predefined values of the 'Content-Type') unless logging level is greater then 10. Thanks for your time @lucagiove :-)

jyurdal avatar May 11 '21 17:05 jyurdal