Permalink
Browse files

Add list of HTTP status codes to test page

  • Loading branch information...
1 parent 9f4682e commit da97b3aa4175ffaa7568ecf775f92a8414341531 @execjosh execjosh committed Jul 11, 2010
Showing with 120 additions and 15 deletions.
  1. +15 −3 test/test.html
  2. +105 −12 test/test.js
View
@@ -20,11 +20,23 @@
<td><input type="text" id="slot_time" value="" /></td>
</tr>
<tr>
- <td><input type="button" id="ajax" value="$.ajax()" /></td>
- <td><input type="button" id="ajax-vals" value="$.ajax({})" /></td>
+ <th><label for="http_code">Http Code:</label></th>
+ <td><select id="http_code"></select></td>
</tr>
<tr>
- <td colspan="2"><input type="button" id="ajaxRetrySetup" value="$.ajaxRetrySetup()" /></td>
+ <td colspan="2">
+ <center>
+ <table border="0" cellpadding="0" cellspacing="0">
+ <tr>
+ <td><input type="button" id="ajax" value="$.ajax()" /></td>
+ <td><input type="button" id="ajax-vals" value="$.ajax({})" /></td>
+ </tr>
+ <tr>
+ <td colspan="2"><input type="button" id="ajaxRetrySetup" value="$.ajaxRetrySetup()" /></td>
+ </tr>
+ </table>
+ </center>
+ </td>
</tr>
</table>
View
@@ -44,7 +44,8 @@
'#ajaxRetrySetup',
'#attempts',
'#cutoff',
- '#slot_time'
+ '#slot_time',
+ '#http_code'
].join(', ');
function enableGui(enable){
@@ -58,23 +59,109 @@
// Set-up
$(document).ready(function(){
- var def_opts = {
- attempts: 8,
- cutoff: 5,
- slot_time: 100,
- },
- ajaxSettings = {
- url: 'this/file/does/not/exist',
+ var ajaxSettings = {
+ url: 'test.php',
error: on_error,
success: on_success,
complete: on_complete,
async: true,
cache: false
};
- $('#attempts').val(def_opts.attempts);
- $('#cutoff').val(def_opts.cutoff);
- $('#slot_time').val(def_opts.slot_time);
+ function setup_ui() {
+ var def_opts = {
+ attempts: 8,
+ cutoff: 5,
+ slot_time: 100,
+ },
+ // http://en.wikipedia.org/wiki/List_of_HTTP_status_codes
+ http_codes = {
+ '1xx Informational':[
+ '100 Continue',
+ '101 Switching Protocols',
+ '102 Processing'
+ ],
+ '2xx Success':[
+ '200 OK',
+ '201 Created',
+ '202 Accepted',
+ '203 Non-Authoritative Information',
+ '204 No Content',
+ '205 Reset Content',
+ '206 Partial Content',
+ '207 Multi-Status'
+ ],
+ '3xx Redirection':[
+ '300 Multiple Choices',
+ '301 Moved Permanently',
+ '302 Found',
+ '303 See Other',
+ '304 Not Modified',
+ '305 Use Proxy',
+ '306 Switch Proxy',
+ '307 Temporary Redirect'
+ ],
+ '4xx Client Error':[
+ '400 Bad Request',
+ '401 Unauthorized',
+ '402 Payment Required',
+ '403 Forbidden',
+ '404 Not Found',
+ '405 Method Not Allowed',
+ '406 Not Acceptable',
+ '407 Proxy Authentication Required',
+ '408 Request Timeout',
+ '409 Conflict',
+ '410 Gone',
+ '411 Length Required',
+ '412 Precondition Failed',
+ '413 Request Entity Too Large',
+ '414 Request-URI Too Long',
+ '415 Unsupported Media Type',
+ '416 Requested Range Not Satisfiable',
+ '417 Expectation Failed',
+ '418 I\'m a teapot',
+ '422 Unprocessable Entity',
+ '423 Locked',
+ '424 Failed Dependency',
+ '425 Unordered Collection',
+ '426 Upgrade Required',
+ '449 Retry With',
+ '450 Blocked by Windows Parental Controls'
+ ],
+ '5xx Server Error':[
+ '500 Internal Server Error',
+ '501 Not Implemented',
+ '502 Bad Gateway',
+ '503 Service Unavailable',
+ '504 Gateway Timeout',
+ '505 HTTP Version Not Supported',
+ '506 Variant Also Negotiates',
+ '507 Insufficient Storage',
+ '509 Bandwidth Limit Exceeded',
+ '510 Not Extended'
+ ]
+ },
+ opt_list = [];
+
+ $('#attempts').val(def_opts.attempts);
+ $('#cutoff').val(def_opts.cutoff);
+ $('#slot_time').val(def_opts.slot_time);
+
+ $.each(http_codes, function(key, val){
+ var grp = [];
+ $.each(val, function(){
+ grp.push(['<option>', this, '</option>'].join(''));
+ });
+ opt_list.push([
+ '<optgroup label="', key, '">',
+ grp.join(''),
+ '</optgroup>'
+ ].join(''));
+ });
+
+ $('#http_code').html(opt_list.join(''));
+ }
function getRetryOpts() {
return {
@@ -85,9 +172,15 @@
}
function initiateAjax(opts) {
- $.ajax($.extend(true, {}, ajaxSettings, {retry: opts}));
+ var opts = {
+ retry: opts,
+ data: {http_code:$('#http_code').val()}
+ };
+ $.ajax($.extend(true, {}, ajaxSettings, opts));
}
+ setup_ui();
+
$('#ajax').click(function(){
enableGui(false);
initiateAjax($.extend(true, {}, $.ajaxRetrySettings, {tick: on_tick}));

0 comments on commit da97b3a

Please sign in to comment.