Post/Redirect/Get
From Wikipedia, the free encyclopedia
Post/Redirect/Get (PRG) is a web development design pattern that prevents some duplicate form submissions, creating a more intuitive interface for user agents (users). PRG implements bookmarks and the refresh button in a predictable way that does not create duplicate form submissions.
Contents[hide] |
[edit]Duplicate form submissions
When a web form is submitted to a server through an HTTP POST request, a web user that attempts to refresh the server response in certain user agents can cause the contents of the original HTTP POST request to be resubmitted, possibly causing undesired results, such as a duplicate web purchase.
To avoid this problem, many web developers use the PRG pattern[1] — instead of returning a web page directly, the POST operation returns a redirection command. The HTTP 1.1 specification introduced the HTTP 303 response code to ensure that in this situation, the web user's browser can safely refresh the server response without causing the initial HTTP POST request to be resubmitted. However most common commercial applications in use today (new and old alike) still continue to issue HTTP 302responses in these situations. Use of HTTP 301 is usually avoided because HTTP-1.1-compliant browsers do not convert the method to GET after receiving HTTP 301, as is more commonly done for HTTP 302.[2] However, HTTP 301 may be preferred in cases where it is not desirable for POST parameters to be converted to GET parameters and thus be recorded in logs.
The PRG pattern cannot address every scenario of duplicate form submission. Some known duplicate form submissions that PRG cannot solve are:
- if a web user refreshes before the initial submission has completed because of server lag, resulting in a duplicate HTTP POST request in certain user agents.
[edit]Bookmarks
User agents store only the URI of an HTTP request as a bookmark. Because of this, an HTTP POST request that results in a response based on the body of the HTTP POST request cannot be bookmarked. By using the PRG pattern, the URI of the HTTP GET request can safely be bookmarked by a web user. It is a question of the persistence of the data and the design of the URI whether bookmarking makes sense and is really working at every step of an application.
[edit]Proxy servers
Since redirects are using absolute URIs, one has to take care about proxy servers (HTTP->HTTPS) and reverse proxy servers. If your application is such that a user uses an SSL tunnel to reach your site, this can cause problems also. (You may be able to use the Referer header to discover the domain and port the user is actually entering.)
[edit]References
- ^ p36, "Universal Design for Web Applications", by Wendy Chisholm and Matt May, O'Reilly Media, Inc., 2008
- ^ "HTTP/1.1".
[edit]External links
- Redirect After Post, Michael Jouravlev, August 2004
- Description of the pattern for J2EE, Michael Jouravlev, August 14, 2003
- GET after POST Adam Vandenberg
- Is the Portlet Programming Model Broken? Subbu Allamaraju
No comments:
Post a Comment