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

[Feature Request] Import/Export using HAR file format #101

Open
DaniloNC opened this issue May 29, 2020 · 4 comments
Open

[Feature Request] Import/Export using HAR file format #101

DaniloNC opened this issue May 29, 2020 · 4 comments
Assignees

Comments

@DaniloNC
Copy link

Feature description:

HAR file format is a de-facto standard for saving HTTP requests/responses and is supported by multiple tools including Google Chrome and Firefox developer tools.

Supporting this format would allow integration with multiple tools.

@latacora-tomekr
Copy link
Contributor

latacora-tomekr commented Aug 11, 2020

👋 I was going to take a crack at the export feature.

HAR Export UI

I've got the UI wired up (I just used the JSONExporterControlPanel and JSONExporter as a starting point since a HAR file is just a big JSON dict.)

Here's a barebones sample of a HAR file where I think I've more or less removed all of the optional fields according to the spec. (added .txt as .har isn't allowed by github).

example.har.txt

How would you recommend going about creating the custom JSON dict that is required by the HAR Format?

@CoreyD97
Copy link
Contributor

Thanks for looking into this @latacora-tomekr!
I think the best way to do this might be to define a specific GSON serializer that'll take a LogEntry object and build the "entry" element that the HAR format expects.

However as the gsonProvider used by the JSONExporter class has a serializer defined for the LogEntry class already, you might be best building a new Gson instance and registering the custom serializer within the HAR exporter class using something like:
Gson gson = new GsonBuilder().registerTypeAdapter(LogEntry.class, new HarSerializer()).create()

Then you could iterate over each entry to be exported and add them to your har export object.

Again, thank you very much for looking into this! :)

@latacora-tomekr
Copy link
Contributor

I see, so I created a HarSerializer in the form of:

public class HarSerializer extends TypeAdapter<LogEntry> {

    @Override
    public void write(JsonWriter writer, LogEntry logEntry) throws IOException {

However, I think a LogEntry represents one possible request. So in the context of the HAR format, this serializer logic would just serialize one object in the entries array of the HAR file. Would I build out log > version, creator, entries on the gson object created by Gson gson = new GsonBuilder().registerTypeAdapter(LogEntry.class, new HarSerializer()).create()?

@CoreyD97
Copy link
Contributor

Apologies, indeed you are correct in saying that LogEntry represents a single request. My previous comment probably wasn't the best method of doing this.

Instead, a TypeAdapter which could take an array (or list) of LogEntry objects would be sensible, and would allow the entire HAR object to be built within this class. The rest of the data for the HAR file such as version, creator etc could be provided when instantiating the serializer class.

Gson gson = new GsonBuilder().registerTypeAdapter(LogEntry[].class, new HarSerializer(version, creator)).create()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants