Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
caddy
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
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Łukasz Nowak
caddy
Commits
dca59d0e
Commit
dca59d0e
authored
Jan 29, 2015
by
Matthew Holt
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Stubbed out really basic proxy middleware
parent
ec5f94ad
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
51 additions
and
0 deletions
+51
-0
middleware/middleware.go
middleware/middleware.go
+1
-0
middleware/proxy.go
middleware/proxy.go
+50
-0
No files found.
middleware/middleware.go
View file @
dca59d0e
...
@@ -17,6 +17,7 @@ func init() {
...
@@ -17,6 +17,7 @@ func init() {
register
(
"rewrite"
,
Rewrite
)
register
(
"rewrite"
,
Rewrite
)
register
(
"redir"
,
Redirect
)
register
(
"redir"
,
Redirect
)
register
(
"ext"
,
Extensionless
)
register
(
"ext"
,
Extensionless
)
register
(
"proxy"
,
Proxy
)
register
(
"fastcgi"
,
FastCGI
)
register
(
"fastcgi"
,
FastCGI
)
}
}
...
...
middleware/proxy.go
0 → 100644
View file @
dca59d0e
package
middleware
import
(
"log"
"net/http"
"strings"
)
// Proxy is middleware that proxies requests.
func
Proxy
(
p
parser
)
Middleware
{
var
rules
[]
proxyRule
for
p
.
Next
()
{
rule
:=
proxyRule
{}
if
!
p
.
Args
(
&
rule
.
from
,
&
rule
.
to
)
{
return
p
.
ArgErr
()
}
rules
=
append
(
rules
,
rule
)
}
return
func
(
next
http
.
HandlerFunc
)
http
.
HandlerFunc
{
return
func
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
for
_
,
rule
:=
range
rules
{
if
Path
(
r
.
URL
.
Path
)
.
Matches
(
rule
.
from
)
{
client
:=
&
http
.
Client
{}
r
.
RequestURI
=
""
r
.
URL
.
Scheme
=
strings
.
ToLower
(
r
.
URL
.
Scheme
)
resp
,
err
:=
client
.
Do
(
r
)
if
err
!=
nil
{
log
.
Fatal
(
err
)
}
resp
.
Write
(
w
)
}
else
{
next
(
w
,
r
)
}
}
}
}
}
type
proxyRule
struct
{
from
string
to
string
}
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