origin() . $path; $plain = $this->http_get( $url, 'GET ' . $path, $evidence ); if ( '' !== $plain['error'] && 0 === $plain['code'] ) { return $this->unable( 'Could not reach the site — ' . $plain['error'], $evidence ); } $details = array( 'path' => $path, 'htmlStatus' => $plain['code'], ); if ( ! in_array( $plain['code'], array( 404, 410 ), true ) ) { $evidence[] = Evidence::parse( 'Check status code', 'negative', 'A nonexistent path returned HTTP ' . $plain['code'] . ' instead of 404.' ); return $this->fail( 'Missing pages return HTTP ' . $plain['code'] . ' instead of 404 — agents cannot tell a dead link from a real page', $evidence, $details ); } $evidence[] = Evidence::parse( 'Check status code', 'positive', 'Nonexistent path returns HTTP ' . $plain['code'] . '.' ); $md = $this->http_get( $url, 'GET ' . $path . ' (Accept: text/markdown)', $evidence, array( 'headers' => array( 'Accept' => 'text/markdown' ) ) ); $ctype = isset( $md['headers']['content-type'] ) ? $md['headers']['content-type'] : ''; $details['markdownStatus'] = $md['code']; $details['markdownContentType'] = $ctype; if ( ! in_array( $md['code'], array( 404, 410 ), true ) || 0 !== stripos( $ctype, 'text/markdown' ) ) { $evidence[] = Evidence::parse( 'Check the Markdown variant of the error page', 'negative', 'HTTP ' . $md['code'] . ', Content-Type ' . ( '' !== $ctype ? $ctype : '(none)' ) . ' — agents asking for Markdown get an HTML error page.' ); return $this->fail( '404 status is correct, but the error page is not served as Markdown for agents', $evidence, $details ); } $evidence[] = Evidence::parse( 'Check the Markdown variant of the error page', 'positive', 'HTTP ' . $md['code'] . ' with a text/markdown body.' ); return $this->pass( 'Missing pages return a real 404, as Markdown when an agent asks for it', $evidence, $details ); } }