Last active
December 6, 2015 02:05
-
-
Save roothybrid7/bd53e469845045ec6adc to your computer and use it in GitHub Desktop.
Golangで、ResponseWriterを使ってHTTPレスポンスを組み立てる際にハマったこと ref: http://qiita.com/roothybrid7/items/34578037d883c9a99ca8
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// A ResponseWriter interface is used by an HTTP handler to | |
// construct an HTTP response. | |
type ResponseWriter interface { | |
// Header returns the header map that will be sent by WriteHeader. | |
// Changing the header after a call to WriteHeader (or Write) has | |
// no effect. | |
Header() Header | |
// Write writes the data to the connection as part of an HTTP reply. | |
// If WriteHeader has not yet been called, Write calls WriteHeader(http.StatusOK) | |
// before writing the data. If the Header does not contain a | |
// Content-Type line, Write adds a Content-Type set to the result of passing | |
// the initial 512 bytes of written data to DetectContentType. | |
Write([]byte) (int, error) | |
// WriteHeader sends an HTTP response header with status code. | |
// If WriteHeader is not called explicitly, the first call to Write | |
// will trigger an implicit WriteHeader(http.StatusOK). | |
// Thus explicit calls to WriteHeader are mainly used to | |
// send error codes. | |
WriteHeader(int) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment