예제 #1
0
func http_test(request *cocaine.Request, response *cocaine.Response) {
	req := cocaine.UnpackProxyRequest(<-request.Read())
	response.Write(cocaine.WriteHead(200, [][2]string{{"Content-Type", "text/html"}}))
	ans := fmt.Sprintf("Method: %s, Uri: %s, UA: %s", req.Method, req.URL, req.UserAgent())
	response.Write(ans)
	response.Close()
}
예제 #2
0
func on_http_generate(request *cocaine.Request, response *cocaine.Response) {
	defer response.Close()
	r, err := cocaine.UnpackProxyRequest(<-request.Read())
	if err != nil {
		response.ErrorMsg(-200, err.Error())
		return
	}

	message := r.FormValue("message")
	if len(message) == 0 {
		response.Write(cocaine.WriteHead(http.StatusBadRequest, ErrorHeaders))
		response.Write("Missing argument `message`")
		return
	}

	png, err := qenerate(message)
	if err != nil {
		response.Write(cocaine.WriteHead(http.StatusInternalServerError, ErrorHeaders))
		response.Write("Unable to generate QR")
		return
	}

	response.Write(cocaine.WriteHead(http.StatusOK, OkHeaders))
	response.Write(png)
}