---
# System prepended metadata

title: '#19.2 HTTP method 共同研究會 - GET/HEAD'
tags: [Meetups]

---

---
title: "#19.2 HTTP method 共同研究會 - GET/HEAD"
tags: Meetups
date: 2022-04-07
---

## [4.3 Method Definitions](https://datatracker.ietf.org/doc/html/rfc7231#section-4.3)

### 4.3.1 GET

> The GET method requests transfer of a current selected representation for the target resource.  GET is the primary mechanism of information retrieval and the focus of almost all performance optimizations.Hence, when people speak of retrieving some identifiable information via HTTP, they are generally referring to making a GET request.
   
GET 方法通常是做為請求目標資源的一個機制。當討論透過 HTTP 取得資訊的時候，通常指的是發一個 GET 請求。



   It is tempting to think of resource identifiers as remote file system pathnames and of representations as being a copy of the contents of such files.  In fact, that is how many resources are implemented (see Section 9.1 for related security considerations).  However, there are no such limitations in practice.  The HTTP interface for a resource is just as likely to be implemented as a tree of content objects, a programmatic view on various database records, or a gateway to other information systems.  Even when the URI mapping mechanism is tied to a file system, an origin server might be configured to execute the files with the request as input and send the output as the representation rather than transfer the files directly. Regardless, only the origin server needs to know how each of its resource identifiers corresponds to an implementation and how each implementation manages to select and send a current representation of the target resource in a response to GET.

資源的標記物（如：URI）可以對映到遠端檔案路徑或是檔案系統的映射。來源伺服器需要處理 URI 如何實作，可能是檔案系統的複本，可能是執行過後的結果。


可參考前一版的說明 [RFC 2616](https://datatracker.ietf.org/doc/html/rfc2616#section-9.3)

   The GET method means retrieve whatever information (in the form of an entity) is identified by the Request-URI. If the Request-URI refers to a data-producing process, it is the produced data which shall be returned as the entity in the response and not the source text of the process, unless that text happens to be the output of the process.

---


   A client can alter the semantics of GET to be a "range request", requesting transfer of only some part(s) of the selected representation, by sending a Range header field in the request ([RFC7233]).

   A payload within a GET request message has no defined semantics; sending a payload body on a GET request might cause some existing implementations to reject the request.

「GET 帶入 payload」這個做法並無明確定義。如果在 GET 請求帶入 payload 有可能會造成請求被拒絕。 

   The response to a GET request is cacheable; a cache MAY use it to satisfy subsequent GET and HEAD requests unless otherwise indicated by the Cache-Control header field (Section 5.2 of [RFC7234]).

### 4.3.1 HEAD

   The HEAD method is identical to GET except that the server MUST NOT send a message body in the response (i.e., the response terminates at the end of the header section).  The server SHOULD send the same header fields in response to a HEAD request as it would have sent if the request had been a GET, except that the payload header fields (Section 3.3) MAY be omitted.  This method can be used for obtaining metadata about the selected representation without transferring the representation data and is often used for testing hypertext links for validity, accessibility, and recent modification.
   
   HEAD 除了沒有回傳的物件本身的副本其他跟 GET 一樣。（也就是說 只有 header 的部份）

   A payload within a HEAD request message has no defined semantics; sending a payload body on a HEAD request might cause some existing implementations to reject the request.


   The response to a HEAD request is cacheable; a cache MAY use it to satisfy subsequent HEAD requests unless otherwise indicated by the Cache-Control header field (Section 5.2 of [RFC7234]).  A HEAD response might also have an effect on previously cached responses to GET; see Section 4.3.5 of [RFC7234].

### 4.3.3. POST

   The POST method requests that the target resource process the representation enclosed in the request according to the resource's own specific semantics.  For example, POST is used for the following functions (among others):

   o  Providing a block of data, such as the fields entered into an HTML form, to a data-handling process;
   o  Posting a message to a bulletin board, newsgroup, mailing list, blog, or similar group of articles;

   o  Creating a new resource that has yet to be identified by the origin server; and

   o  Appending data to a resource's existing representation(s).

   An origin server indicates response semantics by choosing an appropriate status code depending on the result of processing the POST request; almost all of the status codes defined by this specification might be received in a response to POST (the exceptions being 206 (Partial Content), 304 (Not Modified), and 416 (Range Not Satisfiable)).

   If one or more resources has been created on the origin server as a result of successfully processing a POST request, the origin server SHOULD send a 201 (Created) response containing a Location header field that provides an identifier for the primary resource created (Section 7.1.2) and a representation that describes the status of the request while referring to the new resource(s).

   Responses to POST requests are only cacheable when they include explicit freshness information (see Section 4.2.1 of [RFC7234]). However, POST caching is not widely implemented.  For cases where an origin server wishes the client to be able to cache the result of a POST in a way that can be reused by a later GET, the origin server MAY send a 200 (OK) response containing the result and a Content-Location header field that has the same value as the POST's effective request URI (Section 3.1.4.2).

   If the result of processing a POST would be equivalent to a representation of an existing resource, an origin server MAY redirect the user agent to that resource by sending a 303 (See Other) response with the existing resource's identifier in the Location field.  This has the benefits of providing the user agent a resource identifier and transferring the representation via a method more amenable to shared caching, though at the cost of an extra request if the user agent does not already have the representation cached.