We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent dfd1f2b commit d5de75aCopy full SHA for d5de75a
web.go
@@ -55,12 +55,16 @@ func (ctx *Context) Abort(status int, body string) {
55
}
56
57
func (ctx *Context) Redirect(status int, url string) {
58
- //note := "<a href=\"%v\">" + statusText[code] + "</a>.\n"
59
-
60
ctx.SetHeader("Location", url, true)
61
ctx.StartResponse(status)
62
- ctx.WriteString("")
+ ctx.WriteString("Redirecting to: " + url)
+}
+
63
+func (ctx *Context) NotFound(message string) {
64
+ ctx.StartResponse(404)
65
+ ctx.WriteString(message)
66
67
68
//Sets a cookie -- duration is the amount of time in seconds. 0 = forever
69
func (ctx *Context) SetCookie(name string, value string, age int64) {
70
if age == 0 {
web_test.go
@@ -111,6 +111,8 @@ func init() {
111
return ""
112
})
113
114
+ Get("/error/notfound/(.*)", func(ctx *Context, message string) { ctx.NotFound(message) })
115
116
Post("/posterror/code/(.*)/(.*)", func(ctx *Context, code string, message string) string {
117
n, _ := strconv.Atoi(code)
118
ctx.Abort(n, message)
@@ -143,6 +145,7 @@ var tests = []Test{
143
145
Test{"GET", "/echo/" + strings.Repeat("0123456789", 100), "", 200, strings.Repeat("0123456789", 100)},
144
146
147
Test{"GET", "/writetest", "", 200, "hello"},
148
+ Test{"GET", "/error/notfound/notfound", "", 404, "notfound"},
149
Test{"GET", "/doesnotexist", "", 404, "Page not found"},
150
Test{"POST", "/doesnotexist", "", 404, "Page not found"},
151
Test{"GET", "/error/code/500", "", 500, statusText[500]},
0 commit comments