Source File
filetransport.go
Belonging Package
net/http
package http
import (
)
type fileTransport struct {
fh fileHandler
}
func ( FileSystem) RoundTripper {
return fileTransport{fileHandler{}}
}
, := newPopulateResponseWriter()
go func() {
.fh.ServeHTTP(, )
.finish()
}()
return <-, nil
}
func () (*populateResponse, <-chan *Response) {
, := io.Pipe()
:= &populateResponse{
ch: make(chan *Response),
pw: ,
res: &Response{
Proto: "HTTP/1.0",
ProtoMajor: 1,
Header: make(Header),
Close: true,
Body: ,
},
}
return , .ch
}
type populateResponse struct {
res *Response
ch chan *Response
wroteHeader bool
hasContent bool
sentResponse bool
pw *io.PipeWriter
}
func ( *populateResponse) () {
if !.wroteHeader {
.WriteHeader(500)
}
if !.sentResponse {
.sendResponse()
}
.pw.Close()
}
func ( *populateResponse) () {
if .sentResponse {
return
}
.sentResponse = true
if .hasContent {
.res.ContentLength = -1
}
.ch <- .res
}
func ( *populateResponse) () Header {
return .res.Header
}
func ( *populateResponse) ( int) {
if .wroteHeader {
return
}
.wroteHeader = true
.res.StatusCode =
.res.Status = fmt.Sprintf("%d %s", , StatusText())
}
func ( *populateResponse) ( []byte) ( int, error) {
if !.wroteHeader {
.WriteHeader(StatusOK)
}
.hasContent = true
if !.sentResponse {
.sendResponse()
}
return .pw.Write()
![]() |
The pages are generated with Golds v0.3.2-preview. (GOOS=darwin GOARCH=amd64) Golds is a Go 101 project developed by Tapir Liu. PR and bug reports are welcome and can be submitted to the issue list. Please follow @Go100and1 (reachable from the left QR code) to get the latest news of Golds. |