You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tinkerpop.apache.org by "kenhuuu (via GitHub)" <gi...@apache.org> on 2025/03/04 23:20:37 UTC
Re: [PR] Golang driver replace websockets with http [tinkerpop]
kenhuuu commented on code in PR #3059:
URL: https://github.com/apache/tinkerpop/pull/3059#discussion_r1980409492
##########
gremlin-go/driver/httpTransporter.go:
##########
@@ -0,0 +1,124 @@
+/*
+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 gremlingo
+
+import (
+ "bytes"
+ "compress/zlib"
+ "errors"
+ "io"
+ "net/http"
+ "sync"
+)
+
+// TODO decide channel size when chunked response handling is implemented - for now just set to 1
+const responseChannelSizeDefault = 1
+
+// HttpTransporter responsible for sending and receiving bytes to/from the server
+type HttpTransporter struct {
+ url string
+ isClosed bool
+ connSettings *connectionSettings
+ responseChannel chan []byte // receives response bytes from the server
+ httpClient *http.Client
+ wg *sync.WaitGroup
+ logHandler *logHandler
+}
+
+func NewHttpTransporter(url string, connSettings *connectionSettings, httpClient *http.Client, logHandler *logHandler) *HttpTransporter {
+ wg := &sync.WaitGroup{}
+
+ return &HttpTransporter{
+ url: url,
+ connSettings: connSettings,
+ responseChannel: make(chan []byte, responseChannelSizeDefault),
+ httpClient: httpClient,
+ wg: wg,
+ logHandler: logHandler,
+ }
+}
+
+// Write sends bytes to the server as a POST request and sends received response bytes to the responseChannel
+func (transporter *HttpTransporter) Write(data []byte) error {
+ transporter.logHandler.logf(Debug, creatingRequest)
+ req, err := http.NewRequest("POST", transporter.url, bytes.NewBuffer(data))
+ if err != nil {
+ transporter.logHandler.logf(Error, failedToSendRequest, err.Error())
+ return err
+ }
+ req.Header.Set("content-type", graphBinaryMimeType)
+ req.Header.Set("accept", graphBinaryMimeType)
+ if transporter.connSettings.enableUserAgentOnConnect {
+ req.Header.Set(userAgentHeader, userAgent)
+ }
+ if transporter.connSettings.enableCompression {
Review Comment:
`enableCompression` existed in 3.7 to manage per message deflate in WebSockets, but was removed in master. Maybe this is a setting that also applies to master but I feel like in the vast majority of cases this should just be left on.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@tinkerpop.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org