Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
package org.apache.jmeter.protocol.http.control;

import java.net.URL;
import java.time.Instant;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
Expand Down Expand Up @@ -173,20 +174,38 @@ public void addCookieFromHeader(CookieManager cookieManager,
}

@Override
public String getCookieHeaderForURL(CollectionProperty cookiesCP, URL url,
boolean allowVariableCookie) {
List<org.apache.http.cookie.Cookie> c =
getCookiesForUrl(cookiesCP, url, allowVariableCookie);
public String getCookieHeaderForURL(CollectionProperty cookiesCP, URL url, boolean allowVariableCookie) {
List<org.apache.http.cookie.Cookie> c = getCookiesForUrl(cookiesCP, url, allowVariableCookie);

boolean debugEnabled = log.isDebugEnabled();
if (debugEnabled){
if (debugEnabled) {
log.debug("Found {} cookies for {}", c.size(), url);
}

if (c.isEmpty()) {
return null;
}
List<Header> lstHdr = cookieSpec.formatCookies(c);

// Get current time as an Instant
Instant currentTime = Instant.now();
List<org.apache.http.cookie.Cookie> validCookies = new ArrayList<>();

for (org.apache.http.cookie.Cookie cookie : c) {
Date expiryDate = cookie.getExpiryDate();

// Convert Date to Instant for proper comparison
if (expiryDate == null || expiryDate.toInstant().isAfter(currentTime)) {
validCookies.add(cookie);
} else if (debugEnabled) {
log.info("Skipping expired cookie: {} for URL {}", cookie.getName(), url);
}
}

if (validCookies.isEmpty()) {
return null;
}

List<Header> lstHdr = cookieSpec.formatCookies(validCookies);
StringBuilder sbHdr = new StringBuilder();
for (Header header : lstHdr) {
sbHdr.append(header.getValue());
Expand All @@ -195,6 +214,7 @@ public String getCookieHeaderForURL(CollectionProperty cookiesCP, URL url,
return sbHdr.toString();
}


/**
* Get array of valid HttpClient cookies for the URL
*
Expand Down