0

I have a Flask App that has multiple APIs, one of the APIs I've is accessed using POST request and takes data in the body along with some headers, for example, student_id. This API returns the student results based on the passed student_id in the headers.

I've run it in pycharm IDE (locally) and it works 100%, in which for each different student_id a different result is returned. otherwise (the student_id not passed) a bad request is returned.

but when it's deployed into AWS (Elasticbean stalk), the result is the same for any student_id even if there's no student_id present in the headers it still returns the result (the same result for the first request made on this API).

In my opinion, I guess it's a caching issue so I've tried to add a decorator @app.after_request but it didn't work

@application.after_request
def after_request(response):
    response.headers['Last-Modified'] = str(http_date(datetime.now() - timedelta(days=1)))
    response.headers["Cache-Control"] = "'no-store, no-cache, must-revalidate, post-check=0, 
    pre-check=0, max-age=0'"
    response.headers["Expires"] = '-1'
    response.headers["Pragma"] = "no-cache"
    return response
Jamal Alkelani
  • 606
  • 7
  • 19

1 Answers1

0

I've solved the problem, the above code in my question works well in which it disables the caching, but make sure to use a valid date format for HTTP (I've modified the code to work 100%).

The problem wasn't related to caching, it was an issue in which someone of the headers was not passed to the servers, that's because of AWS servers run on Nginx and Apache and

underscores are not allowed in the headers

For complete details refer to this question underscores are not allowed in headers

Jamal Alkelani
  • 606
  • 7
  • 19