Skip to content

Commit

Permalink
Include Last-Modified header in the response
Browse files Browse the repository at this point in the history
  • Loading branch information
mscottford authored and slawekjaranowski committed Aug 16, 2022
1 parent 6685052 commit c3644f0
Showing 1 changed file with 9 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.text.SimpleDateFormat;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.time.ZoneOffset;
import java.time.ZonedDateTime;
import java.time.format.DateTimeFormatter;
import java.util.Collections;
import java.util.Date;

Expand Down Expand Up @@ -159,6 +164,10 @@ protected void doGet( HttpServletRequest req, HttpServletResponse resp )
}
resp.setContentType( getServletContext().getMimeType( fileEntry.getName() ) );

LocalDateTime lastModifiedDate = LocalDateTime.ofEpochSecond( fileEntry.getLastModified() / 1000, (int)(fileEntry.getLastModified() % 1000), ZoneOffset.UTC );
String formattedLastModifiedDate = lastModifiedDate.atZone( ZoneId.of("UTC") ).format( DateTimeFormatter.RFC_1123_DATE_TIME );
resp.addHeader( "Last-Modified", formattedLastModifiedDate);

try (InputStream source = fileEntry.getInputStream())
{
IOUtils.copy( source, resp.getOutputStream() );
Expand Down

0 comments on commit c3644f0

Please sign in to comment.