Skip to content

Commit

Permalink
WarcServer: add Memento-Datetime header #11
Browse files Browse the repository at this point in the history
  • Loading branch information
ato committed Feb 20, 2019
1 parent 2786c9d commit 1e7e3a6
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/org/netpreserve/jwarc/WarcServer.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
import static java.nio.charset.StandardCharsets.US_ASCII;
import static java.nio.charset.StandardCharsets.UTF_8;
import static java.nio.file.StandardOpenOption.READ;
import static java.time.ZoneOffset.UTC;
import static java.time.format.DateTimeFormatter.RFC_1123_DATE_TIME;
import static org.netpreserve.jwarc.HttpServer.send;

/**
Expand Down Expand Up @@ -96,7 +98,8 @@ private void replay(Socket socket, String target, boolean inject) throws IOExcep
try (FileChannel channel = FileChannel.open(entry.file, READ)) {
channel.position(entry.position);
WarcReader reader = new WarcReader(channel);
HttpResponse http = ((WarcResponse) reader.next().get()).http();
WarcResponse record = (WarcResponse) reader.next().get();
HttpResponse http = record.http();
HttpResponse.Builder b = new HttpResponse.Builder(http.status(), http.reason());
for (Map.Entry<String, List<String>> e : http.headers().map().entrySet()) {
if (e.getKey().equalsIgnoreCase("Strict-Transport-Security")) continue;
Expand All @@ -107,6 +110,7 @@ private void replay(Socket socket, String target, boolean inject) throws IOExcep
}
}
b.setHeader("Connection", "keep-alive");
b.setHeader("Memento-Datetime", RFC_1123_DATE_TIME.format(record.date().atOffset(UTC)));
MessageBody body = http.body();
if (inject && HTML.equals(http.contentType().base())) {
body = LengthedBody.create(body, ByteBuffer.wrap(script), script.length + body.size());
Expand Down

0 comments on commit 1e7e3a6

Please sign in to comment.