[mod_python] Can't get a 206 (partial content) response

Graham Dumpleton graham.dumpleton at gmail.com
Mon Jul 2 23:11:56 EDT 2007


On 03/07/07, sliderw hotmail <sliderw at hotmail.com> wrote:
> I have this PythonHandler running on Apache 2.2.2 with mod_python 3.3.1:
>
> def handler(req):
>     req.headers_out["Content-Range"] = "bytes 0-9/1234"
>     req.set_content_length(10)
>     req.write("x" * 10)
>     return apache.HTTP_PARTIAL_CONTENT
>
> When I hit the URL, I expect the HTTP response code to be 206, but it is
> actually 200.
>
> Am I doing something wrong?

Use:

  def handler(req):
      req.status = apache.HTTP_PARTIAL_CONTENT
      req.headers_out["Content-Range"] = "bytes 0-9/1234"
      req.set_content_length(10)
      req.write("x" * 10)
      return apache.OK

Calling req.write() flushes the response code and headers, so need to
supply status through req.status.

Graham


More information about the Mod_python mailing list