je vous écris ce petit script WSGI:Comment le savoir est une requête ajax dans un script WSGI?
def application(environ, start_response):
data = '\n'.join(sorted(['%s = %s' % i for i in environ.items()]))
print data
start_response("200 OK", [
("Content-Type", "text/plain"),
("Content-Length", str(len(data)))
])
return iter([data])
Je me demande comment puis-je détecter que je reçois une demande de paiement ajax: Quand je lance avec gunicorn et quand je produis une demande ajax avec .ajax $() de jQuery, je suis arrivé pour cette variable environ:
HTTP_ACCEPT = */*
HTTP_ACCEPT_ENCODING = gzip, deflate, sdch, br
HTTP_ACCEPT_LANGUAGE = fr-FR,fr;q=0.8,en-US;q=0.6,en;q=0.4
HTTP_ACCESS_CONTROL_REQUEST_HEADERS = 16hhs673uh
HTTP_ACCESS_CONTROL_REQUEST_METHOD = GET
HTTP_CONNECTION = keep-alive
HTTP_HOST = localhost:8222
HTTP_ORIGIN = http://localhost:6543
HTTP_REFERER = http://localhost:6543/test2
HTTP_USER_AGENT = Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/55.0.2883.87 Safari/537.36
PATH_INFO = /test2
QUERY_STRING = name=John4&time=2pm
RAW_URI = /test2?name=John4&time=2pm
REMOTE_ADDR = 127.0.0.1
REMOTE_PORT = 40668
REQUEST_METHOD = OPTIONS
SCRIPT_NAME =
SERVER_NAME = 127.0.0.1
SERVER_PORT = 8222
SERVER_PROTOCOL = HTTP/1.1
SERVER_SOFTWARE = gunicorn/19.7.1
gunicorn.socket = <socket._socketobject object at 0x7f14844e51a0>
wsgi.errors = <gunicorn.http.wsgi.WSGIErrorsWrapper object at 0x7f14844e47d0>
wsgi.file_wrapper = <class 'gunicorn.http.wsgi.FileWrapper'>
wsgi.input = <gunicorn.http.body.Body object at 0x7f14844e4950>
wsgi.multiprocess = False
wsgi.multithread = False
wsgi.run_once = False
wsgi.url_scheme = http
wsgi.version = (1, 0)
Je ne vois pas d'informations comme HTTP_X_REQUESTED_WITH, comment Django ou la pyramide peut connue, il est une demande de paiement ajax?
Pourquoi devriez-vous vous préoccuper de savoir si le client attend une réponse ou la traite de manière asynchrone (ou quelle langue utilise-t-elle)? – UnholySheep
Je veux vérifier cela pour des raisons de sécurité. – Eric
Je ne suis pas vraiment sûr des raisons de sécurité, MAIS je ne peux pas le dire (puisque le client n'a aucune obligation d'envoyer de telles informations) - Je suppose que le 'HTTP_USER_AGENT' est le plus proche que vous puissiez savoir a été envoyé à partir d'un navigateur – UnholySheep