Skip to content

Commit 57cac86

Browse files
fix deseappearing header
1 parent 5ba6a9e commit 57cac86

File tree

2 files changed

+19
-25
lines changed

2 files changed

+19
-25
lines changed

app.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
import os
2-
import sys
32
import logging
43
from flask import Flask
5-
from flask import request
64
from flask_restful import Api
75
from werkzeug.routing import BaseConverter
86
from src.resource import Gateway
@@ -35,10 +33,6 @@ def __init__(self, url_map, *items):
3533

3634
@app.after_request
3735
def _build_cors_post_response(response):
38-
print(f"Headers(post response): {request.headers}")
39-
sys.stdout.flush()
40-
# if 'Origin' in request.headers:
41-
# response.headers.add("Access-Control-Allow-Origin", request.headers['Origin'])
4236
response.headers.add("Access-Control-Allow-Origin", "*")
4337
response.headers.add("Access-Control-Allow-Headers", "*")
4438
response.headers.add("Access-Control-Allow-Methods", "*")

src/apps/users.py

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
import os
33
import logging
44
import jwt
5-
import sys
65

76
import requests
87
from flask import make_response
@@ -29,17 +28,22 @@ def _get_token(headers: dict):
2928

3029
def process_header(headers, body: dict) -> (dict, bool):
3130
token = _get_token(headers)
32-
if not token and not (body and "user_id" in body): # Check to not allow to bypass the token
31+
if not token and not (body and "user_id" in body):
3332
return body, False
3433
newBody = body.copy() if body else {}
3534
try:
36-
processToken = jwt.decode(token, key=os.getenv("HASH_SECRET"), algorithms=[os.getenv("HASH_ALGORITHM"), ])
35+
processToken = jwt.decode(token, key=os.getenv("HASH_SECRET"),
36+
algorithms=[os.getenv("HASH_ALGORITHM"), ])
3737
newBody["user_id"] = processToken.get("id", "")
3838
newBody["email"] = processToken.get("email")
3939
except jwt.ExpiredSignatureError:
40-
return {"message": "expired token", "status": http.client.UNAUTHORIZED}, True
40+
return {"message":
41+
"expired token",
42+
"status": http.client.UNAUTHORIZED}, True
4143
except jwt.InvalidTokenError:
42-
return {"message": "invalid token", "status": http.client.FORBIDDEN}, True
44+
return {"message":
45+
"invalid token",
46+
"status": http.client.FORBIDDEN}, True
4347
return newBody, False
4448

4549

@@ -61,26 +65,22 @@ def get(self, url, body, headers, query_params):
6165
response.status_code)
6266

6367
def post(self, url, body, headers, query_params):
64-
print(f"URL: {url}")
65-
sys.stdout.flush()
66-
if not(url.startswith("login")):
67-
print(f"NO ES UN CASO DE LOG IN !!!!!!! {url}")
68-
sys.stdout.flush()
69-
body, error = process_header(headers, body)
70-
if error:
71-
print(f"ES UN CASO DE ERROR(SEGUIMOS EN LOG IN'T ) !!!!!!! {url}")
72-
sys.stdout.flush()
73-
return make_response(body, body.get("status"))
68+
# if not (url.startswith("login")):
69+
# body, error = process_header(headers, body)
70+
# if error:
71+
# return make_response(body, body.get("status"))
7472
response = requests.post(f"{self.host}{url}"
7573
f"{get_query_params(query_params)}",
7674
json=body,
7775
headers=headers)
7876
logging.info(f"USERS | POST | {url}")
7977
logging.debug(f"BODY: {body}")
80-
print(f"headers: {headers}")
81-
sys.stdout.flush()
82-
return make_response(self.getResponseJson(response),
83-
response.status_code)
78+
headers = dict(response.headers)
79+
response = make_response(self.getResponseJson(response),
80+
response.status_code)
81+
if headers.get(TOKEN_FIELD_NAME):
82+
response.headers[TOKEN_FIELD_NAME] = headers.get(TOKEN_FIELD_NAME)
83+
return response
8484

8585
def patch(self, url, body, headers, query_params):
8686
response = requests.patch(f"{self.host}{url}"

0 commit comments

Comments
 (0)