[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[tor-commits] [metrics-web/release] Add comment section to CSV file headers.
commit b8a0bfbbe8a6f784156c69e3881b5542eec43717
Author: Karsten Loesing <karsten.loesing@xxxxxxx>
Date: Mon Mar 5 16:00:13 2018 +0100
Add comment section to CSV file headers.
Implements #25387, though without legend.
Also fix MIME type from image/csv to text/csv.
---
.../org/torproject/metrics/web/GraphImageServlet.java | 19 ++++++++++++++++---
1 file changed, 16 insertions(+), 3 deletions(-)
diff --git a/src/main/java/org/torproject/metrics/web/GraphImageServlet.java b/src/main/java/org/torproject/metrics/web/GraphImageServlet.java
index f24d698..1c5a8ca 100644
--- a/src/main/java/org/torproject/metrics/web/GraphImageServlet.java
+++ b/src/main/java/org/torproject/metrics/web/GraphImageServlet.java
@@ -64,13 +64,26 @@ public class GraphImageServlet extends HttpServlet {
}
/* Write graph bytes to response. */
- response.setContentType("image/" + fileType);
- response.setHeader("Content-Length",
- String.valueOf(graph.getBytes().length));
+ byte[] headerBytes = ("#\n"
+ + "# The Tor Project\n"
+ + "#\n"
+ + "# URL: https://metrics.torproject.org"
+ + request.getRequestURI()
+ + (null == request.getQueryString() ? ""
+ : "?" + request.getQueryString()) + "\n"
+ + "#\n").getBytes();
+ response.setContentType(
+ ("csv".equals(fileType) ? "text/" : "image/") + fileType);
+ response.setHeader("Content-Length", String.valueOf(
+ ("csv".equals(fileType) ? headerBytes.length : 0)
+ + graph.getBytes().length));
response.setHeader("Content-Disposition",
"inline; filename=\"" + graph.getFileName() + "\"");
BufferedOutputStream output = new BufferedOutputStream(
response.getOutputStream(), 1024);
+ if ("csv".equals(fileType)) {
+ output.write(headerBytes);
+ }
output.write(graph.getBytes(), 0, graph.getBytes().length);
output.flush();
output.close();
_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits