Name | django-middleware-request-id JSON |
Version |
0.1.5
JSON |
| download |
home_page | None |
Summary | The middleware detect if a client or the front reverse proxy server provides a X-Request-ID header, and get it as the request_id. If no such header is provided, it can provide a random value. |
upload_time | 2024-05-22 13:42:55 |
maintainer | Wang DongHao |
docs_url | None |
author | Wang DongHao |
requires_python | None |
license | MIT |
keywords |
django-middleware-request-id
|
VCS |
|
bugtrack_url |
|
requirements |
No requirements were recorded.
|
Travis-CI |
No Travis.
|
coveralls test coverage |
No coveralls.
|
# django-middleware-request-id
The middleware detect if a client or the front reverse proxy server provides a X-Request-ID header, and get it as the request_id. If no such header is provided, it can provide a random value.
## Install
```
pip install django-middleware-request-id
```
## Usage
*pro/settings.py*
```
INSTALLED_APPS = [
"django_middleware_global_request",
"django_middleware_request_id",
]
MIDDLEWARE = [
...
"django_middleware_global_request.middleware.GlobalRequestMiddleware",
"django_middleware_request_id.middlewares.DjangoMiddlewareRequestId",
...
]
```
*app/views.py*
```
from django.http import HttpResponse
from django_middleware_request_id import get_request_id
def get_request_id_view(request):
request_id = get_request_id()
return HttpResponse(request_id)
```
*app/urls.py*
```
from django.contrib import admin
from django.urls import path
froml . import views
urlpatterns = [
path('get_request_id', views.get_request_id_view),
]
```
## Set the request id at nginx
```
http {
...
# -------------------------------------------------------------------------------
# Set variable $reqid.
# If you trust client or front nginx's header, you can use `map block` here.
# -------------------------------------------------------------------------------
map $http_x_request_id $reqid {
default $http_x_request_id;
"" $request_id;
}
# -------------------------------------------------------------------------------
server {
# -------------------------------------------------------------------------------
# If you don't trust client and front nginx's header, or you are sure this
# is the first front nginx, just set the variable $reqid to a new random value.
# Use `map block` above, or use `set line` below, but don't use both.
# Uncomment the `set line` below to `set new random value`.
# -------------------------------------------------------------------------------
# set $reqid $request_id;
# -------------------------------------------------------------------------------
...
location /api/ {
proxy_pass http://backend/api/;
proxy_set_header X-Request-Id $reqid;
...
}
...
}
}
```
## Test Passed
- python27:~=django1.11.29
- python34:~=django1.11.29
- python34:~=django2.0.13
- python35:~=django1.11.29
- python35:~=django2.0.13
- python35:~=django2.1.15
- python35:~=django2.2.28
- python36:~=django2.0.13
- python36:~=django2.1.15
- python36:~=django2.2.28
- python36:~=django3.0.14
- python36:~=django3.1.14
- python36:~=django3.2.21
- python37:~=django2.0.13
- python37:~=django2.1.15
- python37:~=django2.2.28
- python37:~=django3.0.14
- python37:~=django3.1.14
- python37:~=django3.2.21
- python38:~=django2.0.13
- python38:~=django2.1.15
- python38:~=django2.2.28
- python38:~=django3.0.14
- python38:~=django3.1.14
- python38:~=django3.2.21
- python38:~=django4.0.10
- python38:~=django4.1.11
- python38:~=django4.2.5
- python39:~=django2.0.13
- python39:~=django2.1.15
- python39:~=django2.2.28
- python39:~=django3.0.14
- python39:~=django3.1.14
- python39:~=django3.2.21
- python39:~=django4.0.10
- python39:~=django4.1.11
- python39:~=django4.2.5
- python310:~=django2.1.15
- python310:~=django2.2.28
- python310:~=django3.0.14
- python310:~=django3.1.14
- python310:~=django3.2.21
- python310:~=django4.0.10
- python310:~=django4.1.11
- python310:~=django4.2.5
- python311:~=django2.2.28
- python311:~=django3.0.14
- python311:~=django3.1.14
- python311:~=django3.2.21
- python311:~=django4.0.10
- python311:~=django4.1.11
- python311:~=django4.2.5
## Releases
### v0.1.0
- First release.
### v0.1.2
- Fix problem that import `get_request_id` from the package root.
- Fix problem that NOT using DJANGO_REQUEST_ID_HEADER setting.
- Fix problem that call get_request_id() from none request context.
### v0.1.3
- Doc update.
### v0.1.4
- Unit test all passed.
### v0.1.5
- Add unit test for python-12 and django-5.0.6.
Raw data
{
"_id": null,
"home_page": null,
"name": "django-middleware-request-id",
"maintainer": "Wang DongHao",
"docs_url": null,
"requires_python": null,
"maintainer_email": null,
"keywords": "django-middleware-request-id",
"author": "Wang DongHao",
"author_email": null,
"download_url": "https://files.pythonhosted.org/packages/c3/b5/ac87763ef3161baec5889f153ed656a8e830afedabf9e0d2a8af16784715/django-middleware-request-id-0.1.5.tar.gz",
"platform": null,
"description": "# django-middleware-request-id\n\nThe middleware detect if a client or the front reverse proxy server provides a X-Request-ID header, and get it as the request_id. If no such header is provided, it can provide a random value. \n\n## Install\n\n```\npip install django-middleware-request-id\n```\n\n## Usage\n\n*pro/settings.py*\n\n```\nINSTALLED_APPS = [\n \"django_middleware_global_request\",\n \"django_middleware_request_id\",\n]\n\nMIDDLEWARE = [\n ...\n \"django_middleware_global_request.middleware.GlobalRequestMiddleware\",\n \"django_middleware_request_id.middlewares.DjangoMiddlewareRequestId\",\n ...\n]\n\n```\n\n*app/views.py*\n\n```\nfrom django.http import HttpResponse\nfrom django_middleware_request_id import get_request_id\n\ndef get_request_id_view(request):\n request_id = get_request_id()\n return HttpResponse(request_id)\n\n```\n\n*app/urls.py*\n\n```\nfrom django.contrib import admin\nfrom django.urls import path\nfroml . import views\n\nurlpatterns = [\n path('get_request_id', views.get_request_id_view),\n]\n\n```\n\n## Set the request id at nginx\n\n```\nhttp {\n ...\n # -------------------------------------------------------------------------------\n # Set variable $reqid.\n # If you trust client or front nginx's header, you can use `map block` here.\n # -------------------------------------------------------------------------------\n map $http_x_request_id $reqid {\n default $http_x_request_id;\n \"\" $request_id;\n }\n # -------------------------------------------------------------------------------\n\n server {\n\n # -------------------------------------------------------------------------------\n # If you don't trust client and front nginx's header, or you are sure this \n # is the first front nginx, just set the variable $reqid to a new random value.\n # Use `map block` above, or use `set line` below, but don't use both.\n # Uncomment the `set line` below to `set new random value`.\n # -------------------------------------------------------------------------------\n # set $reqid $request_id;\n # -------------------------------------------------------------------------------\n\n ...\n location /api/ {\n proxy_pass http://backend/api/;\n proxy_set_header X-Request-Id $reqid;\n ...\n }\n ...\n }\n}\n\n```\n\n## Test Passed\n\n- python27:~=django1.11.29\n- python34:~=django1.11.29\n- python34:~=django2.0.13\n- python35:~=django1.11.29\n- python35:~=django2.0.13\n- python35:~=django2.1.15\n- python35:~=django2.2.28\n- python36:~=django2.0.13\n- python36:~=django2.1.15\n- python36:~=django2.2.28\n- python36:~=django3.0.14\n- python36:~=django3.1.14\n- python36:~=django3.2.21\n- python37:~=django2.0.13\n- python37:~=django2.1.15\n- python37:~=django2.2.28\n- python37:~=django3.0.14\n- python37:~=django3.1.14\n- python37:~=django3.2.21\n- python38:~=django2.0.13\n- python38:~=django2.1.15\n- python38:~=django2.2.28\n- python38:~=django3.0.14\n- python38:~=django3.1.14\n- python38:~=django3.2.21\n- python38:~=django4.0.10\n- python38:~=django4.1.11\n- python38:~=django4.2.5\n- python39:~=django2.0.13\n- python39:~=django2.1.15\n- python39:~=django2.2.28\n- python39:~=django3.0.14\n- python39:~=django3.1.14\n- python39:~=django3.2.21\n- python39:~=django4.0.10\n- python39:~=django4.1.11\n- python39:~=django4.2.5\n- python310:~=django2.1.15\n- python310:~=django2.2.28\n- python310:~=django3.0.14\n- python310:~=django3.1.14\n- python310:~=django3.2.21\n- python310:~=django4.0.10\n- python310:~=django4.1.11\n- python310:~=django4.2.5\n- python311:~=django2.2.28\n- python311:~=django3.0.14\n- python311:~=django3.1.14\n- python311:~=django3.2.21\n- python311:~=django4.0.10\n- python311:~=django4.1.11\n- python311:~=django4.2.5\n\n## Releases\n\n### v0.1.0\n\n- First release.\n\n### v0.1.2\n\n- Fix problem that import `get_request_id` from the package root.\n- Fix problem that NOT using DJANGO_REQUEST_ID_HEADER setting.\n- Fix problem that call get_request_id() from none request context.\n\n### v0.1.3\n\n- Doc update.\n\n### v0.1.4\n\n- Unit test all passed.\n\n### v0.1.5\n\n- Add unit test for python-12 and django-5.0.6.\n\n\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "The middleware detect if a client or the front reverse proxy server provides a X-Request-ID header, and get it as the request_id. If no such header is provided, it can provide a random value.",
"version": "0.1.5",
"project_urls": null,
"split_keywords": [
"django-middleware-request-id"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "9584bfa363aaba19bf42ec0d0d355a01c2e74afead62c608fd44575f34d2c9cd",
"md5": "16eefb7828d928faab730a8959fa0ead",
"sha256": "022e1cee814f63e8f96433b9eff024fdbd7fe5def0bdbc4553ec4483009359b0"
},
"downloads": -1,
"filename": "django_middleware_request_id-0.1.5-py3-none-any.whl",
"has_sig": false,
"md5_digest": "16eefb7828d928faab730a8959fa0ead",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": null,
"size": 7236,
"upload_time": "2024-05-22T13:42:53",
"upload_time_iso_8601": "2024-05-22T13:42:53.776261Z",
"url": "https://files.pythonhosted.org/packages/95/84/bfa363aaba19bf42ec0d0d355a01c2e74afead62c608fd44575f34d2c9cd/django_middleware_request_id-0.1.5-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "c3b5ac87763ef3161baec5889f153ed656a8e830afedabf9e0d2a8af16784715",
"md5": "1f815114b50b02deb932c8b0c98a61ab",
"sha256": "d8a1ce5aa2e328be37076a618fbd13495ef3cd42b9530b51a0529b85dac28fc6"
},
"downloads": -1,
"filename": "django-middleware-request-id-0.1.5.tar.gz",
"has_sig": false,
"md5_digest": "1f815114b50b02deb932c8b0c98a61ab",
"packagetype": "sdist",
"python_version": "source",
"requires_python": null,
"size": 6018,
"upload_time": "2024-05-22T13:42:55",
"upload_time_iso_8601": "2024-05-22T13:42:55.470411Z",
"url": "https://files.pythonhosted.org/packages/c3/b5/ac87763ef3161baec5889f153ed656a8e830afedabf9e0d2a8af16784715/django-middleware-request-id-0.1.5.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-05-22 13:42:55",
"github": false,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"lcname": "django-middleware-request-id"
}