Code

Opened 22 months ago

Last modified 6 days ago

#18523 assigned New feature

Add getvalue to HttpResponse

Reported by: claudep Owned by: Osmose
Component: HTTP handling Version: master
Severity: Normal Keywords:
Cc: Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

The HttpResponse object can almost be used as another stream object. Unfortunately, it doesn't offer the getvalue() method to be able to read its content, hence requiring conditional code in some circonstances (see #15197). What about adding it (HttpResponse.getvalue() === HttpResponse.content)?

Attachments (0)

Change History (4)

comment:1 Changed 22 months ago by aaugustin

  • Triage Stage changed from Unreviewed to Accepted

Good idea.

Do Python's docs provide a list of the methods that a "stream object" must support? While we're there, we should also check that HttpRequest objects support all the methods that make sense.

comment:2 Changed 22 months ago by claudep

Version 0, edited 22 months ago by claudep (next)

comment:3 Changed 6 months ago by unaizalakain

I would add the following attributes and methods:

  • HttpResponseBase.closed: set to False in __init__, set to True in close()
  • HttpResponseBase.writable(): returns False because write(content) raises an exception (should be changed to IOError BTW)
  • HttpResponseBase.writelines(lines): raises IOError
  • HttpResponseBase.tell(): change it to raise IOError
  • HttpResponse.getvalue(): returns self.content
  • HttpResponse.writelines(lines): writes each line with self.write(line)

comment:4 Changed 6 days ago by Osmose

  • Has patch set
  • Owner changed from nobody to Osmose
  • Status changed from new to assigned

I submitted a PR with the changes mentioned in comment:3 here: https://github.com/django/django/pull/2545 . If we think that all of the stuff from io.IOBase should be included, I can update my PR with the rest.

Last edited 6 days ago by Osmose (previous) (diff)

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as assigned
The owner will be changed from Osmose to anonymous. Next status will be 'assigned'
The ticket will be disowned. Next status will be 'new'
as The resolution will be set. Next status will be 'closed'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.