# Transcript lab 0.2 - HTTP noi soi bang curl
# Chay that ngay 2026-10-18T10:17:36Z tren Flask 3.1.3, curl 7.81
# App: python3 app.py  (127.0.0.1:8010)

$ curl -v http://127.0.0.1:8010/ -o /dev/null
*   Trying 127.0.0.1:8010...
* Connected to 127.0.0.1 (127.0.0.1) port 8010 (#0)
> GET / HTTP/1.1
> Host: 127.0.0.1:8010
> User-Agent: curl/7.81.0
> Accept: */*
> 
* Mark bundle as not supporting multiuse
< HTTP/1.1 200 OK
< Server: Werkzeug/3.1.8 Python/3.11.9
< Date: Sun, 18 Oct 2026 10:17:36 GMT
< Content-Type: text/html; charset=utf-8
< Content-Length: 679
< Server: Lab0.2/Flask
< Connection: close
< 
{ [679 bytes data]
* Closing connection 0

--------------------------------------------------------------------
$ curl -s "http://127.0.0.1:8010/echo?q=hello&lang=vi" -H "X-Custom: demo"
{
  "method": "GET",
  "path": "/echo",
  "query": {
    "q": "hello",
    "lang": "vi"
  },
  "headers": {
    "Host": "127.0.0.1:8010",
    "User-Agent": "curl/7.81.0",
    "Accept": "*/*",
    "X-Custom": "demo"
  },
  "cookies": {},
  "body_raw": "",
  "form": {},
  "remote_addr": "127.0.0.1"
}

--------------------------------------------------------------------
$ curl -s -X DELETE http://127.0.0.1:8010/echo
{
  "method": "DELETE",
  "path": "/echo",
  "query": {},
  "headers": {
    "Host": "127.0.0.1:8010",
    "User-Agent": "curl/7.81.0",
    "Accept": "*/*"
  },
  "cookies": {},
  "body_raw": "",
  "form": {},
  "remote_addr": "127.0.0.1"
}

--------------------------------------------------------------------
$ curl -i -s -X POST -d "user=admin&pass=admin" http://127.0.0.1:8010/login
HTTP/1.1 200 OK
Server: Werkzeug/3.1.8 Python/3.11.9
Date: Sun, 18 Oct 2026 10:17:36 GMT
Content-Type: application/json
Content-Length: 45
Set-Cookie: session=s3ss10n-demo-abc123; HttpOnly; Path=/; SameSite=Lax
Connection: close

{"msg":"dang nhap thanh cong","status":"ok"}


--------------------------------------------------------------------
$ curl -s -b "session=s3ss10n-demo-abc123" http://127.0.0.1:8010/whoami
{"user":"admin","via":"cookie session"}

--------------------------------------------------------------------
$ curl -i -s http://127.0.0.1:8010/secret        # thieu Authorization -> 401
HTTP/1.1 401 UNAUTHORIZED
Server: Werkzeug/3.1.8 Python/3.11.9
Date: Sun, 18 Oct 2026 10:17:36 GMT
Content-Type: application/json
Content-Length: 37
WWW-Authenticate: Basic realm="lab02"
Connection: close

{"error":"can header Authorization"}


--------------------------------------------------------------------
$ curl -i -s http://127.0.0.1:8010/secret -H "Authorization: Bearer demo-token"
HTTP/1.1 200 OK
Server: Werkzeug/3.1.8 Python/3.11.9
Date: Sun, 18 Oct 2026 10:17:36 GMT
Content-Type: application/json
Content-Length: 77
Connection: close

{"got":"Bearer demo-token","secret":"co header roi, day la noi dung bi mat"}


--------------------------------------------------------------------
$ curl -i -s http://127.0.0.1:8010/teapot
HTTP/1.1 418 I'M A TEAPOT
Server: Werkzeug/3.1.8 Python/3.11.9
Date: Sun, 18 Oct 2026 10:17:36 GMT
Content-Type: text/plain; charset=utf-8
Content-Length: 13
Connection: close

I'm a teapot

