wkeeling / selenium-wire

Extends Selenium's Python bindings to give you the ability to inspect requests made by the browser.
MIT License
1.9k stars 251 forks source link

HAR content size is not compliant to the spec #686

Open Lesterpig opened 1 year ago

Lesterpig commented 1 year ago

Hello, I believe there is a difference between the HAR specification and selenium-wire's implementation.

Spec: http://www.softwareishard.com/blog/har-12-spec/#content

size [number] - Length of the returned content in bytes. Should be equal to response.bodySize if there is no compression and bigger when the content has been compressed.
compression [number, optional] - Number of bytes saved. Leave out this field if the information is not available.

Implementation: https://github.com/wkeeling/selenium-wire/blob/master/seleniumwire/har.py#L87

            "content": {
                "size": response_body_size, # Compressed size
                "compression": response_body_compression, # Difference between decoded and compressed size
                "mimeType": flow.response.headers.get('Content-Type', ''),
            },
            "redirectURL": flow.response.headers.get('Location', ''),
            "headersSize": len(str(flow.response.headers)),
            "bodySize": response_body_size, # Compressed size

My understanding is that size should actually be equal to response_body_decoded_size, and be different from bodySize. Am I right? If yes, let me know and I will propose a short pull request.