title: Return data on HTTP upload to sanic server
body: <p>I'm experimenting with uploading data to a <code>sanic</code> web server. To do so I issue a POST request using curl. I try to return some data after the POST request. The rationale behind this is to return some ID now representing the upload on the server side. But this doesn't seem to work. Now I'm wondering: Is my program wrong? Does <code>curl</code> not write the output? Or is this a bug in <code>sanic</code>? Could anyone help me here? Thanks!</p>
  
  <p>Here's the Python program:</p>
  
  <pre><code>import signal
  import asyncio
  import uvloop
  
  import sanic
  
  app = sanic.Sanic(__name__)
  loop = asyncio.get_event_loop()
  server = app.create_server(host="localhost", port=3002)
  task = asyncio.ensure_future(server)
  
  @app.post("/testUpload", stream=True)
  async def api_testUpload(request):
  
      async def doStream(response):
          while True:
              body = await request.stream.get()
              if body is None:
                  break
  
              sanic.response.json({
                  "result": "good!"
              })
  
      return sanic.response.stream(doStream)
  
  signal.signal(signal.SIGINT, lambda s, f: loop.stop())
  try:
      loop.run_forever()
  except:
      loop.stop()
  </code></pre>
  
  <p>You can invoke <code>curl</code> like this:</p>
  
  <pre><code>curl -v --data-binary "@somefile.data" http://localhost:3002/testUpload
  </code></pre>
  
  <p>And here is what <code>curl</code> writes to STDOUT:</p>
  
  <pre><code>*   Trying 127.0.0.1...
  * Connected to localhost (127.0.0.1) port 3002 (#0)
  &gt; POST /testUpload HTTP/1.1
  &gt; Host: localhost:3002
  &gt; User-Agent: curl/7.47.0
  &gt; Accept: */*
  &gt; Content-Length: 334504
  &gt; Content-Type: application/x-www-form-urlencoded
  &gt; Expect: 100-continue
  &gt; 
  &lt; HTTP/1.1 200 OK
  &lt; Keep-Alive: 5
  &lt; Transfer-Encoding: chunked
  &lt; Content-Type: text/plain; charset=utf-8
  &lt; 
  * Done waiting for 100-continue
  * We are completely uploaded and fine
  * Connection #0 to host localhost left intact
  </code></pre>
  
  <p>As you can see, a <code>text/plain</code> response is generated. This should be an <code>application/json</code> with my data, shouldn't it?</p>