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

net.continuumsecurity.proxy.HarUtils Maven / Gradle / Ivy

There is a newer version: 5.1.4
Show newest version
package net.continuumsecurity.proxy;

import edu.umass.cs.benchlab.har.HarHeader;
import edu.umass.cs.benchlab.har.HarRequest;

public class HarUtils {
    public static HarRequest changeCookieValue(HarRequest request,String name,String value) {
        String patternMulti = "([; ]" + name + ")=[^;]*(.*)";
        String patternStart = "^(" + name + ")=[^;]*(.*)";

        for (HarHeader header : request.getHeaders().getHeaders()) {
            if (header.getName().equalsIgnoreCase("COOKIE")) {
                if (header.getValue() != null) {
                    String updated = header.getValue().replaceAll(patternMulti, "$1=" + value + "$2");
                    if (updated.equals(header.getValue())) {
                        updated = header.getValue().replaceAll(patternStart, "$1=" + value + "$2");
                    }
                    header.setValue(updated);
                }
            }
        }
        return request;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy