All Downloads are FREE. Search and download functionalities are using the official Maven repository.

de.sstoehr.harreader.model.HarCache Maven / Gradle / Ivy

The newest version!
package de.sstoehr.harreader.model;

import com.fasterxml.jackson.annotation.JsonAnyGetter;
import com.fasterxml.jackson.annotation.JsonAnySetter;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonInclude;
import lombok.Builder;

import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.time.ZonedDateTime;
import java.util.HashMap;
import java.util.Map;

/**
 * Information about a request coming from browser cache.
 * @see specification
 */
@JsonInclude(JsonInclude.Include.NON_NULL)
@JsonIgnoreProperties(ignoreUnknown = true)
@Builder(toBuilder = true)
public record HarCache(
        @Nullable HarCacheInfo beforeRequest,
        @Nullable HarCacheInfo afterRequest,
        @Nullable String comment,
        @Nonnull Map additional
) {

    public HarCache() {
        this(null, null, null, new HashMap<>());
    }

    public HarCache(@Nullable HarCacheInfo beforeRequest,
                    @Nullable HarCacheInfo afterRequest,
                    @Nullable String comment,
                    @Nullable Map additional) {
        this.beforeRequest = beforeRequest;
        this.afterRequest = afterRequest;
        this.comment = comment;
        this.additional = (additional == null) ? new HashMap<>() : additional;
    }

    @JsonAnyGetter
    public Map additional() {
        return additional;
    }

    @JsonAnySetter
    public void setAdditionalField(String key, Object value) {
        additional.put(key, value);
    }

    /**
     * Information about a request coming from browser cache.
     * @see specification
     */
    @JsonInclude(JsonInclude.Include.NON_NULL)
    @JsonIgnoreProperties(ignoreUnknown = true)
    @Builder(toBuilder = true)
    public record HarCacheInfo(@Nullable @JsonFormat(shape = JsonFormat.Shape.STRING) ZonedDateTime expires,
                                      @Nullable @JsonFormat(shape = JsonFormat.Shape.STRING) ZonedDateTime lastAccess,
                                      @Nullable String eTag,
                                      @Nullable Integer hitCount,
                                      @Nullable String comment,
                                      @Nonnull Map additional) {

        public HarCacheInfo() {
            this(null, null, null, null, null, new HashMap<>());
        }

        public HarCacheInfo(@Nullable ZonedDateTime expires,
                            @Nullable ZonedDateTime lastAccess,
                            @Nullable String eTag,
                            @Nullable Integer hitCount,
                            @Nullable String comment,
                            @Nullable Map additional) {
            this.expires = expires;
            this.lastAccess = lastAccess;
            this.eTag = eTag;
            this.hitCount = hitCount;
            this.comment = comment;
            this.additional = (additional == null) ? new HashMap<>() : additional;
        }

        /**
         * @return Map with additional keys, which are not officially supported by the HAR specification
         */
        @JsonAnyGetter
        public Map additional() {
            return additional;
        }

        @JsonAnySetter
        public void setAdditionalField(String key, Object value) {
            this.additional.put(key, value);
        }

    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy