'Write some data as a result of an HTTP request.  The first
time this is called, it writes out response data.
@type data: C{bytes}
@param data: Some bytes to be sent as part of the response body.'

def write(self, data):

    if self.finished:
        raise RuntimeError('Request.write    called    on    a    request    after    Request.finish    was    called.')
    if (not self.startedWriting):
        self.startedWriting = 1
        version = self.clientproto
        code = intToBytes(self.code)
        reason = self.code_message
        headers = []
        if ((version == 'HTTP/1.1') and (self.responseHeaders.getRawHeaders('content-length') is None) and (self.method != 'HEAD') and (self.code not in NO_BODY_CODES)):
            headers.append(('Transfer-Encoding', 'chunked'))
            self.chunked = 1
        if (self.lastModified is not None):
            if self.responseHeaders.hasHeader('last-modified'):
                log.msg('Warning:    last-modified    specified    both    in    header    list    and    lastModified    attribute.')
            else:
                self.responseHeaders.setRawHeaders('last-modified', [datetimeToString(self.lastModified)])
        if (self.etag is not None):
            self.responseHeaders.setRawHeaders('ETag', [self.etag])
        for (name, values) in self.responseHeaders.getAllRawHeaders():
            for value in values:
                if (not isinstance(value, bytes)):
                    warnings.warn('Passing    non-bytes    header    values    is    deprecated    since    Twisted    12.3.    Pass    only    bytes    instead.', category=DeprecationWarning, stacklevel=2)
                    value = networkString(('%s' % (value,)))
                headers.append((name, value))
        for cookie in self.cookies:
            headers.append(('Set-Cookie', cookie))
        self.channel.writeHeaders(version, code, reason, headers)
        if (self.method == 'HEAD'):
            self.write = (lambda data: None)
            return
        if (self.code in NO_BODY_CODES):
            self.write = (lambda data: None)
            return
    self.sentLength = (self.sentLength + len(data))
    if data:
        if self.chunked:
            self.channel.writeSequence(toChunk(data))
        else:
            self.channel.write(data)
