Content-Location
        
        
          
                Baseline
                
                  Widely available
                
                
              
        
        
        
          
                
              
                
              
                
              
        
        
      
      This feature is well established and works across many devices and browser versions. It’s been available across browsers since 2015年7月.
Content-Location ヘッダーは、返されるデータの代替場所を示します。主な用途は、コンテンツネゴシエーションの結果として送信されたリソースの URL を示すことです。
Location と Content-Location は異なります。
Location はリダイレクトの URL を示し、Content-Location は今後のコンテンツネゴシエーションなしでリソースへのアクセスに使用する直接 URL を示します。 Location はレスポンスに関連付けられたヘッダーで、 Content-Location は返されたデータに関連付けられます。この区別は例がないと抽象的に見えるかもしれません。
| ヘッダー種別 | 表現ヘッダー | 
|---|---|
| 禁止リクエストヘッダー | いいえ | 
構文
Content-Location: <url>
ディレクティブ
例
>サーバーからのデータのリクエストを様々な形式で行う
たとえば、サイトの API が JSON, XML, または CSV 形式でデータを返すとします。特定の文書の URL が https://example.com/documents/foo である場合、サイトはリクエストの Accept ヘッダーに応じて Content-Location 用に異なる URL を返すことができます。
| リクエストヘッダー | レスポンスヘッダー | 
|---|---|
Accept: application/json, text/json | 
Content-Location: /documents/foo.json | 
Accept: application/xml, text/xml | 
Content-Location: /documents/foo.xml | 
Accept: text/plain, text/* | 
Content-Location: /documents/foo.txt | 
これらのURLは例です。サイトは、クエリー文字列引数、例えば /documents/foo?format=json、/documents/foo?format=xml など、任意の URL パターンでさまざまなファイル形式を提供することができます。
その後クライアントはその特定の URL で JSON バージョンが利用可能であることを覚えて、次に文書を要求するときにコンテンツのネゴシエーションをスキップします。
サーバーは Accept-Language のような他のコンテンツネゴシエーションヘッダーを考慮することもあります。
新しい文書を指す (HTTP 201 Created)
サイトの API を通じて新しいブログ投稿を作成しているとします。
POST /new/post
Host: example.com
Content-Type: text/markdown
# My first blog post!
I made this through `example.com`'s API. I hope it worked.
サイトは公開された投稿をレスポンス本体で返します。サーバーは、新しい投稿の場所を Content-Location ヘッダーで指定し、この場所がこのレスポンスのコンテンツ(本体)を参照することを示します。
HTTP/1.1 201 Created
Content-Type: text/markdown
Content-Location: /my-first-blog-post
# My first blog post
I made this through `example.com`'s API. I hope it worked.
トランザクションの結果の URL を示す
サイトの別のユーザーに送金するための <form> があるとします。
<form action="/send-payment" method="post">
  <p>
    <label
      >送金したい宛先は?
      <input type="text" name="recipient" />
    </label>
  </p>
  <p>
    <label
      >金額は?
      <input type="number" name="amount" />
    </label>
  </p>
  <button type="submit">送金する</button>
</form>
フォームが送信されると、サイトは取引の領収書を生成します。サーバーは Content-Location を使用して、将来のアクセスのために領収書の URL を示すことができます。
HTTP/1.1 200 OK
Content-Type: text/html; charset=utf-8
Content-Location: /my-receipts/38
<!doctype html>
(Lots of HTML…)
<p>You sent $38.00 to ExampleUser.</p>
(Lots more HTML…)
仕様書
| Specification | 
|---|
| HTTP Semantics> # field.content-location>  | 
            
ブラウザーの互換性
Loading…