[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[tor-commits] [metrics-lib/release] Use enum for request method.



commit 86c47d3764b1d563bb81eb683da39c3ca31c13ba
Author: iwakeh <iwakeh@xxxxxxxxxxxxxx>
Date:   Wed Jan 31 12:35:28 2018 +0000

    Use enum for request method.
---
 src/main/java/org/torproject/descriptor/log/Method.java       |  8 ++++++++
 .../org/torproject/descriptor/log/WebServerAccessLogLine.java | 11 ++++++-----
 2 files changed, 14 insertions(+), 5 deletions(-)

diff --git a/src/main/java/org/torproject/descriptor/log/Method.java b/src/main/java/org/torproject/descriptor/log/Method.java
new file mode 100644
index 0000000..c29d495
--- /dev/null
+++ b/src/main/java/org/torproject/descriptor/log/Method.java
@@ -0,0 +1,8 @@
+/* Copyright 2018 The Tor Project
+ * See LICENSE for licensing information */
+
+package org.torproject.descriptor.log;
+
+public  enum Method {
+    GET, HEAD, POST;
+}
diff --git a/src/main/java/org/torproject/descriptor/log/WebServerAccessLogLine.java b/src/main/java/org/torproject/descriptor/log/WebServerAccessLogLine.java
index 4eda73b..fdbf5c1 100644
--- a/src/main/java/org/torproject/descriptor/log/WebServerAccessLogLine.java
+++ b/src/main/java/org/torproject/descriptor/log/WebServerAccessLogLine.java
@@ -34,7 +34,7 @@ public class WebServerAccessLogLine {
   private String ip;
   private int response;
   private String request;
-  private String method;
+  private Method method;
   private LocalDate date;
   private String protocol;
   private int size = -1;
@@ -52,8 +52,8 @@ public class WebServerAccessLogLine {
   @Override
   public String toString() {
     return String.format("%s - - [%s:00:00:00 +0000] \"%s %s %s\" %d %s",
-        this.ip, this.getDateString(), this.method, this.request, this.type,
-        this.response, this.size < 0 ? DASH : this.size);
+        this.ip, this.getDateString(), this.method.name(), this.request,
+        this.type, this.response, this.size < 0 ? DASH : this.size);
   }
 
   /** Returns the string of the date using 'yyyymmdd' format. */
@@ -71,7 +71,7 @@ public class WebServerAccessLogLine {
     this.ip = ip;
   }
 
-  public String getMethod() {
+  public Method getMethod() {
     return this.method;
   }
 
@@ -111,7 +111,7 @@ public class WebServerAccessLogLine {
       Matcher mat = logLinePattern.matcher(line);
       if (mat.find()) {
         res.response = Integer.valueOf(mat.group(10));
-        res.method = mat.group(7);
+        res.method = Method.valueOf(mat.group(7));
         res.protocol = mat.group(9);
         String dateTimeString = mat.group(4) + mat.group(5) + mat.group(6);
         res.date = ZonedDateTime.parse(dateTimeString,
@@ -135,3 +135,4 @@ public class WebServerAccessLogLine {
   }
 
 }
+



_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits