Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-workhorse
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
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Kirill Smelkov
gitlab-workhorse
Commits
d360a0c2
Commit
d360a0c2
authored
Jan 13, 2016
by
Jacob Vosmaer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Move logging and HTTPError to the helper package
parent
bcf4e63e
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
14 additions
and
66 deletions
+14
-66
internal/helper/helpers.go
internal/helper/helpers.go
+9
-0
internal/upstream/logging.go
internal/upstream/logging.go
+0
-52
internal/upstream/upstream.go
internal/upstream/upstream.go
+5
-14
No files found.
internal/helper/helpers.go
View file @
d360a0c2
...
...
@@ -60,3 +60,12 @@ func URLMustParse(s string) *url.URL {
}
return
u
}
func
HTTPError
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
,
error
string
,
code
int
)
{
if
r
.
ProtoAtLeast
(
1
,
1
)
{
// Force client to disconnect if we render request error
w
.
Header
()
.
Set
(
"Connection"
,
"close"
)
}
http
.
Error
(
w
,
error
,
code
)
}
internal/upstream/logging.go
deleted
100644 → 0
View file @
bcf4e63e
package
upstream
import
(
"fmt"
"net/http"
"time"
)
type
loggingResponseWriter
struct
{
rw
http
.
ResponseWriter
status
int
written
int64
started
time
.
Time
}
func
newLoggingResponseWriter
(
rw
http
.
ResponseWriter
)
loggingResponseWriter
{
return
loggingResponseWriter
{
rw
:
rw
,
started
:
time
.
Now
(),
}
}
func
(
l
*
loggingResponseWriter
)
Header
()
http
.
Header
{
return
l
.
rw
.
Header
()
}
func
(
l
*
loggingResponseWriter
)
Write
(
data
[]
byte
)
(
n
int
,
err
error
)
{
if
l
.
status
==
0
{
l
.
WriteHeader
(
http
.
StatusOK
)
}
n
,
err
=
l
.
rw
.
Write
(
data
)
l
.
written
+=
int64
(
n
)
return
}
func
(
l
*
loggingResponseWriter
)
WriteHeader
(
status
int
)
{
if
l
.
status
!=
0
{
return
}
l
.
status
=
status
l
.
rw
.
WriteHeader
(
status
)
}
func
(
l
*
loggingResponseWriter
)
Log
(
r
*
http
.
Request
)
{
duration
:=
time
.
Since
(
l
.
started
)
fmt
.
Printf
(
"%s %s - - [%s] %q %d %d %q %q %f
\n
"
,
r
.
Host
,
r
.
RemoteAddr
,
l
.
started
,
fmt
.
Sprintf
(
"%s %s %s"
,
r
.
Method
,
r
.
RequestURI
,
r
.
Proto
),
l
.
status
,
l
.
written
,
r
.
Referer
(),
r
.
UserAgent
(),
duration
.
Seconds
(),
)
}
internal/upstream/upstream.go
View file @
d360a0c2
...
...
@@ -55,18 +55,18 @@ func (u *Upstream) configureURLPrefix() {
}
func
(
u
*
Upstream
)
ServeHTTP
(
ow
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
w
:=
n
ewLoggingResponseWriter
(
ow
)
w
:=
helper
.
N
ewLoggingResponseWriter
(
ow
)
defer
w
.
Log
(
r
)
// Drop WebSocket connection and CONNECT method
if
r
.
RequestURI
==
"*"
{
h
ttp
Error
(
&
w
,
r
,
"Connection upgrade not allowed"
,
http
.
StatusBadRequest
)
h
elper
.
HTTP
Error
(
&
w
,
r
,
"Connection upgrade not allowed"
,
http
.
StatusBadRequest
)
return
}
// Disallow connect
if
r
.
Method
==
"CONNECT"
{
h
ttp
Error
(
&
w
,
r
,
"CONNECT not allowed"
,
http
.
StatusBadRequest
)
h
elper
.
HTTP
Error
(
&
w
,
r
,
"CONNECT not allowed"
,
http
.
StatusBadRequest
)
return
}
...
...
@@ -74,7 +74,7 @@ func (u *Upstream) ServeHTTP(ow http.ResponseWriter, r *http.Request) {
URIPath
:=
urlprefix
.
CleanURIPath
(
r
.
URL
.
Path
)
prefix
:=
u
.
URLPrefix
if
!
prefix
.
Match
(
URIPath
)
{
h
ttp
Error
(
&
w
,
r
,
fmt
.
Sprintf
(
"Not found %q"
,
URIPath
),
http
.
StatusNotFound
)
h
elper
.
HTTP
Error
(
&
w
,
r
,
fmt
.
Sprintf
(
"Not found %q"
,
URIPath
),
http
.
StatusNotFound
)
return
}
...
...
@@ -94,18 +94,9 @@ func (u *Upstream) ServeHTTP(ow http.ResponseWriter, r *http.Request) {
if
!
foundService
{
// The protocol spec in git/Documentation/technical/http-protocol.txt
// says we must return 403 if no matching service is found.
h
ttp
Error
(
&
w
,
r
,
"Forbidden"
,
http
.
StatusForbidden
)
h
elper
.
HTTP
Error
(
&
w
,
r
,
"Forbidden"
,
http
.
StatusForbidden
)
return
}
ro
.
handler
.
ServeHTTP
(
&
w
,
r
)
}
func
httpError
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
,
error
string
,
code
int
)
{
if
r
.
ProtoAtLeast
(
1
,
1
)
{
// Force client to disconnect if we render request error
w
.
Header
()
.
Set
(
"Connection"
,
"close"
)
}
http
.
Error
(
w
,
error
,
code
)
}
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