http: Make methods of .Data.Res actually work
This commit is contained in:
@@ -123,9 +123,13 @@ func (this *Handler) serveDocument (
|
||||
|
||||
// execute document
|
||||
data := HTTPData { }
|
||||
data.Res.Header = recorder.Header()
|
||||
data.Res.WriteHeader = recorder.WriteHeader
|
||||
data.Res.Reset = resetRecorder
|
||||
data.Res = WrappedResponseWriter {
|
||||
responseWriter: res,
|
||||
resetFunc: resetRecorder,
|
||||
Header: WrappedHeader {
|
||||
Header: recorder.Header(),
|
||||
},
|
||||
}
|
||||
data.Req = req
|
||||
err = document.Execute(&recorder, step.ExecutionData {
|
||||
Data: data,
|
||||
|
||||
39
http/http.go
39
http/http.go
@@ -8,15 +8,44 @@ import "net/http"
|
||||
// available to templates as they are being executed.
|
||||
type HTTPData struct {
|
||||
// Res is like an http.ResponseWriter.
|
||||
Res struct {
|
||||
Header http.Header
|
||||
WriteHeader func (statusCode int)
|
||||
Reset func ()
|
||||
}
|
||||
Res WrappedResponseWriter
|
||||
// Req is the HTTP request.
|
||||
Req *http.Request
|
||||
}
|
||||
|
||||
type WrappedResponseWriter struct {
|
||||
responseWriter http.ResponseWriter
|
||||
resetFunc func ()
|
||||
Header WrappedHeader
|
||||
}
|
||||
|
||||
func (this WrappedResponseWriter) WriteHeader (statusCode int) string {
|
||||
this.responseWriter.WriteHeader(statusCode)
|
||||
return ""
|
||||
}
|
||||
|
||||
func (this WrappedResponseWriter) Reset () string {
|
||||
this.resetFunc()
|
||||
return ""
|
||||
}
|
||||
|
||||
type WrappedHeader struct { http.Header }
|
||||
|
||||
func (this WrappedHeader) Add (name, value string) string {
|
||||
this.Header.Add(name, value)
|
||||
return ""
|
||||
}
|
||||
|
||||
func (this WrappedHeader) Del (name string) string {
|
||||
this.Header.Del(name)
|
||||
return ""
|
||||
}
|
||||
|
||||
func (this WrappedHeader) Set (name, value string) string {
|
||||
this.Header.Set(name, value)
|
||||
return ""
|
||||
}
|
||||
|
||||
var _ http.ResponseWriter = new(HTTPResponseRecorder)
|
||||
|
||||
// HTTPResponseRecorder is an http.ResponseWriter that can buffer a response to
|
||||
|
||||
Reference in New Issue
Block a user