1
0
mirror of https://github.com/octoleo/plantuml-server.git synced 2024-12-22 08:48:54 +00:00

Add Date header

This commit is contained in:
Arnaud Roques 2011-01-30 15:23:08 +01:00
parent 6a93bdad66
commit e55fea2359

View File

@ -71,14 +71,18 @@ public class PlantUmlServlet extends HttpServlet {
PrintWriter writer = resp.getWriter();
writer.print("<html>");
writer.print("<head>");
writer.print("<meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\" />");
writer
.print("<meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\" />");
writer.print("<meta http-equiv=\"expires\" content=\"0\">");
writer.print("<meta http-equiv=\"pragma\" content=\"no-cache\">");
writer.print("<meta http-equiv=\"cache-control\" content=\"no-cache, must-revalidate\">");
writer.print("<link rel=\"SHORTCUT ICON\" href=\"/plantuml/favicon.ico\">");
writer
.print("<meta http-equiv=\"cache-control\" content=\"no-cache, must-revalidate\">");
writer
.print("<link rel=\"SHORTCUT ICON\" href=\"/plantuml/favicon.ico\">");
writer.print("</head>");
writer.print("<body>");
writer.print("<h1>PlantUMLServer</h1><p>This application provides a servlet which serves images createdby <a href=\"http://plantuml.sourceforge.net\">PlantUML</a>.</p>");
writer
.print("<h1>PlantUMLServer</h1><p>This application provides a servlet which serves images createdby <a href=\"http://plantuml.sourceforge.net\">PlantUML</a>.</p>");
String text = request.getParameter("text");
String url = request.getParameter("url");
@ -93,7 +97,8 @@ public class PlantUmlServlet extends HttpServlet {
}
text = transcoder.decode(url);
}
writer.print("<form method=post action=\"/plantuml/uml/post\"><textarea name=\"text\" cols=\"120\" rows=\"10\">");
writer
.print("<form method=post action=\"/plantuml/uml/post\"><textarea name=\"text\" cols=\"120\" rows=\"10\">");
if (text != null) {
encode = transcoder.encode(text);
writer.print(text);
@ -102,10 +107,12 @@ public class PlantUmlServlet extends HttpServlet {
writer.print("<hr>");
writer.print("You can enter here a previously generated URL:<p>");
String host = "http://" + request.getServerName()+ ":" + request.getServerPort();
String host = "http://" + request.getServerName() + ":"
+ request.getServerPort();
String total = host + "/plantuml/uml/image/" + encode;
writer.print("<form method=\"post\" action=\"/plantuml/uml/post\"><input name=\"url\" type=\"text\" size=\"150\" value=\""
writer
.print("<form method=\"post\" action=\"/plantuml/uml/post\"><input name=\"url\" type=\"text\" size=\"150\" value=\""
+ total + "\">");
writer.print("<br><input type=\"submit\"></form>");
@ -131,7 +138,6 @@ public class PlantUmlServlet extends HttpServlet {
return TranscoderUtil.getDefaultTranscoder();
}
private void handleImage(HttpServletResponse response, String source)
throws IOException {
source = URLDecoder.decode(source, "UTF-8");
@ -173,8 +179,15 @@ public class PlantUmlServlet extends HttpServlet {
SourceStringReader reader = new SourceStringReader(plantUmlSource
.toString());
// Write the first image to "os"
long today = System.currentTimeMillis();
response.addDateHeader("Expires", today + 31536000000L);
// today + 1 year
response.addDateHeader("Last-Modified", 1261440000000L);
// 2009 dec 22 constant date in the past
response.addHeader("Cache-Control", "public");
response.setContentType("image/png");
reader.generateImage(response.getOutputStream());
response.flushBuffer();
}