rest - HTTP statuscode to retry same request -
is there http status code instruct client perform same request again?
i facing situation server has "wait" lock disappear when processing request. time lock disappears, requests might close timeout limit. instead, once lock clears, instruct client perform same request again.
the best come http 307 same location, i'm worried browsers might not buy (redirect loop detection).
the correct response, when server unable handle request, 503 service unavailable. when condition temporary, in case, can set retry-after
header let client know how long should wait before trying again.
however, not force browser perform request again - need handle in javascript. example, here how might perform retrying ajax post request in jquery:
function postdata() { $.ajax({ type: 'post', url: '503.php', success: function() { /* whatever need here when successful. */ }, statuscode: { 503: function(jqxhr) { var retryafter = jqxhr.getresponseheader('retry-after'); retryafter = parseint(retryafter, 10); if (!retryafter) retryafter = 5; settimeout(postdata, retryafter * 1000); } } }); }
note above code supports retry-after
header retry delay specified in seconds. if want support dates require little more work. in production code recommend counter of sort make sure don't keep retrying forever.
as using 307 status code repeat request automatically, don't think idea. if add retry parameter around browser loop detection (which feels horrible hack), it's still not going work on post request. rfc2616:
if 307 status code received in response request other or head, user agent must not automatically redirect request unless can confirmed user.
while browsers known ignore requirement, it's not correct, , isn't want rely on.
and if you're not using post request, should be. remember request should not have side effects, , default response cached. description of problem, sounds request doing has side-effects.
Comments
Post a Comment