Exemplo n.º 1
0
//adapted from Revel framework BinaryResult.Apply method
func (r *StreamResult) Write(ctx framework.WebContext) error {

	var err error

	// If we have a ReadSeeker, delegate to http.ServeContent
	if rs, ok := r.Reader.(io.ReadSeeker); ok {
		http.ServeContent(ctx, ctx.Req(), r.Name, r.ModTime, rs)

	} else {
		// Else, do a simple io.Copy.

		if r.Length != -1 {
			ctx.Header().Set("Content-Length", strconv.FormatInt(r.Length, 10))
		}

		ctx.WriteHeader(http.StatusOK)
		//TODO: use a mime-type to file extension strategy like Revel does
		//ctx.ContentType("application/octet-stream")
		//ctx.ContentType(ContentTypeByFilename(r.Name))
		_, err = io.Copy(ctx, r.Reader)
	}

	// Close the Reader if we can
	if v, ok := r.Reader.(io.Closer); ok {
		v.Close()
	}

	return err
}
func (this EventController) Test(ctx framework.WebContext) framework.WebResult {

	//note: time.sleep frees the thread and allows other goroutines to execute
	//sending 1000 concurrent requests with AB all complete within 5seconds

	time.Sleep(1 * time.Second)

	fmt.Println(ctx.Header())

	fmt.Println("Test invoked")

	return ctx.Text("test operation")
}
Exemplo n.º 3
0
func (r *RedirectResult) Write(ctx framework.WebContext) error {

	ctx.Header().Set("Location", r.Url)
	ctx.WriteHeader(r.Status)
	return nil
}