Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
A
apaas-meshproxy
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
gzga-jzapi
apaas-meshproxy
Commits
0c108240
Commit
0c108240
authored
Dec 20, 2020
by
leitao.zhang
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'dev' into dev-ysgz
parents
81fa533c
9997acc4
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
31 additions
and
25 deletions
+31
-25
src/handler/proxyhandler.go
src/handler/proxyhandler.go
+29
-24
src/main.go
src/main.go
+2
-1
No files found.
src/handler/proxyhandler.go
View file @
0c108240
...
@@ -77,6 +77,15 @@ func Proxy(c *gin.Context) {
...
@@ -77,6 +77,15 @@ func Proxy(c *gin.Context) {
//如果是静态文件
//如果是静态文件
if
CheckStaticFile
(
c
.
Request
.
URL
.
Path
)
{
if
CheckStaticFile
(
c
.
Request
.
URL
.
Path
)
{
host
:=
getHost
(
proxyData
.
ReqUrl
)
host
:=
getHost
(
proxyData
.
ReqUrl
)
//var prefix string
//if apiId == "" {
// prefix= fmt.Sprintf("%s/%s/service/%s/%s/", config.Prefix, config.MeshId,applyId,apiId)
//}else {
// prefix= fmt.Sprintf("%s/%s/service/%s/", config.Prefix, config.MeshId,applyId)
//}
//
//staticPath:= strings.ReplaceAll(c.Request.URL.Path,prefix,"")
fwd
,
_
:=
forward
.
New
(
forward
.
PassHostHeader
(
false
))
fwd
,
_
:=
forward
.
New
(
forward
.
PassHostHeader
(
false
))
c
.
Request
.
URL
=
testutils
.
ParseURI
(
fmt
.
Sprintf
(
"%s%s"
,
host
,
c
.
Request
.
URL
.
Path
))
c
.
Request
.
URL
=
testutils
.
ParseURI
(
fmt
.
Sprintf
(
"%s%s"
,
host
,
c
.
Request
.
URL
.
Path
))
c
.
Request
.
RequestURI
=
getRequestURI
(
c
.
Request
)
c
.
Request
.
RequestURI
=
getRequestURI
(
c
.
Request
)
...
@@ -86,7 +95,7 @@ func Proxy(c *gin.Context) {
...
@@ -86,7 +95,7 @@ func Proxy(c *gin.Context) {
roundTripper
:=
http
.
DefaultTransport
.
(
*
http
.
Transport
)
roundTripper
:=
http
.
DefaultTransport
.
(
*
http
.
Transport
)
//roundTripper.ForceAttemptHTTP2 = false
//roundTripper.ForceAttemptHTTP2 = false
roundTripper
.
TLSClientConfig
=
&
tls
.
Config
{
InsecureSkipVerify
:
true
}
roundTripper
.
TLSClientConfig
=
&
tls
.
Config
{
InsecureSkipVerify
:
true
}
f
,
err
:=
forward
.
New
(
forward
.
PassHostHeader
(
false
),
forward
.
RoundTripper
(
roundTripper
),
forward
.
ResponseModifier
(
func
(
resp
*
http
.
Response
)
error
{
f
orwarder
,
err
:=
forward
.
New
(
forward
.
PassHostHeader
(
false
),
forward
.
RoundTripper
(
roundTripper
),
forward
.
ResponseModifier
(
func
(
resp
*
http
.
Response
)
error
{
respbody
,
err1
:=
ioutil
.
ReadAll
(
resp
.
Body
)
respbody
,
err1
:=
ioutil
.
ReadAll
(
resp
.
Body
)
if
err1
!=
nil
{
if
err1
!=
nil
{
log
.
Println
(
err1
)
log
.
Println
(
err1
)
...
@@ -148,15 +157,25 @@ func Proxy(c *gin.Context) {
...
@@ -148,15 +157,25 @@ func Proxy(c *gin.Context) {
return
nil
return
nil
}))
}))
if
err
!=
nil
{
if
err
!=
nil
{
c
.
JSON
(
500
,
errors
.
New
(
"请求失败"
))
return
}
reqURL
:=
testutils
.
ParseURI
(
proxyData
.
ReqUrl
)
if
reqURL
.
RawQuery
==
""
{
reqURL
.
RawQuery
=
c
.
Request
.
URL
.
RawQuery
}
else
{
if
c
.
Request
.
URL
.
RawQuery
!=
""
{
reqURL
.
RawQuery
+=
"&"
+
c
.
Request
.
URL
.
RawQuery
}
}
c
.
Request
.
URL
=
testutils
.
ParseURI
(
proxyData
.
ReqUrl
)
}
c
.
Request
.
URL
=
reqURL
fmt
.
Println
(
"c.Request.URL-------"
,
c
.
Request
.
URL
)
fmt
.
Println
(
"c.Request.URL-------"
,
c
.
Request
.
URL
)
c
.
Request
.
RequestURI
=
getRequestURI
(
c
.
Request
)
c
.
Request
.
RequestURI
=
reqURL
.
RequestURI
(
)
fmt
.
Println
(
"c.Request-------"
,
c
.
Request
)
fmt
.
Println
(
"c.Request-------"
,
c
.
Request
)
c
.
Request
.
Host
=
getHost
(
proxyData
.
ReqUrl
)
c
.
Request
.
Host
=
getHost
(
proxyData
.
ReqUrl
)
fmt
.
Println
(
"proxyData.RealUrl-------"
,
proxyData
.
ReqUrl
)
fmt
.
Println
(
"proxyData.RealUrl-------"
,
proxyData
.
ReqUrl
)
f
.
ServeHTTP
(
c
.
Writer
,
c
.
Request
)
f
orwarder
.
ServeHTTP
(
c
.
Writer
,
c
.
Request
)
}
}
}
}
...
@@ -169,26 +188,12 @@ func CheckStaticFile(path string) bool {
...
@@ -169,26 +188,12 @@ func CheckStaticFile(path string) bool {
return
false
return
false
}
}
func
getProxyURL
(
proxyData
model
.
ProxyData
,
req
*
http
.
Request
)
string
{
realPath
:=
proxyData
.
ReqUrl
rawQuery
:=
req
.
URL
.
RawQuery
var
result
=
""
if
rawQuery
==
""
{
if
proxyData
.
DataServiceType1
==
6
{
result
=
realPath
+
"?f=json"
}
else
{
result
=
realPath
}
}
else
{
result
=
realPath
+
"?"
+
rawQuery
if
proxyData
.
DataServiceType1
==
6
&&
!
strings
.
Contains
(
rawQuery
,
"f=json"
)
{
result
=
result
+
"&f=json"
}
}
return
result
}
func
getRequestURI
(
req
*
http
.
Request
)
string
{
func
getRequestURI
(
req
*
http
.
Request
)
string
{
//requestURI, _ := url.ParseRequestURI(req.RequestURI)
//
//requestURI.RawQuery
path
:=
req
.
URL
.
Path
path
:=
req
.
URL
.
Path
rawQuery
:=
req
.
URL
.
RawQuery
rawQuery
:=
req
.
URL
.
RawQuery
var
result
=
""
var
result
=
""
...
...
src/main.go
View file @
0c108240
...
@@ -18,7 +18,7 @@ import (
...
@@ -18,7 +18,7 @@ import (
var
(
var
(
argPort
=
pflag
.
Int
(
"port"
,
8011
,
""
)
argPort
=
pflag
.
Int
(
"port"
,
8011
,
""
)
argPrefix
=
pflag
.
String
(
"prefix"
,
"/bgmesh/fiddler"
,
""
)
argPrefix
=
pflag
.
String
(
"prefix"
,
"/bgmesh/fiddler"
,
""
)
meshId
=
pflag
.
String
(
"meshId"
,
"
133
"
,
""
)
meshId
=
pflag
.
String
(
"meshId"
,
"
461
"
,
""
)
redisUrl
=
pflag
.
String
(
"redisUrl"
,
"redis://apaas-redis:6379"
,
""
)
redisUrl
=
pflag
.
String
(
"redisUrl"
,
"redis://apaas-redis:6379"
,
""
)
redisTag
=
pflag
.
String
(
"redisTag"
,
"apaas-mesh-proxy"
,
""
)
redisTag
=
pflag
.
String
(
"redisTag"
,
"apaas-mesh-proxy"
,
""
)
confPath
=
pflag
.
String
(
"confPath"
,
"/app/config/proxy.json"
,
""
)
confPath
=
pflag
.
String
(
"confPath"
,
"/app/config/proxy.json"
,
""
)
...
@@ -33,6 +33,7 @@ func main() {
...
@@ -33,6 +33,7 @@ func main() {
server
()
server
()
}
}
//打包
func
server
()
error
{
func
server
()
error
{
config
.
Prefix
=
*
argPrefix
config
.
Prefix
=
*
argPrefix
handler
:=
router
.
Load
(
ginrus
.
Ginrus
(
logrus
.
StandardLogger
(),
time
.
RFC3339
,
true
))
handler
:=
router
.
Load
(
ginrus
.
Ginrus
(
logrus
.
StandardLogger
(),
time
.
RFC3339
,
true
))
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment