'Handle a chunk of input'

def outReceived(self, output):

    if self.handling_headers:
        text = (self.headertext + output)
        headerEnds = []
        for delimiter in ('\n\n', '\r\n\r\n', '\r\r', '\n\r\n'):
            headerend = text.find(delimiter)
            if (headerend != (-1)):
                headerEnds.append((headerend, delimiter))
        if headerEnds:
            self.request.defaultContentType = None
            headerEnds.sort()
            (headerend, delimiter) = headerEnds[0]
            self.headertext = text[:headerend]
            linebreak = delimiter[:(len(delimiter) // 2)]
            headers = self.headertext.split(linebreak)
            for header in headers:
                br = header.find(':    ')
                if (br == (-1)):
                    self._log.error('ignoring    malformed    CGI    header:    {header!r}', header=header)
                else:
                    headerName = header[:br].lower()
                    headerText = header[(br + 2):]
                    if (headerName == 'location'):
                        self.request.setResponseCode(http.FOUND)
                    if (headerName == 'status'):
                        try:
                            statusNum = int(headerText[:3])
                        except:
                            self._log.error('malformed    status    header')
                        else:
                            self.request.setResponseCode(statusNum)
                    elif (headerName.lower() not in ('server', 'date')):
                        self.request.responseHeaders.addRawHeader(headerName, headerText)
            output = text[(headerend + len(delimiter)):]
            self.handling_headers = 0
        if self.handling_headers:
            self.headertext = text
    if (not self.handling_headers):
        self.request.write(output)
