[ 
https://issues.apache.org/jira/browse/TINKERPOP-2830?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17786951#comment-17786951
 ] 

ASF GitHub Bot commented on TINKERPOP-2830:
-------------------------------------------

Cole-Greer commented on code in PR #2328:
URL: https://github.com/apache/tinkerpop/pull/2328#discussion_r1396383468


##########
gremlin-server/src/main/java/org/apache/tinkerpop/gremlin/server/handler/HttpUserAgentHandler.java:
##########
@@ -0,0 +1,71 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tinkerpop.gremlin.server.handler;
+
+import com.codahale.metrics.MetricRegistry;
+import io.netty.channel.ChannelHandlerContext;
+import io.netty.channel.ChannelInboundHandlerAdapter;
+import io.netty.handler.codec.http.*;
+import io.netty.handler.codec.http.websocketx.WebSocketServerProtocolHandler;
+import io.netty.util.AttributeKey;
+import org.apache.tinkerpop.gremlin.driver.UserAgent;
+import org.apache.tinkerpop.gremlin.server.GremlinServer;
+import org.apache.tinkerpop.gremlin.server.util.MetricManager;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import static 
org.apache.tinkerpop.gremlin.server.handler.HttpHandlerUtil.sendError;
+
+public class HttpUserAgentHandler extends ChannelInboundHandlerAdapter {
+    /**
+     * This constant caps the number of unique user agents which will be 
tracked in the metrics. Any new unique
+     * user agents will be replaced with "other" in the metrics after this cap 
has been reached.
+     */
+    private static final int MAX_USER_AGENT_METRICS = 10000;
+
+    private static final Logger logger = 
LoggerFactory.getLogger(HttpUserAgentHandler.class);
+    public static final AttributeKey<String> USER_AGENT_ATTR_KEY = 
AttributeKey.valueOf(UserAgent.USER_AGENT_HEADER_NAME);
+
+    @Override
+    public void channelRead(final ChannelHandlerContext ctx, Object msg) {
+        if (msg instanceof FullHttpMessage) {
+            final FullHttpMessage request = (FullHttpMessage) msg;
+            if (request.headers().contains(UserAgent.USER_AGENT_HEADER_NAME)) {

Review Comment:
   I took a look at this, and the contains method here is case-insensitive.





> Handle User-Agent from HTTP Requests to server
> ----------------------------------------------
>
>                 Key: TINKERPOP-2830
>                 URL: https://issues.apache.org/jira/browse/TINKERPOP-2830
>             Project: TinkerPop
>          Issue Type: Improvement
>          Components: server
>    Affects Versions: 3.5.4
>            Reporter: Cole Greer
>            Priority: Critical
>
> Changes are being introduced in 
> [2480|https://issues.apache.org/jira/browse/TINKERPOP-2480] which add a user 
> agent which is sent as a request header during web socket handshakes. 
> Originally 2480 was planned to also include the server accepting user agents 
> from http requests but this has now fallen outside of the scope. This ticket 
> is to complete the user agent feature by adding the ability for the server to 
> accept user agents in http requests in addition to web sockets.



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to