Example #1
0
 def close(self):
     if not self.headers_sent:
         self.send_headers()
     if self.chunked:
         # Sending an empty chunk signals the end of the
         # response and prematurely closes the response
         util.write_chunk(self.sock, b"")
Example #2
0
    def send(self):
        # send headers
        resp_head = [
            "HTTP/1.1 %s\r\n" % self.status,
            "Server: %s\r\n" % self.SERVER_VERSION,
            "Date: %s\r\n" % http_date(),
            "Connection: close\r\n"
        ]
        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
            write(self._sock, chunk, self.chunked)
            
        if self.chunked:
                # send last chunk
                write_chunk(self._sock, "")

        close(self._sock)

        if hasattr(self.data, "close"):
            self.data.close()
Example #3
0
 def close(self):
     if not self.headers_sent:
         self.send_headers()
     if self.chunked:
         util.write_chunk(self.sock, b"")
Example #4
0
 def close(self):
     if not self.headers_sent:
         self.send_headers()
     if self.chunked:
         util.write_chunk(self.sock, b"")
Example #5
0
 def close(self):
     if self.chunked:
         write_chunk(self.socket, "")