ok2c commented on code in PR #500:
URL:
https://github.com/apache/httpcomponents-core/pull/500#discussion_r1810132671
##########
httpcore5/src/main/java/org/apache/hc/core5/http/protocol/ResponseDate.java:
##########
@@ -46,27 +46,49 @@
* This interceptor is recommended for the HTTP protocol conformance and
* the correct operation of the server-side message processing pipeline.
* </p>
+ * <p>
+ * If the {@code Date} header is invalid, the interceptor will replace it with
the
+ * time at which the response was received.
+ * </p>
*
* @since 4.0
*/
@Contract(threading = ThreadingBehavior.SAFE)
public class ResponseDate implements HttpResponseInterceptor {
+ /**
+ * Indicates whether to replace an invalid Date header.
+ *
+ * @since 5.4
+ */
+ private final boolean replaceInvalidDate;
+
public static final ResponseDate INSTANCE = new ResponseDate();
public ResponseDate() {
+ this(false);
+ }
+
+ /**
+ * Constructs a ResponseDate interceptor.
+ *
+ * @param replaceInvalidDate Whether to replace an invalid {@code Date}
header.
+ * If {@code true}, the interceptor will replace
any
+ * detected invalid {@code Date} header with a
valid value.
+ * @since 5.4
+ */
+ public ResponseDate(final boolean replaceInvalidDate) {
super();
+ this.replaceInvalidDate = replaceInvalidDate;
}
@Override
public void process(final HttpResponse response, final EntityDetails
entity, final HttpContext context)
throws HttpException, IOException {
Args.notNull(response, "HTTP response");
- final int status = response.getCode();
- if (status >= HttpStatus.SC_OK &&
- !response.containsHeader(HttpHeaders.DATE)) {
+ final Header dateHeader = response.getFirstHeader(HttpHeaders.DATE);
Review Comment:
@arturobernalg I suppose `replaceInvalidDate` is not the best name now.
`alwaysReplace`?
This bit cab be optimized a little. If the `alwaysReplace` flag is true
there is no need to do ` response.getFirstHeader(HttpHeaders.DATE)`. Its result
is basically ignored. Please re-organize the logical conditions to avoid that.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]