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
1366a446
Commit
1366a446
authored
Jul 25, 2017
by
Matt Holt
Committed by
GitHub
Jul 25, 2017
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #1780 from sergeyfrolov/master
httpserver: Encapsulate WriteSiteNotFound error
parents
b63d9fdc
ea245b5a
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
14 additions
and
1 deletion
+14
-1
caddyhttp/httpserver/server.go
caddyhttp/httpserver/server.go
+14
-1
No files found.
caddyhttp/httpserver/server.go
View file @
1366a446
...
@@ -366,7 +366,7 @@ func (s *Server) serveHTTP(w http.ResponseWriter, r *http.Request) (int, error)
...
@@ -366,7 +366,7 @@ func (s *Server) serveHTTP(w http.ResponseWriter, r *http.Request) (int, error)
if
err
!=
nil
{
if
err
!=
nil
{
remoteHost
=
r
.
RemoteAddr
remoteHost
=
r
.
RemoteAddr
}
}
Write
TextResponse
(
w
,
http
.
StatusNotFound
,
"No such site at "
+
s
.
Server
.
Addr
)
Write
SiteNotFound
(
w
,
r
)
// don't add headers outside of this function
log
.
Printf
(
"[INFO] %s - No such site at %s (Remote: %s, Referer: %s)"
,
log
.
Printf
(
"[INFO] %s - No such site at %s (Remote: %s, Referer: %s)"
,
hostname
,
s
.
Server
.
Addr
,
remoteHost
,
r
.
Header
.
Get
(
"Referer"
))
hostname
,
s
.
Server
.
Addr
,
remoteHost
,
r
.
Header
.
Get
(
"Referer"
))
return
0
,
nil
return
0
,
nil
...
@@ -490,6 +490,19 @@ func DefaultErrorFunc(w http.ResponseWriter, r *http.Request, status int) {
...
@@ -490,6 +490,19 @@ func DefaultErrorFunc(w http.ResponseWriter, r *http.Request, status int) {
WriteTextResponse
(
w
,
status
,
fmt
.
Sprintf
(
"%d %s
\n
"
,
status
,
http
.
StatusText
(
status
)))
WriteTextResponse
(
w
,
status
,
fmt
.
Sprintf
(
"%d %s
\n
"
,
status
,
http
.
StatusText
(
status
)))
}
}
const
httpStatusMisdirectedRequest
=
421
// RFC 7540, 9.1.2
// WriteSiteNotFound writes appropriate error code to w, signaling that
// requested host is not served by Caddy on a given port.
func
WriteSiteNotFound
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
status
:=
http
.
StatusNotFound
if
r
.
ProtoMajor
>=
2
{
// TODO: use http.StatusMisdirectedRequest when it gets defined
status
=
httpStatusMisdirectedRequest
}
WriteTextResponse
(
w
,
status
,
fmt
.
Sprintf
(
"%d Site %s is not served on this interface
\n
"
,
status
,
r
.
Host
))
}
// WriteTextResponse writes body with code status to w. The body will
// WriteTextResponse writes body with code status to w. The body will
// be interpreted as plain text.
// be interpreted as plain text.
func
WriteTextResponse
(
w
http
.
ResponseWriter
,
status
int
,
body
string
)
{
func
WriteTextResponse
(
w
http
.
ResponseWriter
,
status
int
,
body
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