HTTP 401 UnauthorizedとWWW-Authenticateが返された時、ブラウザ(クライアント)側は、入力されたユーザー名とパスワードを':'で繋げて、Base64変換し、Authorizationヘッダに付けて送る。
サーバ側と一致すればアクセスできる。
HTTP 認証 - HTTP | MDN
Authorization - HTTP | MDN
http_server.cで、
OpenSSLのヘッダを追加。
ユーザー名は"testuser"、パスワードは"test123"、これを":"で繋げてBase64変換する。
これとブラウザ側のAuthorizationヘッダにあるものが一致すればHTTP 200 OKを返す。
![](https://cdn-ak.f.st-hatena.com/images/fotolife/B/BG1/20210909/20210909172215.png)
サーバ側はdから始まる。
![適当なユーザー名やパスワードだと](https://cdn-ak.f.st-hatena.com/images/fotolife/B/BG1/20210909/20210909172338.png)
適当なユーザー名やパスワードだと、
![ブラウザ側はaから始まってるので](https://cdn-ak.f.st-hatena.com/images/fotolife/B/BG1/20210909/20210909172550.png)
ブラウザ側はaから始まってるので、
![401](https://cdn-ak.f.st-hatena.com/images/fotolife/B/BG1/20210909/20210909172629.png)
401。
![正しいユーザー名とパスワードだと](https://cdn-ak.f.st-hatena.com/images/fotolife/B/BG1/20210909/20210909172720.png)
正しいユーザー名とパスワードだと、
![200](https://cdn-ak.f.st-hatena.com/images/fotolife/B/BG1/20210909/20210909172758.png)
200。
![bufとbasic_strが一致](https://cdn-ak.f.st-hatena.com/images/fotolife/B/BG1/20210909/20210909172912.png)
bufとbasic_strが一致。
Sample/http/Authorization/Authorization/src/Authorization at master · bg1bgst333/Sample · GitHub