<?xml version="1.0" encoding="UTF-8" standalone="yes"?><feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en-us"><id>https://blog.pgxn.org/tags/rdg/</id><title>RDG</title><updated>2010-09-29T21:10:00Z</updated><link rel="self" type="application/atom+xml" href="https://blog.pgxn.org/tags/rdg/feed.xml"/><link rel="alternate" type="text/html" href="https://blog.pgxn.org/tags/rdg/"/><author><name>The PGXN Maintainers</name></author><generator uri="https://gohugo.io/" version="0.167.0">Hugo</generator><entry><id>https://blog.pgxn.org/post/1212136083</id><title type="html">Conflict and Redirection on POST</title><link rel="alternate" type="text/html" href="https://blog.pgxn.org/2010/conflict-redirection-on-post/"/><updated>2026-10-07T16:13:48Z</updated><published>2010-09-29T21:10:00Z</published><author><name>David E. Wheeler</name></author><category scheme="https://blog.pgxn.org/tags" term="http" label="Http"/><category scheme="https://blog.pgxn.org/tags" term="post" label="Post"/><category scheme="https://blog.pgxn.org/tags" term="redirect" label="Redirect"/><category scheme="https://blog.pgxn.org/tags" term="rdg" label="RDG"/><category scheme="https://blog.pgxn.org/tags" term="post/redirect/get" label="Post/Redirect/Get"/><category scheme="https://blog.pgxn.org/tags" term="conflict" label="Conflict"/><category scheme="https://blog.pgxn.org/tags" term="http-status-codes" label="HTTP Status Codes"/><summary type="html"><![CDATA[Had an interesting discussion on <a href="#ZgotmplZ">#plack</a>. The upload form, which takes a POST
request for an upload, sends a redirect on a successful form submission. This
is known as the <a href="https://en.wikipedia.org/wiki/Post/Redirect/Get">Post/Redirect/Get (RDG)</a> pattern, though I didn&rsquo;t know that
before <a href="https://duckduckgo.com/?q=redirect&#43;from&#43;post">DuckDuckGoing it</a> it today. But I realized that the code was <em>not</em>
redirecting on a failed form submission, but reloading the form. I was
thinking that one should always redirect on POST, and so was looking into a
Rails-like <code>flash</code> pattern to cache an error message and the form contents on
the redirect. But in this discussion, I learned a few things:]]></summary><content type="html" xml:base="https://blog.pgxn.org/" xml:space="preserve"><![CDATA[<p>Had an interesting discussion on <a href="#ZgotmplZ">#plack</a>. The upload form, which takes a POST
request for an upload, sends a redirect on a successful form submission. This
is known as the <a href="https://en.wikipedia.org/wiki/Post/Redirect/Get">Post/Redirect/Get (RDG)</a> pattern, though I didn&rsquo;t know that
before <a href="https://duckduckgo.com/?q=redirect&#43;from&#43;post">DuckDuckGoing it</a> it today. But I realized that the code was <em>not</em>
redirecting on a failed form submission, but reloading the form. I was
thinking that one should always redirect on POST, and so was looking into a
Rails-like <code>flash</code> pattern to cache an error message and the form contents on
the redirect. But in this discussion, I learned a few things:</p>
<ol>
<li>
<p>One should use <a href="https://tools.ietf.org/html/rfc2616#section-10.3.4">HTTP 1.1 status code 303</a> rather than <a href="https://tools.ietf.org/html/rfc2616#section-10.3.3">status code 302</a>
for these sorts of redirects. Apparently, this status code, called &ldquo;See
Other,&rdquo; is specifically designed for use redirecting from a POST. Thanks
to <a href="https://blog.weftsoar.net/">counfound</a> for pointing that out.</p>
</li>
<li>
<p>The whole point of RDG is to prevent a double form submission. But the
truth is, in the case of an error, you <em>want</em> a second form submission.
For errors &ndash; such as a username conflict or a malformed distribution
archive &ndash; the POST failed, so you show the form again along with a
message about the problem and how to fix it.</p>
</li>
</ol>
<p>What&rsquo;s nice about this is that it&rsquo;s already the way I was doing it! In fact,
for such errors, I&rsquo;m returning <a href="https://tools.ietf.org/html/rfc2616#section-10.4.10">HTTP status code 409</a>, which indicates that
the request failed due to a conflict, and the user should fix it and resubmit.
So no need to redirect on failure. Yay!</p>
<p>Note that for XMLHttpRequests, I&rsquo;m not redirecting at all, but simply
returning the proper status code (success or conflict, generally) and a
fragment to be used to show an error message (or &ldquo;success&rdquo;) (in HTML, JSON, or
plain text, depending on the requestor&rsquo;s preferred type).</p>
<p>I think this works pretty well, and I&rsquo;m pleased to be making good use of HTTP.
Does it make sense to you?</p>
]]></content></entry></feed>