예제 #1
0
//FormParser parse the url query variables and Body of a request.
//If parsing is succesful then the data can be retrieved via pelau.Request.Get()
func FormParser(req pelau.Request, res pelau.Response, ctx *pelau.Context) {

	req.Raw(func(modReq *pelau.ModifiedRequest) {

		err := modReq.ParseForm()

		if err != nil {

			req.Error(err, nil)

		}

		ctx.Next(req, res, ctx)

	})

}
예제 #2
0
func handler(req pelau.Request, res pelau.Response) {

	fmt.Printf("[%s] request detected on path %s.\n", req.Raw().Method, req.Raw().URL.Path)
	fmt.Printf("Printing Submatches: %v\n", req.Params())
	res.Head("X-Men", "Was a good show")
	//	res.Header("Content-Type", "application/json")
	res.Send(struct{ FIELD string }{"NAME"})

}
				f = func(req pelau.Request) {

					Expect(req.Value("first")).To(Equal("1"))

				}
				http.PostForm(server.URL, url.Values{"first": {"1"}})

			})
		})

	})

	Describe("request uri params", func() {

		var req pelau.Request
		BeforeEach(func() {

			mreq := pelau.ModifiedRequest{}

			mreq.Params = []string{"wholeurl", "m1", "m2"}

			req = pelau.DefaultRequest(&mreq)
		})

		It("should provide matches from the regex applied to the url", func() {

			Expect(req.Param(0)).To(Equal("wholeurl"))
			Expect(req.Param(2)).To(Equal("m2"))
		})