// Close the reader and writer connections func (s SecureReadWriteCloser) Close() error { if s.writer != nil { io.Closer(s.writer).Close() } if s.reader != nil { io.Closer(s.reader).Close() } return nil }
// Some assertions around filehandle's applicability func TestTypes(t *testing.T) { _ = os.FileInfo(&FileHandle{}) _ = io.Closer(&FileHandle{}) _ = io.Reader(&FileHandle{}) _ = io.ReaderAt(&FileHandle{}) _ = io.WriterTo(&FileHandle{}) _ = io.Seeker(&FileHandle{}) }
// Read reads from the underlying net.TCPConn func (c *Session) Read() bool { buf := make([]byte, 1024) n, err := c.reader.Read(buf) if n == 0 { c.logf("Connection closed by remote host\n") io.Closer(c.conn).Close() // not sure this is necessary? return false } if err != nil { c.logf("Error reading from socket: %s\n", err) return false } text := string(buf[0:n]) logText := strings.Replace(text, "\n", "\\n", -1) logText = strings.Replace(logText, "\r", "\\r", -1) c.logf("Received %d bytes: '%s'\n", n, logText) c.line += text for strings.Contains(c.line, "\r\n") { line, reply := c.proto.Parse(c.line) c.line = line if reply != nil { c.Write(reply) if reply.Status == 221 { io.Closer(c.conn).Close() return false } } } return true }
// NewReplacer makes a new replacer based on r and rr which // are used for request and response placeholders, respectively. // Request placeholders are created immediately, whereas // response placeholders are not created until Replace() // is invoked. rr may be nil if it is not available. // emptyValue should be the string that is used in place // of empty string (can still be empty string). func NewReplacer(r *http.Request, rr *ResponseRecorder, emptyValue string) Replacer { rb := newLimitWriter(MaxLogBodySize) if r.Body != nil { r.Body = struct { io.Reader io.Closer }{io.TeeReader(r.Body, rb), io.Closer(r.Body)} } return &replacer{ request: r, requestBody: rb, responseRecorder: rr, customReplacements: make(map[string]string), emptyValue: emptyValue, } }
// NewReplacer makes a new replacer based on r and rr which // are used for request and response placeholders, respectively. // Request placeholders are created immediately, whereas // response placeholders are not created until Replace() // is invoked. rr may be nil if it is not available. // emptyValue should be the string that is used in place // of empty string (can still be empty string). func NewReplacer(r *http.Request, rr *ResponseRecorder, emptyValue string) Replacer { rb := newLimitWriter(MaxLogBodySize) if r.Body != nil { r.Body = struct { io.Reader io.Closer }{io.TeeReader(r.Body, rb), io.Closer(r.Body)} } rep := &replacer{ request: r, requestBody: rb, responseRecorder: rr, customReplacements: make(map[string]string), emptyValue: emptyValue, } // Header placeholders (case-insensitive) for header, values := range r.Header { rep.customReplacements["{>"+strings.ToLower(header)+"}"] = strings.Join(values, ",") } return rep }