'Write this request to the given transport using content-length to frame
the body.
@param transport: See L{writeTo}.
@return: See L{writeTo}.'

def _writeToBodyProducerContentLength(self, transport):

    self._writeHeaders(transport, networkString(('Content-Length:    %d\r\n' % (self.bodyProducer.length,))))
    finishedConsuming = Deferred()
    encoder = LengthEnforcingConsumer(self.bodyProducer, transport, finishedConsuming)
    transport.registerProducer(self.bodyProducer, True)
    finishedProducing = self.bodyProducer.startProducing(encoder)
    def combine(consuming, producing):
        def cancelConsuming(ign):
            finishedProducing.cancel()
        ultimate = Deferred(cancelConsuming)
        state = [None]
        def ebConsuming(err):
            if (state == [None]):
                state[0] = 1
                ultimate.errback(err)
            else:
                log.err(err, (u'Buggy    state    machine    in    %r/[%d]:    ebConsuming    called' % (self, state[0])))
        def cbProducing(result):
            if (state == [None]):
                state[0] = 2
                try:
                    encoder._noMoreWritesExpected()
                except:
                    ultimate.errback()
                else:
                    ultimate.callback(None)
        def ebProducing(err):
            if (state == [None]):
                state[0] = 3
                encoder._allowNoMoreWrites()
                ultimate.errback(err)
            else:
                log.err(err, u'Producer    is    buggy')
        consuming.addErrback(ebConsuming)
        producing.addCallbacks(cbProducing, ebProducing)
        return ultimate
    d = combine(finishedConsuming, finishedProducing)
    def f(passthrough):
        transport.unregisterProducer()
        return passthrough
    d.addBoth(f)
    return d
