예제 #1
0
    def get(self, request: Request) -> Response:
        utc_now_str = datetime.datetime.utcnow().strftime(
            '%a, %d %b %Y %H:%M:%S GMT')
        content = get_file_content(TEMPLATE_DIR + "/now/index.html")
        content = fill_parameters(content, {"$now": utc_now_str})

        return Response(body=content, content_type="text/html")
예제 #2
0
    def get(self, request: Request) -> Response:
        content = get_file_content(TEMPLATE_DIR + "/user/index.html")
        user_id = request.cookies.get("session_id")

        user_name = "名無し"
        if user_id is not None:
            user_name = SESSIONS.get(user_id)
        content = fill_parameters(content, {"$user_name": user_name})
        return Response(body=content, content_type="text/html")
예제 #3
0
    def get(self, request: Request) -> Response:
        headers_list = [
            f"{k}: {v}<br>".encode() for k, v in request.headers.items()
        ]
        headers_str = "".join(headers_list)
        content = get_file_content(TEMPLATE_DIR + "/headers/index.html")
        content = fill_parameters(content, {"$headers": headers_str})

        return Response(body=content, content_type="text/html")
예제 #4
0
 def get(self, request: Request) -> Response:
     query_list = [f"{k}: {v}<br>".encode() for k, v in request.GET.items()]
     query_str = "".join(query_list)
     content = get_file_content(TEMPLATE_DIR + "/parameters/index.html")
     if query_str:
         content = fill_parameters(content, {"$parameters": query_str})
     else:
         content = fill_parameters(
             content, {"$parameters": "parameters are not exist"})
     return Response(body=content, content_type="text/html")
예제 #5
0
 def get(self, request: Request) -> Response:
     content = get_file_content(TEMPLATE_DIR + "/cookie/index.html")
     cookie = {
         "test": "12345",
         "test2": "abcde",
     }
     content = fill_parameters(content, {"$cookie": json.dumps(cookie)})
     response = Response(body=content, content_type="text/html")
     for k, v in cookie.items():
         response.set_cookie(k, v)
     return response
예제 #6
0
    def post(self, request: Request) -> Response:
        user_name = request.POST["user_name"]

        if "session_id" in request.cookies:
            user_id = request.cookies.get("session_id")
        else:
            user_id = sha256(user_name.encode()).hexdigest()
            SESSIONS[user_id] = user_name

        content = get_file_content(TEMPLATE_DIR + "/user/index.html")
        content = fill_parameters(content, {"$user_name": user_name})
        response = Response(body=content, content_type="text/html")
        response.set_cookie("session_id", user_id)
        return response
예제 #7
0
 def get(self, request: Request) -> Response:
     content = get_file_content(TEMPLATE_DIR + "/index.html")
     return Response(body=content, content_type="text/html")
예제 #8
0
 def get(self, request: Request) -> Response:
     filename = request.path.replace("/static/", "")
     content_type = self.get_content_type(request)
     content = get_file_content(STATIC_DIR + filename)
     return Response(content, content_type=content_type)