Skip to content

Implement incremental writing of HAR file#729

Merged
Mzack9999 merged 6 commits intoprojectdiscovery:devfrom
mjkim610:export-har
Sep 10, 2025
Merged

Implement incremental writing of HAR file#729
Mzack9999 merged 6 commits intoprojectdiscovery:devfrom
mjkim610:export-har

Conversation

@mjkim610
Copy link
Contributor

@mjkim610 mjkim610 commented Sep 6, 2025

Proposed changes

  • Implement incremental writing of HAR file (every 10 seconds)
  • Move HAR exporting functionality to separate pkg

Checklist

  • Pull request is created against the dev branch
  • All checks passed (lint, unit/integration/regression tests etc.) with my changes
  • I have added tests that prove my fix is effective or that my feature works
  • I have added necessary documentation (if appropriate)

Use martian's HAR package to Export() logs periodically. This
enables proxify to save some HAR logs even if it crashes
unexpectedly. However, it does not reduce the burden on RAM usage
caused by martian keeping track of all the reqs/resps.

Signed-off-by: MJ Kim <mjkim610@gmail.com>
Replace Export() with ExportAndReset().

This allows martian to flush its memory of completed reqs/resps.
There are several ways to append new logs into the existing HAR
file.

1. read-merge-overwrite: less error-prone, but overhead caused by
   overwriting
2. parse-append: less overhead, but more complex logic and more
   error-prone

The read-merge-overwrite approach is chosen in this commit.

Signed-off-by: MJ Kim <mjkim610@gmail.com>
@mjkim610
Copy link
Contributor Author

mjkim610 commented Sep 6, 2025

Closes #728

@ehsandeep ehsandeep linked an issue Sep 6, 2025 that may be closed by this pull request
- Move all the logic related to HAR logging into a new package
  `har`.
- Clean up HAR logging code
- Add `done` channel and `wg` WaitGroup for exiting goroutine

Signed-off-by: MJ Kim <mjkim610@gmail.com>
- Add har_test.go
- Add argument to NewLogger to make DI possible and change flush interval (for testing purposes)

Signed-off-by: MJ Kim <mjkim610@gmail.com>
@Mzack9999 Mzack9999 merged commit 90c263a into projectdiscovery:dev Sep 10, 2025
8 checks passed
@mjkim610 mjkim610 deleted the export-har branch September 10, 2025 22:44
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.

Export HAR Chunked writing optimization

2 participants

Comments