Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ability to export as HAR File #114

Merged
merged 7 commits into from
Sep 3, 2020

Conversation

latacora-tomekr
Copy link
Contributor

@latacora-tomekr latacora-tomekr commented Aug 13, 2020

This PR adds the export feautre of #101 according to the HAR file spec.

efbe707 Creates a HARExporter and serializer that gets added to the current list of exporters.
3895efb and e85db02 are required additions to support the new fields of the HAR file.
85a3f4a The auto formatter in VS Code ran on a few files

The HARSerializer's write function is one large function which for the most part maps LogEntry fields to the HAR file format's JSON fields. As a result, this function is pretty big. If you'd prefer that get split up in any way, let me know and I can make the changes.

A sample HAR file generated by the exporter can be found here: LoggerPlusPlus.har.txt

Screen Shot 2020-08-13 at 2 29 30 PM

Screen Shot 2020-08-13 at 2 29 54 PM

Note, this only implements export, import is left as a TODO

@CoreyD97
Copy link
Contributor

Thank you for this PR, I've just had a quick glance over the code and it looks perfect!
I'll check it out properly to make sure all works as expected and then merge it soon 👍

@latacora-tomekr
Copy link
Contributor Author

Ah I may have found an issue. The spec says:

A HAR file is REQUIRED to be saved in UTF-8 encoding. Other encodings are forbidden. A reader MUST ignore a byte-order mark if it exists in the file, and a writer MAY emit a byte-order mark in the file.

I believe the default encoder uses unicode. Here is a sample of a multipart file upload parameter:

              {
                "name": "upfile",
                "value": "�PNG\r\n\u001a\n\u0000\u0000\u0000\rIHDR\u0000\u0000\u0001�\u0000 ..."
              },

@latacora-tomekr
Copy link
Contributor Author

👋 Checking back in on this to see if you have a recommended way to switch to UTF-8

@CoreyD97
Copy link
Contributor

Thanks for the poke on this, I've had a look and it seems to me that it is already formatting the files as UTF-8 as far as I can see. If you're cat'ing the file to the terminal you'll probably get some issues, as it'll try to display the characters, but using less you'll probably see something similar to the below.

UTF-8 Encoding

Other than that, just one small issue with imported entries having a null request time cannot be exported but I've fixed that 😄

If you can confirm that the files are indeed UTF-8 encoded on your end I'll go ahead and merge this 👍

@latacora-tomekr
Copy link
Contributor Author

oh yep, good call! Yea looks good to me then!

@CoreyD97 CoreyD97 merged commit 5ca5ba3 into nccgroup:master Sep 3, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants