Skip to content

Commit db5f200

Browse files
authored
Merge pull request #3 from mitty1293/addhttpstatus
Addhttpstatus
2 parents 9f398ff + eb1c928 commit db5f200

File tree

4 files changed

+17
-46
lines changed

4 files changed

+17
-46
lines changed

README.md

+11-3
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,27 @@
11
# return-http-status-code
22
API to return HTTP status code
33
## Setup
4+
Clone the repository
45
```
56
$ git clone https://github.com/mitty1293/return-http-status-code.git
7+
```
8+
Write the NGINX port to be accessed in the `return-http-status-code/.env` file.
9+
```
10+
NGINX_PORT=80
11+
```
12+
Start the container
13+
```
614
$ docker-compose -f ./return-http-status-code/docker-compose.yml up -d
715
```
816
## Usage
917
Enter any status code in `[http_status_code]` and access the following URL.
1018
```
11-
http://host-ip:8004/[http_status_code]
19+
http://host-ip:[NGINX_PORT]/[http_status_code]
1220
```
13-
If a status code that is not listed in the `flask/app/const.py` is specified, `404 Not Found` will be returned.
21+
If a status code that is not listed in the [class http.HTTPStatus](https://docs.python.org/3/library/http.html#http-status-codes) is specified, `404 Not Found` will be returned.
1422
### Example
1523
```Shell
16-
$ curl -I http://host-ip:8004/500
24+
$ curl -I http://host-ip:[NGINX_PORT]/500
1725
HTTP/1.1 500 INTERNAL SERVER ERROR
1826
Server: nginx/1.20.1
1927
Date: Tue, 13 Jul 2021 15:16:34 GMT

flask/app/const.py

-35
This file was deleted.

flask/app/templates/index.html

+3-3
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,10 @@ <h2>Code List</h2>
5353
</tr>
5454
</thead>
5555
<tbody>
56-
{% for key in status_line %}
56+
{% for line in status_lines %}
5757
<tr>
58-
<th>{{key}}</th>
59-
<td>{{status_line[key]}}</td>
58+
<th>{{line.value}}</th>
59+
<td>{{line.name}}</td>
6060
</tr>
6161
{% endfor %}
6262
</tbody>

flask/app/views.py

+3-5
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,14 @@
1+
from http import HTTPStatus
12
from app import app
23
from flask import render_template, Response
3-
from . import const
4-
5-
responce = const.HTTPStatusCode()
64

75
@app.route('/')
86
def index():
9-
return render_template("index.html", status_line=responce.status_line)
7+
return render_template("index.html", status_lines=HTTPStatus)
108

119
@app.route('/<int:status_cd>')
1210
def return_status_code(status_cd):
13-
if status_cd in responce.status_line.keys():
11+
if status_cd in [e.value for e in HTTPStatus]:
1412
return Response(status=status_cd)
1513
return Response(status=404)
1614

0 commit comments

Comments
 (0)