mirror of
https://github.com/frappe/gunicorn.git
synced 2026-01-14 11:09:11 +08:00
change the way we handle last chunk, on't break but instead test if last
was an empty string. So we allows idiot content to send empty string at first.
This commit is contained in:
parent
771d44902a
commit
514a0ba0e3
@ -1,5 +1,7 @@
|
||||
from django.conf.urls.defaults import patterns, url
|
||||
|
||||
urlpatterns = patterns('',
|
||||
url(r'^acsv$', 'testing.views.acsv'),
|
||||
url(r'^$', 'testing.views.home'),
|
||||
)
|
||||
|
||||
)
|
||||
|
||||
@ -1,7 +1,9 @@
|
||||
# Create your views here.
|
||||
|
||||
import csv
|
||||
import os
|
||||
from django import forms
|
||||
from django.http import HttpResponse
|
||||
from django.shortcuts import render_to_response
|
||||
import tempfile
|
||||
|
||||
@ -40,4 +42,19 @@ def home(request):
|
||||
})
|
||||
|
||||
|
||||
|
||||
def acsv(request):
|
||||
rows = [
|
||||
{'a': 1, 'b': 2},
|
||||
{'a': 3, 'b': 3}
|
||||
]
|
||||
|
||||
response = HttpResponse(mimetype='text/csv')
|
||||
response['Content-Disposition'] = 'attachment; filename=report.csv'
|
||||
|
||||
writer = csv.writer(response)
|
||||
writer.writerow(['a', 'b'])
|
||||
|
||||
for r in rows:
|
||||
writer.writerow([r['a'], r['b']])
|
||||
|
||||
return response
|
||||
|
||||
@ -2,5 +2,5 @@
|
||||
from django.conf.urls.defaults import patterns,include
|
||||
|
||||
urlpatterns = patterns('',
|
||||
('^$', include("testing.urls")),
|
||||
)
|
||||
(r'^', include("testing.urls")),
|
||||
)
|
||||
|
||||
@ -170,5 +170,6 @@ class Request(object):
|
||||
self.response_chunked = True
|
||||
if not isinstance(value, basestring):
|
||||
value = str(value)
|
||||
self.response_headers.append((name.title(), value.strip()))
|
||||
self.response_headers.append((name.title(), value.strip()))
|
||||
|
||||
self.start_response_called = True
|
||||
|
||||
@ -30,11 +30,12 @@ class Response(object):
|
||||
resp_head.extend(["%s: %s\r\n" % (n, v) for n, v in self.headers])
|
||||
write(self._sock, "%s\r\n" % "".join(resp_head))
|
||||
|
||||
for chunk in list(self.data):
|
||||
if chunk == "": break
|
||||
last_chunk = None
|
||||
for chunk in self.data:
|
||||
last_chunk = chunk
|
||||
write(self._sock, chunk, self.chunked)
|
||||
|
||||
if self.chunked:
|
||||
if self.chunked and last_chunk != "":
|
||||
# send last chunk
|
||||
write_chunk(self._sock, "")
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user