Skip to content

Include Daniel's ResponseWriter delegate type. #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions contributor/responsewriter_delegator.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
Copyright (c) 2013, Matt T. Proud
All rights reserved.

Use of this source code is governed by a BSD-style license that can be found in
the LICENSE file.
*/

package contributor

import (
"net/http"
"strconv"
)

const (
unknownStatusCode = "unknown"
)

// ResponseWriterDelegator is a means of wrapping http.ResponseWriter to divine
// the response code from a given answer, especially in systems where the
// response is treated as a blackbox.
type ResponseWriterDelegator struct {
http.ResponseWriter
Status *string
}

func (r ResponseWriterDelegator) WriteHeader(code int) {
*r.Status = strconv.Itoa(code)

r.ResponseWriter.WriteHeader(code)
}

func NewResponseWriterDelegator(delegate http.ResponseWriter) ResponseWriterDelegator {
defaultStatusCode := unknownStatusCode

return ResponseWriterDelegator{delegate, &defaultStatusCode}
}