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
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
iv
gitlab-workhorse
Commits
244e1b98
Commit
244e1b98
authored
Dec 18, 2015
by
Jacob Vosmaer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Create internal/errorpage package
parent
14cdbd60
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
20 additions
and
16 deletions
+20
-16
deploy_page.go
deploy_page.go
+2
-1
error_pages_test.go
error_pages_test.go
+3
-2
helpers.go
helpers.go
+0
-6
internal/errorpage/error_pages.go
internal/errorpage/error_pages.go
+6
-5
internal/helper/helpers.go
internal/helper/helpers.go
+6
-0
main.go
main.go
+3
-2
No files found.
deploy_page.go
View file @
244e1b98
package
main
import
(
"./internal/helper"
"io/ioutil"
"net/http"
"path/filepath"
...
...
@@ -15,7 +16,7 @@ func handleDeployPage(documentRoot *string, handler http.Handler) http.HandlerFu
return
}
s
etNoCacheHeaders
(
w
.
Header
())
helper
.
S
etNoCacheHeaders
(
w
.
Header
())
w
.
Header
()
.
Set
(
"Content-Type"
,
"text/html; charset=utf-8"
)
w
.
WriteHeader
(
http
.
StatusOK
)
w
.
Write
(
data
)
...
...
error_pages_test.go
View file @
244e1b98
package
main
import
(
"./internal/errorpage"
"fmt"
"io/ioutil"
"net/http"
...
...
@@ -25,7 +26,7 @@ func TestIfErrorPageIsPresented(t *testing.T) {
w
.
WriteHeader
(
404
)
fmt
.
Fprint
(
w
,
"Not Found"
)
})
handleRailsError
(
&
dir
,
h
)(
w
,
nil
)
errorpage
.
Inject
(
dir
,
h
)(
w
,
nil
)
w
.
Flush
()
assertResponseCode
(
t
,
w
,
404
)
...
...
@@ -45,7 +46,7 @@ func TestIfErrorPassedIfNoErrorPageIsFound(t *testing.T) {
w
.
WriteHeader
(
404
)
fmt
.
Fprint
(
w
,
errorResponse
)
})
handleRailsError
(
&
dir
,
h
)(
w
,
nil
)
errorpage
.
Inject
(
dir
,
h
)(
w
,
nil
)
w
.
Flush
()
assertResponseCode
(
t
,
w
,
404
)
...
...
helpers.go
View file @
244e1b98
...
...
@@ -54,12 +54,6 @@ func cleanUpProcessGroup(cmd *exec.Cmd) {
cmd
.
Wait
()
}
func
setNoCacheHeaders
(
header
http
.
Header
)
{
header
.
Set
(
"Cache-Control"
,
"no-cache, no-store, max-age=0, must-revalidate"
)
header
.
Set
(
"Pragma"
,
"no-cache"
)
header
.
Set
(
"Expires"
,
"Fri, 01 Jan 1990 00:00:00 GMT"
)
}
// Borrowed from: net/http/server.go
// Return the canonical path for p, eliminating . and .. elements.
func
cleanURIPath
(
p
string
)
string
{
...
...
error_pages.go
→
internal/errorpage/
error_pages.go
View file @
244e1b98
package
main
package
errorpage
import
(
"../helper"
"fmt"
"io/ioutil"
"log"
...
...
@@ -12,7 +13,7 @@ type errorPageResponseWriter struct {
rw
http
.
ResponseWriter
status
int
hijacked
bool
path
*
string
path
string
}
func
(
s
*
errorPageResponseWriter
)
Header
()
http
.
Header
{
...
...
@@ -37,14 +38,14 @@ func (s *errorPageResponseWriter) WriteHeader(status int) {
s
.
status
=
status
if
400
<=
s
.
status
&&
s
.
status
<=
599
{
errorPageFile
:=
filepath
.
Join
(
*
s
.
path
,
fmt
.
Sprintf
(
"%d.html"
,
s
.
status
))
errorPageFile
:=
filepath
.
Join
(
s
.
path
,
fmt
.
Sprintf
(
"%d.html"
,
s
.
status
))
// check if custom error page exists, serve this page instead
if
data
,
err
:=
ioutil
.
ReadFile
(
errorPageFile
);
err
==
nil
{
s
.
hijacked
=
true
log
.
Printf
(
"ErrorPage: serving predefined error page: %d"
,
s
.
status
)
s
etNoCacheHeaders
(
s
.
rw
.
Header
())
helper
.
S
etNoCacheHeaders
(
s
.
rw
.
Header
())
s
.
rw
.
Header
()
.
Set
(
"Content-Type"
,
"text/html; charset=utf-8"
)
s
.
rw
.
WriteHeader
(
s
.
status
)
s
.
rw
.
Write
(
data
)
...
...
@@ -59,7 +60,7 @@ func (s *errorPageResponseWriter) Flush() {
s
.
WriteHeader
(
http
.
StatusOK
)
}
func
handleRailsError
(
documentRoot
*
string
,
handler
http
.
Handler
)
http
.
HandlerFunc
{
func
Inject
(
documentRoot
string
,
handler
http
.
Handler
)
http
.
HandlerFunc
{
return
func
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
rw
:=
errorPageResponseWriter
{
rw
:
w
,
...
...
internal/helper/helpers.go
View file @
244e1b98
...
...
@@ -16,6 +16,12 @@ func LogError(err error) {
log
.
Printf
(
"error: %v"
,
err
)
}
func
SetNoCacheHeaders
(
header
http
.
Header
)
{
header
.
Set
(
"Cache-Control"
,
"no-cache, no-store, max-age=0, must-revalidate"
)
header
.
Set
(
"Pragma"
,
"no-cache"
)
header
.
Set
(
"Expires"
,
"Fri, 01 Jan 1990 00:00:00 GMT"
)
}
func
OpenFile
(
path
string
)
(
file
*
os
.
File
,
fi
os
.
FileInfo
,
err
error
)
{
file
,
err
=
os
.
Open
(
path
)
if
err
!=
nil
{
...
...
main.go
View file @
244e1b98
...
...
@@ -14,6 +14,7 @@ In this file we start the web server and hand off to the upstream type.
package
main
import
(
"./internal/errorpage"
"flag"
"fmt"
"log"
...
...
@@ -95,7 +96,7 @@ func compileRoutes(u *upstream) {
u
.
handleServeFile
(
documentRoot
,
CacheExpireMax
,
handleDevelopmentMode
(
developmentMode
,
handleDeployPage
(
documentRoot
,
handleRailsError
(
documentRoot
,
errorpage
.
Inject
(
*
documentRoot
,
proxy
,
),
),
...
...
@@ -107,7 +108,7 @@ func compileRoutes(u *upstream) {
httpRoute
{
""
,
nil
,
u
.
handleServeFile
(
documentRoot
,
CacheDisabled
,
handleDeployPage
(
documentRoot
,
handleRailsError
(
documentRoot
,
errorpage
.
Inject
(
*
documentRoot
,
proxy
,
),
),
...
...
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