package io.undertow.server.handlers;

import java.util.Date;

import io.undertow.server.HttpHandler;
import io.undertow.server.HttpServerExchange;
import io.undertow.util.DateUtils;
import io.undertow.util.Headers;

/**
 * Class that adds the Date: header to a HTTP response.
 *
 * The current date string is cached, and is updated every second in a racey
 * manner (i.e. it is possible for two thread to update it at once).
 *
 * @author Stuart Douglas
 */
public class DateHandler implements HttpHandler {

    private final HttpHandler next;
    private volatile String cachedDateString;
    private volatile long nextUpdateTime = -1;


    public DateHandler(final HttpHandler next) {
        this.next = next;
    }

    @Override
    public void handleRequest(final HttpServerExchange exchange) throws Exception {
        long time = System.currentTimeMillis();
        if(time < nextUpdateTime) {
            exchange.getResponseHeaders().put(Headers.DATE, cachedDateString);
        } else {
            String dateString = DateUtils.toDateString(new Date(time));
            cachedDateString = dateString;
            nextUpdateTime = time + 1000;
            exchange.getResponseHeaders().put(Headers.DATE, dateString);
        }
        next.handleRequest(exchange);
    }


}

@@ -844,25 +844,16 @@
 tem.
-currentTimeMillis
+nanoTime
 ();%0A
@@ -984,16 +984,72 @@
  else %7B%0A
+            long realTime = System.currentTimeMillis();%0A
         
@@ -1104,17 +1104,21 @@
 ew Date(
-t
+realT
 ime));%0A 
@@ -1199,16 +1199,22 @@
 e + 1000
+000000
 ;%0A      

Fix date handler