Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
Snowflake WebExtension
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Cecylia Bocovich
Snowflake WebExtension
Commits
83f87120
Commit
83f87120
authored
7 years ago
by
David Fifield
Browse files
Options
Downloads
Patches
Plain Diff
Factor out a function to extract the client IP address.
parent
9e5eb7f5
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
server/server.go
+12
-10
12 additions, 10 deletions
server/server.go
with
12 additions
and
10 deletions
server/server.go
+
12
−
10
View file @
83f87120
...
...
@@ -128,6 +128,16 @@ func proxy(local *net.TCPConn, conn *webSocketConn) {
wg
.
Wait
()
}
// Return an address string suitable to pass into pt.DialOr.
func
clientAddr
(
clientIPParam
string
)
string
{
// Check if client addr is a valid IP
clientIP
:=
net
.
ParseIP
(
clientIPParam
)
if
clientIP
==
nil
{
return
""
}
return
clientIPParam
}
func
webSocketHandler
(
ws
*
websocket
.
WebSocket
)
{
// Undo timeouts on HTTP request handling.
ws
.
Conn
.
SetDeadline
(
time
.
Time
{})
...
...
@@ -139,17 +149,9 @@ func webSocketHandler(ws *websocket.WebSocket) {
handlerChan
<-
-
1
}()
// Check if client addr is a valid IP
addr
:=
ws
.
Request
()
.
URL
.
Query
()
.
Get
(
"client_ip"
)
clientIP
:=
net
.
ParseIP
(
addr
)
if
clientIP
==
nil
{
// Set client addr to empty
addr
=
""
}
// Pass the address of client as the remote address of incoming connection
or
,
err
:=
pt
.
DialOr
(
&
ptInfo
,
addr
,
ptMethodName
)
clientIPParam
:=
ws
.
Request
()
.
URL
.
Query
()
.
Get
(
"client_ip"
)
or
,
err
:=
pt
.
DialOr
(
&
ptInfo
,
clientIPParam
,
ptMethodName
)
if
err
!=
nil
{
log
.
Printf
(
"failed to connect to ORPort: %s"
,
err
)
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment