<commit_before><?php
namespace webignition\WebsiteSitemapFinder;

/**
 * Identify if a given URL is (currently) that of a sitemap
 *  
 */
class SitemapIdentifier {
    
    /**
     *
     * @var string
     */
    private $possibleSitemapUrl = null;
    
    
    
    private $validContentTypes = array();
    
    
    /**
     *
     * @var \webignition\Http\Client\Client
     */
    private $httpClient = null;
    
    
    /**
     *
     * @var boolean
     */
    private $isSitemapUrl = null;
    
    
    /**
     *
     * @param array $validContentTypes 
     */
    public function setValidContentTypes($validContentTypes) {
        $this->validContentTypes = $validContentTypes;
    }
    
    /**
     *
     * @return array
     */
    public function getValidContentTypes() {
        return $this->validContentTypes;
    }
    
    
    /**
     *
     * @param string $possibleSitemapUrl 
     */
    public function setPossibleSitemapUrl($possibleSitemapUrl) {
        $this->possibleSitemapUrl = $possibleSitemapUrl;
        $this->isSitemapUrl = null;
    }
    
    
    /**
     *
     * @return boolean
     */
    public function isSitemapUrl() {
        if (is_null($this->isSitemapUrl)) {
            $request = new \HttpRequest($this->possibleSitemapUrl);
            $request->setMethod(HTTP_METH_HEAD);
            $response = $this->getHttpClient()->getResponse($request);
            
            $this->isSitemapUrl = $response->getResponseCode() == 200 && in_array($response->getHeader('content-type'), $this->getValidContentTypes());
        }<commit_msg>Correctly parse content type header when checking if response content type is correct<commit_after><?php
namespace webignition\WebsiteSitemapFinder;

/**
 * Identify if a given URL is (currently) that of a sitemap
 *  
 */
class SitemapIdentifier {
    
    /**
     *
     * @var string
     */
    private $possibleSitemapUrl = null;
    
    
    
    private $validContentTypes = array();
    
    
    /**
     *
     * @var \webignition\Http\Client\Client
     */
    private $httpClient = null;
    
    
    /**
     *
     * @var boolean
     */
    private $isSitemapUrl = null;
    
    
    /**
     *
     * @param array $validContentTypes 
     */
    public function setValidContentTypes($validContentTypes) {
        $this->validContentTypes = $validContentTypes;
    }
    
    /**
     *
     * @return array
     */
    public function getValidContentTypes() {
        return $this->validContentTypes;
    }
    
    
    /**
     *
     * @param string $possibleSitemapUrl 
     */
    public function setPossibleSitemapUrl($possibleSitemapUrl) {
        $this->possibleSitemapUrl = $possibleSitemapUrl;
        $this->isSitemapUrl = null;
    }
    
    
    /**
     *
     * @return boolean
     */
    public function isSitemapUrl() {
        if (is_null($this->isSitemapUrl)) {
            $request = new \HttpRequest($this->possibleSitemapUrl);
            $request->setMethod(HTTP_METH_HEAD);
            $response = $this->getHttpClient()->getResponse($request);
            
            if ($response->getResponseCode() == 200) {
                $mediaTypeParser = new \webignition\InternetMediaType\Parser\Parser();
                $contentType = $mediaTypeParser->parse($response->getHeader('content-type'));
                
                $this->isSitemapUrl = in_array($contentType->getTypeSubtypeString(), $this->getValidContentTypes());
            } else {
                $this->isSitemapUrl = false;
            }
        }
{'fraction_non_alphanumeric': 0.12007874015748031, 'fraction_numerical': 0.001687289088863892, 'mean_word_length': 1.9396694214876034, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 32, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1561733', 'n_tokens_mistral': 1071, 'n_tokens_neox': 1052, 'n_words': 175}