MCPcopy Create free account
hub / github.com/EasyIME/PIME / get

Method get

python/python3/tornado/test/curl_httpclient_test.py:33–70  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

31 self.password = password
32
33 def get(self):
34 realm = "test"
35 opaque = "asdf"
36 # Real implementations would use a random nonce.
37 nonce = "1234"
38
39 auth_header = self.request.headers.get("Authorization", None)
40 if auth_header is not None:
41 auth_mode, params = auth_header.split(" ", 1)
42 assert auth_mode == "Digest"
43 param_dict = {}
44 for pair in params.split(","):
45 k, v = pair.strip().split("=", 1)
46 if v[0] == '"' and v[-1] == '"':
47 v = v[1:-1]
48 param_dict[k] = v
49 assert param_dict["realm"] == realm
50 assert param_dict["opaque"] == opaque
51 assert param_dict["nonce"] == nonce
52 assert param_dict["username"] == self.username
53 assert param_dict["uri"] == self.request.path
54 h1 = md5(
55 utf8("%s:%s:%s" % (self.username, realm, self.password))
56 ).hexdigest()
57 h2 = md5(
58 utf8("%s:%s" % (self.request.method, self.request.path))
59 ).hexdigest()
60 digest = md5(utf8("%s:%s:%s" % (h1, nonce, h2))).hexdigest()
61 if digest == param_dict["response"]:
62 self.write("ok")
63 else:
64 self.write("fail")
65 else:
66 self.set_status(401)
67 self.set_header(
68 "WWW-Authenticate",
69 'Digest realm="%s", nonce="%s", opaque="%s"' % (realm, nonce, opaque),
70 )
71
72
73class CustomReasonHandler(RequestHandler):

Callers

nothing calls this directly

Calls 6

utf8Function · 0.90
md5Class · 0.85
splitMethod · 0.80
set_statusMethod · 0.80
set_headerMethod · 0.80
writeMethod · 0.45

Tested by

no test coverage detected