見出し画像

HTTPレスポンスと認証方式の学びなおし

「HTML5プロフェッショナル認定試験」対策を兼ねた、多くを引用した個人の勉強ノートその2です。参考まで。

HTTPステータスコードとは

HTTPリクエストが成功したかどうかを示す数値コードで、レスポンスの意味を示すもの。

HTTP response status codes indicate whether a specific HTTP request has been successfully completed. 

https://developer.mozilla.org/ja/docs/Web/HTTP/Status

■ 1xx Informational 情報系
プロセス継続中。継続しているときに暫定的に発行され、最終的な返答待ちを通知するもの。

It is issued on a provisional basis while request processing continues. It alerts the client to wait for a final response.

- 101 Switching Protocol
サーバーにプロトコル切り替え依頼し承諾。

The requester has asked the server to switch protocols and the server has agreed to do so.

■ 2xx Success 成功系

- 200 OK
リクエストが成功したことを示す。リクエストメソッドによってその成功のレスポンスは異なる。GETメソッドではボディにリソースが含まれ、POSTメソッドでは結果が含まれる。

This class of status codes indicates the action requested by the client was received, understood, and accepted.
200 OK
Standard response for successful HTTP requests. The actual response will depend on the request method used. In a GET request, the response will contain an entity corresponding to the requested resource. In a POST request, the response will contain an entity describing or containing the result of the action.

■ 3xx Redirection リダイレクト系

- 301 Moved Permanently
リクエストされたURLが永続的に変更され、Locationヘッダに移動先のURLが示される。

This and all future requests should be directed to the given URI.

- 304 Not Modified
更新なし。前回アクセスした時のブラウザ内のキャッシュを取り出して表示する。

This is used for caching purposes. It tells the client that the response has not been modified, so the client can continue to use the same cached version of the response.

- 307 Temporary Redirect
一時的なリダイレクト。

The server sends this response to direct the client to get the requested resource at another URI with same method that was used in the prior request.

■ 4xx Client errors クライアントエラー系

- 401 Unauthorized 
認証(後述)が必要。

Although the HTTP standard specifies "unauthorized", semantically this response means "unauthenticated". That is, the client must authenticate itself to get the requested response.

- 403 Forbidden
アクセス権が無い。

The client does not have access rights to the content; that is, it is unauthorized, so the server is refusing to give the requested resource.

- 404 Not Found
リソース見つからず。

The requested resource could not be found but may be available in the future. Subsequent requests by the client are permissible.

■ 5xx server errors サーバーエラー系

- 500 Internal Server Error
サーバー内でエラー発生。文法エラー等予期せぬ状態で詳細不明。

A generic error message, given when an unexpected condition was encountered and no more specific message is suitable.

Ajax

クライアントとサーバー間のやり取りにおいてリクエストを送ってからレスポンスが返ってくるまでの間、ほかの処理を行わずにレスポンスを待ち続ける通信方式のことを同期、バッググラウンドで別の処理を行い、ブラウザの処理を待ちつつサーバーとやり取りすることを非同期という。これを可能にするjsを用いた技術をAjax(Asynchronous JavaScript and XML)という。

With Ajax, web applications can send and retrieve data from a server asynchronously (in the background) without interfering with the display and behavior of the existing page.

認証方式

■ Basic認証
ブラウザでID/ PWを暗号化して送る方法。この時Base64という方法を取り、一定の規則に基づいて64種類の英数字のみを用いてデータを表現する。
HTTPリクエストのヘッダ「Authorization」に付加して送信する。

Basic authentication scheme
The "Basic" HTTP authentication scheme is defined in RFC 7617, which transmits credentials as user ID/password pairs, encoded using base64.
Base64 is a encoding algorithm that allows you to transform any characters into an alphabet which consists of Latin letters, digits, plus, and slash.

このBasic認証はハッシュ化していないため安全ではなく、HTTPSと併用が望ましい。

ハッシュ値化
元の値を「ハッシュ関数」と呼ばれる「値を中に放り込むと適当な値(適当に見える値)を返してくれる関数」に入れて「ハッシュ値」と呼ばれる「適当な値(適当に見える値)」に変換すること。ハッシュ値から元データに戻せない。
the basic authentication scheme is not secure. HTTPS / TLS should be used in conjunction with basic authentication. Without these additional security enhancements, basic authentication should not be used to protect sensitive or valuable information.

■ Digest 認証
Basic認証とは異なり、ID/PWをMD5もしくはSHA2という方法でハッシュ値化して送信するより安全な方法。

 It applies a hash function to the username and password before sending them over the network.
Technically, digest authentication is an application of MD5 cryptographic hashing with usage of nonce values to prevent replay attacks. It uses the HTTP protocol.

以上です!何かすこしでも役に立てば嬉しいです。
コメントもお待ちしてます。

この記事が気に入ったらサポートをしてみませんか?