示例#1
0
 def _extents(self, resp, context):
     # Older daemon considered "/extents" as part of the ticket id, and will
     # fail to authorize the request.
     if "extents" not in self.features:
         raise http.Error(http.FORBIDDEN, "No extents for you!")
     if context not in self.extents:
         raise http.Error(http.NOT_FOUND, "No dirty extents for you!")
     log.debug("EXTENTS context=%s", context)
     resp.send_json(self.extents[context])
示例#2
0
 def put(self, req, resp, name):
     count = req.content_length
     with open("/dev/null", "wb") as f:
         while count:
             with req.clock.run("read"):
                 chunk = req.read(1024 * 1024)
             if not chunk:
                 raise http.Error(400, "Client disconnected")
             with req.clock.run("write"):
                 f.write(chunk)
             count -= len(chunk)
示例#3
0
 def patch(self, req, resp, path=None):
     """
     Implement PATCH/zero and PATCH/flush.
     """
     self.requests += 1
     msg = json.loads(req.read())
     if msg["op"] == "zero":
         self._zero(msg)
     elif msg["op"] == "flush":
         self._flush()
     else:
         raise http.Error(http.BAD_REQUEST, "Invalid PATCH request")
示例#4
0
    def put(self, req, resp, ticket):
        if req.headers.get("expect") == "100-continue":
            resp.send_info(http.CONTINUE)

        count = req.content_length
        resp.headers["content-length"] = count

        while count:
            with req.clock.run("read"):
                chunk = req.read(1024 * 1024)
            if not chunk:
                raise http.Error(400, "Client disconnected")
            with req.clock.run("write"):
                resp.write(chunk)
            count -= len(chunk)
示例#5
0
    def get(self, req, resp, path=None):
        """
        Implement GET with optional Range header.
        """
        self.requests += 1
        if req.range:
            offset = req.range.first
            size = req.range.last + 1 - offset
            if offset + size > len(self.image):
                raise http.Error(
                    http.REQUESTED_RANGE_NOT_SATISFIABLE,
                    "Invalid content range: offset={} size={} length={}".
                    format(offset, size, len(self.image)))

            resp.status_code = http.PARTIAL_CONTENT
            resp.headers["content-range"] = "bytes {}-{}/{}".format(
                offset, offset + size - 1, len(self.image))
        else:
            offset = 0
            size = len(self.image)
            resp.status_code = http.OK

        resp.headers["content-length"] = size
        self._read(resp, offset, size)
示例#6
0
 def fail(req, resp, tid):
     raise http.Error(http.FORBIDDEN, "Fake error")