func (r *Response) WriteHeaderAndEntity(status int, value interface{}) error {
	writer, ok := r.EntityWriter()
	if !ok {
		r.WriteHeader(http.StatusNotAcceptable)
		return nil
	}
	return writer.Write(r, status, value)
}
WriteHeaderAndEntity marshals the value using the representation denoted by the Accept Header and the registered EntityWriters.
If no Accept header is specified (or */*) then respond with the Content-Type as specified by the first in the Route.Produces.
If an Accept header is specified then respond with the Content-Type as specified by the first in the Route.Produces that is matched with the Accept header.
If the value is nil then no response is send except for the Http status. You may want to call WriteHeader(http.StatusNotFound) instead.
If there is no writer available that can represent the value in the requested MIME type then Http Status NotAcceptable is written.
Current implementation ignores any q-parameters in the Accept Header.
Returns an error if the value could not be written on the response.
package restful
import (
	"errors"
	"net/http"
)
var DefaultResponseMimeType string
var PrettyPrintResponses = true
type Response struct {
	http.ResponseWriter
	requestAccept string    
	routeProduces []string  
	statusCode    int       
	contentLength int       
	prettyPrint   bool      
	err           error     
}
func NewResponse(httpWriter http.ResponseWriter) *Response {
	return &Response{httpWriter, "", []string{}, http.StatusOK, 0, PrettyPrintResponses, nil}  
}
func DefaultResponseContentType(mime string) {
	DefaultResponseMimeType = mime
}
func (r Response) InternalServerError() Response {
	r.WriteHeader(http.StatusInternalServerError)
	return r
}
func (r *Response) PrettyPrint(bePretty bool) {
	r.prettyPrint = bePretty
}
func (r Response) AddHeader(header string, value string) Response {
	r.Header().Add(header, value)
	return r
}
func (r *Response) SetRequestAccepts(mime string) {
	r.requestAccept = mime
}
func (r *Response) EntityWriter() (EntityReaderWriter, bool) {
	sorted := sortedMimes(r.requestAccept)
	for _, eachAccept := range sorted {
		for _, eachProduce := range r.routeProduces {
			if eachProduce == eachAccept.media {
				if w, ok := entityAccessRegistry.accessorAt(eachAccept.media); ok {
					return w, true
				}
			}
		}
		if eachAccept.media == "*/*" {
			for _, each := range r.routeProduces {
				if w, ok := entityAccessRegistry.accessorAt(each); ok {
					return w, true
				}
			}
		}
	}
	writer, ok := entityAccessRegistry.accessorAt(r.requestAccept)
	if !ok {
		if DefaultResponseMimeType == MIME_JSON {
			return entityAccessRegistry.accessorAt(MIME_JSON)
		}
		if DefaultResponseMimeType == MIME_XML {
			return entityAccessRegistry.accessorAt(MIME_XML)
		}
		for _, each := range r.routeProduces {
			if w, ok := entityAccessRegistry.accessorAt(each); ok {
				return w, true
			}
		}
		if trace {
			traceLogger.Printf("no registered EntityReaderWriter found for %s", r.requestAccept)
		}
	}
	return writer, ok
}
func (r *Response) WriteEntity(value interface{}) error {
	return r.WriteHeaderAndEntity(http.StatusOK, value)
}