Ticket #4017 enhancement closed fixed

Opened 4 years ago

Last modified 2 years ago

Add an IBodyProducer which produces bytes from a file-like object

Reported by: exarkun Owned by: exarkun
Priority: normal Milestone:
Component: web Keywords: httpclient IBodyProducer
Cc: Branch: branches/filebodyproducer-4017-2
(diff, github, buildbot, log)
Author: exarkun Launchpad Bug:

Description (last modified by exarkun) (diff)

#886 introduces an HTTP client API along with a new interface, IBodyProducer, for providing request bodies in a streaming manner. This interface isn't quite the same as IProducer, so existing producers don't quite work with it.

For convenience, we should provide an implementation of this interface based on file-like objects (along the lines of twisted.protocols.basic.FileSender). This will be useful both for the obvious reason (sending files as request bodies), as well as as an example of how to implement these, and will also be usable with StringIO instances to send data constructed in memory (eg simple form posts).

Change History

1

Changed 4 years ago by ivank

  • keywords IBodyProducer added

2

Changed 4 years ago by exarkun

  • keywords httpclient added

3

Changed 2 years ago by <automation>

  • owner exarkun deleted

4

Changed 2 years ago by djfroofy

  • status changed from new to assigned
  • owner set to djfroofy

5

Changed 2 years ago by exarkun

  • branch set to branches/filebodyproducer-4017
  • branch_author set to exarkun

(In [32067]) Branching to 'filebodyproducer-4017'

6

Changed 2 years ago by exarkun

  • owner djfroofy deleted
  • status changed from assigned to new
  • keywords review added

I took a crack at this because I thought it would be quick and easy. Oh well, I've certainly done worse than none out of two before.

Please find FileBodyProducer, tests, docs, and an example in the linked branch. Here are the  build results.

7

Changed 2 years ago by exarkun

  • description modified (diff)
  • summary changed from Add an IEntityBodyProducer which produces bytes from a file-like object to Add an IBodyProducer which produces bytes from a file-like object

8

Changed 2 years ago by exarkun

One possible change that should be made to this code is that the producer should take responsibility for closing the file after it finishes reading from it or if stopProducing is called.

9

Changed 2 years ago by therve

  • owner set to exarkun
  • Instead of keeping a reference to the the cooperator object, you may only keep one to the cooperate method. It would prevent the need of that comment about the task module.
  • I don't have a really strong feeling for closing the file or not, but whatever you choose, it should be mentioned in the documentation (both the docstring and the howto).

Please merge!

10

Changed 2 years ago by therve

  • keywords review removed

11

Changed 2 years ago by exarkun

(In [32154]) Address review feedback, plus

  • add docstrings to some test helpers
  • use the bound cooperate method instead of a Cooperator instance/cooperator module
  • close the input file when the FileBodyProducer is done with it (and update docs)

refs #4017

12

Changed 2 years ago by exarkun

  • branch changed from branches/filebodyproducer-4017 to branches/filebodyproducer-4017-2

(In [32155]) Branching to 'filebodyproducer-4017-2'

13

Changed 2 years ago by exarkun

  • status changed from new to closed
  • resolution set to fixed

(In [32157]) Merge filebodyproducer-4017-2

Author: exarkun Reviewer: therve Fixes: #4017

Add twisted.web.client.FileBodyProducer for use with Agent to specify request bodies based on file-like objects.

Note: See TracTickets for help on using tickets.