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
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
package
main
import
(
import
(
"./internal/helper"
"io/ioutil"
"io/ioutil"
"net/http"
"net/http"
"path/filepath"
"path/filepath"
...
@@ -15,7 +16,7 @@ func handleDeployPage(documentRoot *string, handler http.Handler) http.HandlerFu
...
@@ -15,7 +16,7 @@ func handleDeployPage(documentRoot *string, handler http.Handler) http.HandlerFu
return
return
}
}
s
etNoCacheHeaders
(
w
.
Header
())
helper
.
S
etNoCacheHeaders
(
w
.
Header
())
w
.
Header
()
.
Set
(
"Content-Type"
,
"text/html; charset=utf-8"
)
w
.
Header
()
.
Set
(
"Content-Type"
,
"text/html; charset=utf-8"
)
w
.
WriteHeader
(
http
.
StatusOK
)
w
.
WriteHeader
(
http
.
StatusOK
)
w
.
Write
(
data
)
w
.
Write
(
data
)
...
...
error_pages_test.go
View file @
244e1b98
package
main
package
main
import
(
import
(
"./internal/errorpage"
"fmt"
"fmt"
"io/ioutil"
"io/ioutil"
"net/http"
"net/http"
...
@@ -25,7 +26,7 @@ func TestIfErrorPageIsPresented(t *testing.T) {
...
@@ -25,7 +26,7 @@ func TestIfErrorPageIsPresented(t *testing.T) {
w
.
WriteHeader
(
404
)
w
.
WriteHeader
(
404
)
fmt
.
Fprint
(
w
,
"Not Found"
)
fmt
.
Fprint
(
w
,
"Not Found"
)
})
})
handleRailsError
(
&
dir
,
h
)(
w
,
nil
)
errorpage
.
Inject
(
dir
,
h
)(
w
,
nil
)
w
.
Flush
()
w
.
Flush
()
assertResponseCode
(
t
,
w
,
404
)
assertResponseCode
(
t
,
w
,
404
)
...
@@ -45,7 +46,7 @@ func TestIfErrorPassedIfNoErrorPageIsFound(t *testing.T) {
...
@@ -45,7 +46,7 @@ func TestIfErrorPassedIfNoErrorPageIsFound(t *testing.T) {
w
.
WriteHeader
(
404
)
w
.
WriteHeader
(
404
)
fmt
.
Fprint
(
w
,
errorResponse
)
fmt
.
Fprint
(
w
,
errorResponse
)
})
})
handleRailsError
(
&
dir
,
h
)(
w
,
nil
)
errorpage
.
Inject
(
dir
,
h
)(
w
,
nil
)
w
.
Flush
()
w
.
Flush
()
assertResponseCode
(
t
,
w
,
404
)
assertResponseCode
(
t
,
w
,
404
)
...
...
helpers.go
View file @
244e1b98
...
@@ -54,12 +54,6 @@ func cleanUpProcessGroup(cmd *exec.Cmd) {
...
@@ -54,12 +54,6 @@ func cleanUpProcessGroup(cmd *exec.Cmd) {
cmd
.
Wait
()
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
// Borrowed from: net/http/server.go
// Return the canonical path for p, eliminating . and .. elements.
// Return the canonical path for p, eliminating . and .. elements.
func
cleanURIPath
(
p
string
)
string
{
func
cleanURIPath
(
p
string
)
string
{
...
...
error_pages.go
→
internal/errorpage/
error_pages.go
View file @
244e1b98
package
main
package
errorpage
import
(
import
(
"../helper"
"fmt"
"fmt"
"io/ioutil"
"io/ioutil"
"log"
"log"
...
@@ -12,7 +13,7 @@ type errorPageResponseWriter struct {
...
@@ -12,7 +13,7 @@ type errorPageResponseWriter struct {
rw
http
.
ResponseWriter
rw
http
.
ResponseWriter
status
int
status
int
hijacked
bool
hijacked
bool
path
*
string
path
string
}
}
func
(
s
*
errorPageResponseWriter
)
Header
()
http
.
Header
{
func
(
s
*
errorPageResponseWriter
)
Header
()
http
.
Header
{
...
@@ -37,14 +38,14 @@ func (s *errorPageResponseWriter) WriteHeader(status int) {
...
@@ -37,14 +38,14 @@ func (s *errorPageResponseWriter) WriteHeader(status int) {
s
.
status
=
status
s
.
status
=
status
if
400
<=
s
.
status
&&
s
.
status
<=
599
{
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
// check if custom error page exists, serve this page instead
if
data
,
err
:=
ioutil
.
ReadFile
(
errorPageFile
);
err
==
nil
{
if
data
,
err
:=
ioutil
.
ReadFile
(
errorPageFile
);
err
==
nil
{
s
.
hijacked
=
true
s
.
hijacked
=
true
log
.
Printf
(
"ErrorPage: serving predefined error page: %d"
,
s
.
status
)
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
.
Header
()
.
Set
(
"Content-Type"
,
"text/html; charset=utf-8"
)
s
.
rw
.
WriteHeader
(
s
.
status
)
s
.
rw
.
WriteHeader
(
s
.
status
)
s
.
rw
.
Write
(
data
)
s
.
rw
.
Write
(
data
)
...
@@ -59,7 +60,7 @@ func (s *errorPageResponseWriter) Flush() {
...
@@ -59,7 +60,7 @@ func (s *errorPageResponseWriter) Flush() {
s
.
WriteHeader
(
http
.
StatusOK
)
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
)
{
return
func
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
rw
:=
errorPageResponseWriter
{
rw
:=
errorPageResponseWriter
{
rw
:
w
,
rw
:
w
,
...
...
internal/helper/helpers.go
View file @
244e1b98
...
@@ -16,6 +16,12 @@ func LogError(err error) {
...
@@ -16,6 +16,12 @@ func LogError(err error) {
log
.
Printf
(
"error: %v"
,
err
)
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
)
{
func
OpenFile
(
path
string
)
(
file
*
os
.
File
,
fi
os
.
FileInfo
,
err
error
)
{
file
,
err
=
os
.
Open
(
path
)
file
,
err
=
os
.
Open
(
path
)
if
err
!=
nil
{
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.
...
@@ -14,6 +14,7 @@ In this file we start the web server and hand off to the upstream type.
package
main
package
main
import
(
import
(
"./internal/errorpage"
"flag"
"flag"
"fmt"
"fmt"
"log"
"log"
...
@@ -95,7 +96,7 @@ func compileRoutes(u *upstream) {
...
@@ -95,7 +96,7 @@ func compileRoutes(u *upstream) {
u
.
handleServeFile
(
documentRoot
,
CacheExpireMax
,
u
.
handleServeFile
(
documentRoot
,
CacheExpireMax
,
handleDevelopmentMode
(
developmentMode
,
handleDevelopmentMode
(
developmentMode
,
handleDeployPage
(
documentRoot
,
handleDeployPage
(
documentRoot
,
handleRailsError
(
documentRoot
,
errorpage
.
Inject
(
*
documentRoot
,
proxy
,
proxy
,
),
),
),
),
...
@@ -107,7 +108,7 @@ func compileRoutes(u *upstream) {
...
@@ -107,7 +108,7 @@ func compileRoutes(u *upstream) {
httpRoute
{
""
,
nil
,
httpRoute
{
""
,
nil
,
u
.
handleServeFile
(
documentRoot
,
CacheDisabled
,
u
.
handleServeFile
(
documentRoot
,
CacheDisabled
,
handleDeployPage
(
documentRoot
,
handleDeployPage
(
documentRoot
,
handleRailsError
(
documentRoot
,
errorpage
.
Inject
(
*
documentRoot
,
proxy
,
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