Skip to content
Merged
Show file tree
Hide file tree
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 @@ -29,6 +29,7 @@
import java.io.IOException;
import java.time.Instant;

import org.apache.hc.client5.http.utils.DateUtils;
import org.apache.hc.core5.annotation.Contract;
import org.apache.hc.core5.annotation.ThreadingBehavior;
import org.apache.hc.core5.http.EntityDetails;
Expand Down Expand Up @@ -71,7 +72,7 @@ public void process(final HttpResponse response,
}
}
if (!response.containsHeader(HttpHeaders.DATE)) {
response.addHeader(new BasicHeader(HttpHeaders.DATE, Instant.now()));
response.addHeader(new BasicHeader(HttpHeaders.DATE, DateUtils.formatStandardDate(Instant.now())));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,11 @@
import java.time.Instant;

import org.apache.hc.client5.http.utils.DateUtils;
import org.apache.hc.core5.http.HttpHeaders;
import org.apache.hc.core5.http.HttpResponse;
import org.apache.hc.core5.http.HttpStatus;
import org.apache.hc.core5.http.support.BasicResponseBuilder;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

Expand Down Expand Up @@ -87,4 +89,14 @@ void shouldStripContentTypeFromOrigin304ResponseToStrongValidation() throws Exce
"Content-Type", "text/html;charset=utf-8");
}

@Test
void shouldAddStandardDateHeaderIfMissing() throws Exception {
final HttpResponse response = BasicResponseBuilder.create(HttpStatus.SC_OK)
.build();
assertFalse(response.containsHeader(HttpHeaders.DATE));
impl.process(response, null, null);
Assertions.assertTrue(response.containsHeader(HttpHeaders.DATE));
Assertions.assertNotNull(DateUtils.parseStandardDate(response, HttpHeaders.DATE));
}

}