kopia lustrzana https://github.com/cirospaciari/socketify.py
add CODE_OF_CONDUCT and get_headers
rodzic
fd28873063
commit
a2872a6dee
|
@ -387,6 +387,12 @@ class AppRequest:
|
||||||
self._for_each_header_handler = handler
|
self._for_each_header_handler = handler
|
||||||
lib.uws_req_for_each_header(self.req, uws_req_for_each_header_handler, self._ptr)
|
lib.uws_req_for_each_header(self.req, uws_req_for_each_header_handler, self._ptr)
|
||||||
|
|
||||||
|
def get_headers(self):
|
||||||
|
headers = {}
|
||||||
|
def copy_headers(key, value):
|
||||||
|
headers[key] = value
|
||||||
|
self.for_each_header(copy_headers)
|
||||||
|
return headers
|
||||||
|
|
||||||
def get_header(self, lower_case_header):
|
def get_header(self, lower_case_header):
|
||||||
if isinstance(lower_case_header, str):
|
if isinstance(lower_case_header, str):
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
Subproject commit 39d96d296c279ef1545489c4c79ac476373a68bd
|
Subproject commit 32e366da8d8d0186b5584867500e490159143a22
|
44
src/tests.py
44
src/tests.py
|
@ -18,6 +18,47 @@
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# void uws_res_prepare_for_sendfile(int ssl, uws_res_t *res) {
|
||||||
|
# if (ssl) {
|
||||||
|
# uWS::HttpResponse<true> *uwsRes = (uWS::HttpResponse<true> *)res;
|
||||||
|
# auto pair = uwsRes->getSendBuffer(2);
|
||||||
|
# char *ptr = pair.first;
|
||||||
|
# ptr[0] = '\r';
|
||||||
|
# ptr[1] = '\n';
|
||||||
|
# uwsRes->uncork();
|
||||||
|
# } else {
|
||||||
|
# uWS::HttpResponse<false> *uwsRes = (uWS::HttpResponse<false> *)res;
|
||||||
|
# auto pair = uwsRes->getSendBuffer(2);
|
||||||
|
# char *ptr = pair.first;
|
||||||
|
# ptr[0] = '\r';
|
||||||
|
# ptr[1] = '\n';
|
||||||
|
# uwsRes->uncork();
|
||||||
|
# }
|
||||||
|
# }
|
||||||
|
|
||||||
|
# int uws_res_state(int ssl, uws_res_t *res) {
|
||||||
|
# if (ssl) {
|
||||||
|
# uWS::HttpResponse<true> *uwsRes = (uWS::HttpResponse<true> *)res;
|
||||||
|
# return uwsRes->getHttpResponseData()->state;
|
||||||
|
# } else {
|
||||||
|
# uWS::HttpResponse<false> *uwsRes = (uWS::HttpResponse<false> *)res;
|
||||||
|
# return uwsRes->getHttpResponseData()->state;
|
||||||
|
# }
|
||||||
|
# }
|
||||||
|
|
||||||
|
#uws_res_get_native_handle
|
||||||
|
|
||||||
|
|
||||||
|
# void *uws_res_get_native_handle(int ssl, uws_res_t *res) {
|
||||||
|
# if (ssl) {
|
||||||
|
# uWS::HttpResponse<true> *uwsRes = (uWS::HttpResponse<true> *)res;
|
||||||
|
# return uwsRes->getNativeHandle();
|
||||||
|
# } else {
|
||||||
|
# uWS::HttpResponse<false> *uwsRes = (uWS::HttpResponse<false> *)res;
|
||||||
|
# return uwsRes->getNativeHandle();
|
||||||
|
# }
|
||||||
|
# }
|
||||||
|
# }
|
||||||
# unsigned int uws_num_subscribers(int ssl, uws_app_t *app, const char *topic);
|
# unsigned int uws_num_subscribers(int ssl, uws_app_t *app, const char *topic);
|
||||||
# bool uws_publish(int ssl, uws_app_t *app, const char *topic, size_t topic_length, const char *message, size_t message_length, uws_opcode_t opcode, bool compress);
|
# bool uws_publish(int ssl, uws_app_t *app, const char *topic, size_t topic_length, const char *message, size_t message_length, uws_opcode_t opcode, bool compress);
|
||||||
# void *uws_get_native_handle(int ssl, uws_app_t *app);
|
# void *uws_get_native_handle(int ssl, uws_app_t *app);
|
||||||
|
@ -42,6 +83,9 @@ async def home(res, req):
|
||||||
print("normal", req.get_url())
|
print("normal", req.get_url())
|
||||||
|
|
||||||
req.for_each_header(lambda key,value: print("Header %s: %s" % (key, value)))
|
req.for_each_header(lambda key,value: print("Header %s: %s" % (key, value)))
|
||||||
|
|
||||||
|
|
||||||
|
print("All headers", req.get_headers())
|
||||||
res.end("Test")
|
res.end("Test")
|
||||||
|
|
||||||
def run_app():
|
def run_app():
|
||||||
|
|
|
@ -66,8 +66,10 @@ def json(res, req):
|
||||||
async def sleepy_json(res, req):
|
async def sleepy_json(res, req):
|
||||||
#get parameters, query, headers anything you need here before first await :)
|
#get parameters, query, headers anything you need here before first await :)
|
||||||
user_agent = req.get_header("user-agent")
|
user_agent = req.get_header("user-agent")
|
||||||
#get all headers
|
#print all headers
|
||||||
req.for_each_header(lambda key,value: print("Header %s: %s" % (key, value)))
|
req.for_each_header(lambda key,value: print("Header %s: %s" % (key, value)))
|
||||||
|
#or if you want get all headers in an dict
|
||||||
|
print("All headers", req.get_headers())
|
||||||
|
|
||||||
#req maybe will not be available in direct attached async functions after await
|
#req maybe will not be available in direct attached async functions after await
|
||||||
#but if you dont care about req info you can do it
|
#but if you dont care about req info you can do it
|
||||||
|
|
Ładowanie…
Reference in New Issue