Skip to content

About

Library for accessing HTTP Archives (HAR) with Java

Topics

Resources

Stars

105 stars

Watchers

12 watching

Forks

Latest commit

 

History

568 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

HAR Reader

A Java library for reading and writing HTTP Archive (HAR) files.

Build Status codecov Maven Central License: MIT

Features

  • ✅ Read HAR files from File, String, or InputStream
  • ✅ Write HAR data to File, OutputStream, Writer, or byte array
  • ✅ Fluent builder API for creating HAR data structures
  • ✅ Support for non-standard date formats (LAX mode)
  • ✅ Customizable Jackson ObjectMapper configuration
  • ✅ Support for additional non-standard HAR fields
  • ✅ Fully compliant with HAR 1.2 specification
  • ✅ Records-based immutable model (Java 17+)

Table of Contents

Requirements

  • Java 17 or higher
  • Jackson 3.x (for version 4.0.0+)
  • Jackson 2.x (for version 3.1.6 and earlier)

Installation

Add the dependency to your pom.xml:

<dependency>
  <groupId>de.sstoehr</groupId>
  <artifactId>har-reader</artifactId>
  <version>4.0.4</version>
</dependency>

Usage

Reading HAR Files

From File

HarReader harReader = new HarReader();
Har har = harReader.readFromFile(new File("myhar.har"));
System.out.println(har.log().creator().name());

From String

HarReader harReader = new HarReader();
Har har = harReader.readFromString("{ ... HAR-JSON-Data ... }");

LAX Mode for Non-Standard Formats

Some HAR generators use date formats that don't comply with the specification. Use LAX mode to handle these gracefully:

HarReader harReader = new HarReader();
Har har = harReader.readFromFile(new File("myhar.har"), HarReaderMode.LAX);
// or
Har har = harReader.readFromString("{ ... }", HarReaderMode.LAX);

For more control over date parsing, see the Customization section.

Writing HAR Files

To File

Har har = new Har();
HarWriter harWriter = new HarWriter();
harWriter.writeTo(new File("myhar.har"), har);

To OutputStream

Har har = new Har();
HarWriter harWriter = new HarWriter();
ByteArrayOutputStream baos = new ByteArrayOutputStream();
harWriter.writeTo(baos, har);

To Writer

Har har = new Har();
HarWriter harWriter = new HarWriter();
StringWriter sw = new StringWriter();
harWriter.writeTo(sw, har);

As Byte Array

Har har = new Har();
HarWriter harWriter = new HarWriter();
byte[] harBytes = harWriter.writeAsBytes(har);

Building HAR Data

Create HAR data structures using the fluent builder API:

Har har = Har.builder()
    .log(HarLog.builder()
        .creator(HarCreatorBrowser.builder()
            .name("HAR reader")
            .version("1.0")
            .build())
        .entry(HarEntry.builder()
            .pageref("page_0")
            .startedDateTime(ZonedDateTime.parse("2021-01-01T00:00:00Z"))
            .time(42)
            .request(HarRequest.builder()
                .method(HttpMethod.GET.name())
                .url("https://www.example.com")
                .httpVersion("HTTP/1.1")
                .build())
            .response(HarResponse.builder()
                .status(200)
                .statusText("OK")
                .httpVersion("HTTP/1.1")
                .build())
            .build())
        .build())
    .build();

Builder API Features

The builders support both single and batch operations:

// Add single entry
harLogBuilder.page(HarPage page);

// Add multiple entries (does NOT replace existing entries)
harLogBuilder.pages(List<HarPage> pages);

// Clear all entries
harLogBuilder.clearPages();

Updating Existing Objects

Use .toBuilder() to create a modified copy of an existing object:

Har updatedHar = har.toBuilder()
    .log(har.log().toBuilder()
        .comment("Updated comment")
        .build())
    .build();

Customization

Create a custom MapperFactory to configure Jackson's ObjectMapper behavior:

public class MyMapperFactory implements MapperFactory {
    public ObjectMapper instance(HarReaderMode mode) {
        ObjectMapper mapper = new ObjectMapper();
        SimpleModule module = new SimpleModule();

        // Configure Jackson object mapper as needed
        // e.g., custom date deserializers, property naming strategies, etc.

        mapper.registerModule(module);
        return mapper;
    }
}

Use your custom factory:

HarReader harReader = new HarReader(new MyMapperFactory());

See DefaultMapperFactory for reference.

Release Notes

4.0.4 - 2026-08-01

  • Dependency updates

Full Release Details

Older releases of 4.x series

4.0.3 - 2026-07-01

  • Dependency updates

Full Release Details

4.0.2 - 2026-03-01

  • Dependency updates

Full Release Details

4.0.1 - 2025-11-16

  • Dependency updates

Full Release Details

4.0.0 - 2025-10-05

⚠️ BREAKING CHANGE: Switched to Jackson 3

If you need Jackson 2 support, use version 3.1.6.

Full Release Details

View Older Releases (3.x / 2.x series)

3.x series

  • 3.1.6 (2025-10-02): Dependency updates
  • 3.1.0 (2025-04-23): Switched timings from int to long
  • 3.0.0 (2024-12-21): Major modernization release, Java 17, Records, ZonedDateTime instead of Date, @Nullable and @NotNull annotations

View All Releases

2.x Series (Java 8+)

  • 2.5.0 (2024-11-20): Fixed browser field nullability
  • 2.4.1 (2024-11-15): Fixed duplicate fields issue
  • 2.4.0 (2024-11-13): HAR serialization support, unknown HTTP methods/status codes
  • 2.3.0 (2023-11-17): Dropped Java 7 support
  • 2.2.1 (2022-05-26): Default values compliance
  • 2.2.0 (2021-03-27): Support for additional non-standard fields
  • 2.1.x (2018-2020): Various dependency updates and minor enhancements
  • 2.0.0 (2015-08-30): Customizable MapperFactory support

View All Releases

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

License

This project is licensed under the MIT License - see the LICENSE.md file for details.

About

Library for accessing HTTP Archives (HAR) with Java

Topics

Resources

Stars

105 stars

Watchers

12 watching

Forks

Releases

Packages

Used by

Contributors

Languages