diff --git a/linkchecker.module b/linkchecker.module index cb3a8ac..be4f8e4 100644 --- a/linkchecker.module +++ b/linkchecker.module @@ -2270,58 +2270,189 @@ function _linkchecker_link_check_status_filter($url) { } /** - * Defines the list of allowed response codes for form input validation. + * Defines the list of allowed response codes. + * + * @return array + * TRUE if the status code is valid, otherwise FALSE. + */ +function _linkchecker_valid_response_codes() { + $responses = array( + 100 => array( + 'summary' => 'Continue', + 'description' => 'This means that the server has received the request headers, and that the client should proceed to send the request body (in the case of a request for which a body needs to be sent; for example, a POST request). If the request body is large, sending it to a server when a request has already been rejected based upon inappropriate headers is inefficient. To have a server check if the request could be accepted based on the request\'s headers alone, a client must send Expect: 100-continue as a header in its initial request and check if a 100 Continue status code is received in response before continuing (or receive 417 Expectation Failed and not continue).', + ), + 101 => array( + 'summary' => 'Switching Protocols', + 'description' => 'This means the requester has asked the server to switch protocols and the server is acknowledging that it will do so.', + ), + 200 => array( + 'summary' => 'OK', + 'description' => 'Standard response for successful HTTP requests. The actual response will depend on the request method used. In a GET request, the response will contain an entity corresponding to the requested resource. In a POST request the response will contain an entity describing or containing the result of the action.', + ), + 201 => array( + 'summary' => 'Created', + 'description' => 'The request has been fulfilled and resulted in a new resource being created.', + ), + 202 => array( + 'summary' => 'Accepted', + 'description' => 'The request has been accepted for processing, but the processing has not been completed. The request might or might not eventually be acted upon, as it might be disallowed when processing actually takes place.', + ), + 203 => array( + 'summary' => 'Non-Authoritative Information', + 'description' => 'The server successfully processed the request, but is returning information that may be from another source.', + ), + 204 => array( + 'summary' => 'No Content', + 'description' => 'The server successfully processed the request, but is not returning any content. Usually used as a response to a successful delete request.', + ), + 205 => array( + 'summary' => 'Reset Content', + 'description' => 'The server successfully processed the request, but is not returning any content. Unlike a 204 response, this response requires that the requester reset the document view.', + ), + 206 => array( + 'summary' => 'Partial Content', + 'description' => 'The server is delivering only part of the resource (byte serving) due to a range header sent by the client. The range header is used by tools like wget to enable resuming of interrupted downloads, or split a download into multiple simultaneous streams.', + ), + 300 => array( + 'summary' => 'Multiple Choices', + 'description' => 'Indicates multiple options for the resource that the client may follow. It, for instance, could be used to present different format options for video, list files with different extensions, or word sense disambiguation.', + ), + 301 => array( + 'summary' => 'Moved Permanently', + 'description' => 'This and all future requests should be directed to the given URI.', + ), + 302 => array( + 'summary' => 'Found', + 'description' => 'This is an example of industry practice contradicting the standard. The HTTP/1.0 specification (RFC 1945) required the client to perform a temporary redirect (the original describing phrase was "Moved Temporarily"), but popular browsers implemented 302 with the functionality of a 303 See Other. Therefore, HTTP/1.1 added status codes 303 and 307 to distinguish between the two behaviours. However, some Web applications and frameworks use the 302 status code as if it were the 303.', + ), + 303 => array( + 'summary' => 'See Other', + 'description' => 'The response to the request can be found under another URI using a GET method. When received in response to a POST (or PUT/DELETE), it should be assumed that the server has received the data and the redirect should be issued with a separate GET message.', + ), + 304 => array( + 'summary' => 'Not Modified', + 'description' => 'Indicates that the resource has not been modified since the version specified by the request headers If-Modified-Since or If-None-Match. This means that there is no need to retransmit the resource, since the client still has a previously-downloaded copy.', + ), + 305 => array( + 'summary' => 'Use Proxy', + 'description' => 'The requested resource is only available through a proxy, whose address is provided in the response. Many HTTP clients (such as Mozilla and Internet Explorer) do not correctly handle responses with this status code, primarily for security reasons.', + ), + 307 => array( + 'summary' => 'Temporary Redirect', + 'description' => 'In this case, the request should be repeated with another URI; however, future requests should still use the original URI. In contrast to how 302 was historically implemented, the request method is not allowed to be changed when reissuing the original request. For instance, a POST request should be repeated using another POST request.', + ), + 400 => array( + 'summary' => 'Bad Request', + 'description' => 'The server cannot or will not process the request due to something that is perceived to be a client error.', + ), + 401 => array( + 'summary' => 'Unauthorized', + 'description' => 'Similar to 403 Forbidden, but specifically for use when authentication is required and has failed or has not yet been provided. The response must include a WWW-Authenticate header field containing a challenge applicable to the requested resource.', + ), + 402 => array( + 'summary' => 'Payment Required', + 'description' => 'Reserved for future use. The original intention was that this code might be used as part of some form of digital cash or micropayment scheme, but that has not happened, and this code is not usually used. YouTube uses this status if a particular IP address has made excessive requests, and requires the person to enter a CAPTCHA.', + ), + 403 => array( + 'summary' => 'Forbidden', + 'description' => 'The request was a valid request, but the server is refusing to respond to it. Unlike a 401 Unauthorized response, authenticating will make no difference.', + ), + 404 => array( + 'summary' => 'Not Found', + 'description' => 'The requested resource could not be found but may be available again in the future. Subsequent requests by the client are permissible.', + ), + 405 => array( + 'summary' => 'Method Not Allowed', + 'description' => 'A request was made of a resource using a request method not supported by that resource; for example, using GET on a form which requires data to be presented via POST, or using PUT on a read-only resource.', + ), + 406 => array( + 'summary' => 'Not Acceptable', + 'description' => 'The requested resource is only capable of generating content not acceptable according to the Accept headers sent in the request.', + ), + 407 => array( + 'summary' => 'Proxy Authentication Required', + 'description' => 'The client must first authenticate itself with the proxy.', + ), + 408 => array( + 'summary' => 'Request Timeout', + 'description' => 'The server timed out waiting for the request. According to HTTP specifications: "The client did not produce a request within the time that the server was prepared to wait. The client MAY repeat the request without modifications at any later time."', + ), + 409 => array( + 'summary' => 'Conflict', + 'description' => 'Indicates that the request could not be processed because of conflict in the request, such as an edit conflict in the case of multiple updates.', + ), + 410 => array( + 'summary' => 'Gone', + 'description' => 'Indicates that the resource requested is no longer available and will not be available again. This should be used when a resource has been intentionally removed and the resource should be purged. Upon receiving a 410 status code, the client should not request the resource again in the future. Clients such as search engines should remove the resource from their indices. [citation needed] Most use cases do not require clients and search engines to purge the resource, and a "404 Not Found" may be used instead.', + ), + 411 => array( + 'summary' => 'Length Required', + 'description' => 'The request did not specify the length of its content, which is required by the requested resource.', + ), + 412 => array( + 'summary' => 'Precondition Failed', + 'description' => 'The server does not meet one of the preconditions that the requester put on the request.', + ), + 413 => array( + 'summary' => 'Request Entity Too Large', + 'description' => 'The request is larger than the server is willing or able to process.', + ), + 414 => array( + 'summary' => 'Request-URI Too Long', + 'description' => 'The URI provided was too long for the server to process. Often the result of too much data being encoded as a query-string of a GET request, in which case it should be converted to a POST request.', + ), + 415 => array( + 'summary' => 'Unsupported Media Type', + 'description' => 'The request entity has a media type which the server or resource does not support. For example, the client uploads an image as image/svg+xml, but the server requires that images use a different format.', + ), + 416 => array( + 'summary' => 'Requested Range Not Satisfiable', + 'description' => 'The client has asked for a portion of the file (byte serving), but the server cannot supply that portion. For example, if the client asked for a part of the file that lies beyond the end of the file.', + ), + 417 => array( + 'summary' => 'Expectation Failed', + 'description' => 'The server cannot meet the requirements of the Expect request-header field.', + ), + 500 => array( + 'summary' => 'Internal Server Error', + 'description' => 'A generic error message, given when an unexpected condition was encountered and no more specific message is suitable.', + ), + 501 => array( + 'summary' => 'Not Implemented', + 'description' => 'The server either does not recognize the request method, or it lacks the ability to fulfil the request. Usually this implies future availability (e.g., a new feature of a web-service API).', + ), + 502 => array( + 'summary' => 'Bad Gateway', + 'description' => 'The server was acting as a gateway or proxy and received an invalid response from the upstream server.', + ), + 503 => array( + 'summary' => 'Service Unavailable', + 'description' => 'The server is currently unavailable (because it is overloaded or down for maintenance). Generally, this is a temporary state.', + ), + 504 => array( + 'summary' => 'Gateway Timeout', + 'description' => 'The server was acting as a gateway or proxy and did not receive a timely response from the upstream server.', + ), + 505 => array( + 'summary' => 'HTTP Version Not Supported', + 'description' => 'The server does not support the HTTP protocol version used in the request.', + ), + ); + + return $responses; +} + +/** + * Checks response code against allowed codes for for form input validation. * * @param int $code - * An numeric response code. + * An numeric response code to check. * * @return bool * TRUE if the status code is valid, otherwise FALSE. */ function _linkchecker_isvalid_response_code($code) { - - $responses = array( - 100 => 'Continue', - 101 => 'Switching Protocols', - 200 => 'OK', - 201 => 'Created', - 202 => 'Accepted', - 203 => 'Non-Authoritative Information', - 204 => 'No Content', - 205 => 'Reset Content', - 206 => 'Partial Content', - 300 => 'Multiple Choices', - 301 => 'Moved Permanently', - 302 => 'Found', - 303 => 'See Other', - 304 => 'Not Modified', - 305 => 'Use Proxy', - 307 => 'Temporary Redirect', - 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 Time-out', - 409 => 'Conflict', - 410 => 'Gone', - 411 => 'Length Required', - 412 => 'Precondition Failed', - 413 => 'Request Entity Too Large', - 414 => 'Request-URI Too Large', - 415 => 'Unsupported Media Type', - 416 => 'Requested range not satisfiable', - 417 => 'Expectation Failed', - 500 => 'Internal Server Error', - 501 => 'Not Implemented', - 502 => 'Bad Gateway', - 503 => 'Service Unavailable', - 504 => 'Gateway Time-out', - 505 => 'HTTP Version not supported', - ); + $responses = _linkchecker_valid_response_codes(); return array_key_exists($code, $responses); } diff --git a/linkchecker.pages.inc b/linkchecker.pages.inc index b533149..391d99f 100644 --- a/linkchecker.pages.inc +++ b/linkchecker.pages.inc @@ -128,6 +128,8 @@ function _linkchecker_report_page($query, $account = NULL) { ->orderByHeader($header) ->execute(); + $response_info = _linkchecker_valid_response_codes(); + // Evaluate permission once for performance reasons. $access_edit_link_settings = user_access('edit link settings'); $access_administer_blocks = user_access('administer blocks'); @@ -181,11 +183,16 @@ function _linkchecker_report_page($query, $account = NULL) { $links[] = l(t('Create redirection'), 'admin/config/search/redirect/add', array('query' => array('source' => $link->internal, drupal_get_destination()))); } + $response_content = '

' . $link->code . '

'; + if (isset($response_info[$link->code])) { + $response_content .= '

' . $response_info[$link->code]['description'] . '

'; + } + // Create table data for output. $rows[] = array( 'data' => array( l(_filter_url_trim($link->url, 40), $link->url), - $link->code, + $response_content, check_plain($link->error), theme('item_list', array('items' => $links)), ),