Skip to content

Commit a344644

Browse files
author
Michael Hoisie
committed
Context.HasParam renamed to Contetx.GetParam . This either returns an empty string, or the first param for the name
Head requests now receive url params Params
1 parent 450827e commit a344644

File tree

2 files changed

+13
-6
lines changed

2 files changed

+13
-6
lines changed

request.go

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ func (r *Request) parseParams() (err os.Error) {
138138

139139
var query string
140140
switch r.Method {
141-
case "GET":
141+
case "GET", "HEAD":
142142
query = r.URL.RawQuery
143143
case "POST":
144144
if r.Body == nil {
@@ -253,13 +253,18 @@ func (r *Request) parseCookies() (err os.Error) {
253253
return nil
254254
}
255255

256-
func (r *Request) HasParam(name string) bool {
256+
//Returns the first parameter given a name, or an empty string
257+
func (r *Request) GetParam(name string) string {
257258
if r.Params == nil || len(r.Params) == 0 {
258-
return false
259+
return ""
259260
}
260-
_, ok := r.Params[name]
261-
return ok
261+
params, ok := r.Params[name]
262+
if !ok || len(params) == 0 {
263+
return ""
264+
}
265+
return params[0]
262266
}
267+
263268
func (r *Request) HasFile(name string) bool {
264269
if r.Files == nil || len(r.Files) == 0 {
265270
return false

web_test.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,6 @@ func buildTestResponse(buf *bytes.Buffer) *testResponse {
8080
}
8181

8282
func getTestResponse(method string, path string, body string, headers map[string]string) *testResponse {
83-
8483
req := buildTestRequest(method, path, body, headers)
8584
var buf bytes.Buffer
8685

@@ -137,6 +136,7 @@ func init() {
137136
}
138137
return val
139138
})
139+
Get("/getparam", func(ctx *Context) string { return ctx.GetParam("a") })
140140
}
141141

142142
var tests = []Test{
@@ -157,6 +157,8 @@ var tests = []Test{
157157
Test{"POST", "/doesnotexist", "", 404, "Page not found"},
158158
Test{"GET", "/error/code/500", "", 500, statusText[500]},
159159
Test{"POST", "/posterror/code/410/failedrequest", "", 410, "failedrequest"},
160+
Test{"GET", "/getparam?a=abcd", "", 200, "abcd"},
161+
Test{"GET", "/getparam?b=abcd", "", 200, ""},
160162
}
161163

162164
func buildTestRequest(method string, path string, body string, headers map[string]string) *Request {

0 commit comments

Comments
 (0)