def do_PUT(self): # The URL path is the key key = self.path # Reject values that are too long contentLength = int(self.headers['Content-Length']) if contentLength <= 0 or contentLength > MAX_CONTENT_LENGHT: self.respond(400, "text/html", "Content body too large") return # The value is the body of the PUT request value = self.rfile.read(contentLength) # Defer to NodeCore result = node.do_put(key, value) # Take action depending on NodeCore decision if isinstance(result, ValueStored): self.respond(200, "application/octet-stream", "") elif isinstance(result, ForwardRequest): node_request.sendPUT(result.destination, node_httpserver_port, key, value) self.respond(200, "application/octet-stream", "") else: raise Exception("Unknown result command: " + pformat(result))
def sendPUT(self, key, value, size): self.size = self.size + size node = random.choice(storageBackendNodes) node_request.sendPUT(node, node_httpserver_port, key, value)