<commit_before>/******************************************************
 * Web crawler
 * 
 *
 * Copyright (C) 2012 by <NAME> (http://peterhedenskog.com)
 *
 ******************************************************
 *
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in 
 * compliance with the License. You may obtain a copy of the License at
 * 
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software distributed under the License is 
 * distributed  on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.   
 * See the License for the specific language governing permissions and limitations under the License.
 *
 *******************************************************
 */
package com.soulgalore.crawler.core;

import java.util.Map;

import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;

import com.google.common.base.Objects;

/**
 * The response for a html page.
 * 
 */
public class HTMLPageResponse {

	private static final int NO_HTTP_PORT = -1;
	
	private final Document doc;
	private final String encoding;
	private final PageURL url;
	private final int responseCode;

	/**
	 * Create a response.
	 * @param pageUrl the url
	 * @param theResponseCode the response code
	 * @param theHeaders the headers
	 * @param theBody the body
	 * @param theEncoding the encoding
	 * @param theSize the size
	 */
	public HTMLPageResponse(PageURL pageUrl, int theResponseCode,
			Map<String, String> theHeaders, String theBody, String theEncoding,
			long theSize) {
		encoding = theEncoding;
		url = pageUrl;
		responseCode = theResponseCode;

		// special hack:
		// if the path contains a . (.html etc) then use the full path,
		//
		// relative links using ../ get's confused if the path don't
		// ends with an /

		final String baseUri = pageUrl.getUri().getScheme()
				+ ":"
				+ ((pageUrl.getUri().getPort() != NO_HTTP_PORT) ? pageUrl
						.getUri().getPort() : "")
				+ "//"
				+ pageUrl.getUri().getHost()
				+ ((pageUrl.getUri().getPath().contains(".")) ? pageUrl
						.getUri().getPath() : pageUrl.getUri().getPath()
						+ (pageUrl.getUri().getPath().endsWith("/") ? "" : "/"));

		doc = Jsoup.parse(theBody, baseUri);
<commit_msg>fixed defect when accessing sites running on ports!=80<commit_after>/******************************************************
 * Web crawler
 * 
 *
 * Copyright (C) 2012 by <NAME> (http://peterhedenskog.com)
 *
 ******************************************************
 *
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in 
 * compliance with the License. You may obtain a copy of the License at
 * 
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software distributed under the License is 
 * distributed  on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.   
 * See the License for the specific language governing permissions and limitations under the License.
 *
 *******************************************************
 */
package com.soulgalore.crawler.core;

import java.util.Map;

import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;

import com.google.common.base.Objects;

/**
 * The response for a html page.
 * 
 */
public class HTMLPageResponse {

	private static final int NO_HTTP_PORT = -1;
	
	private final Document doc;
	private final String encoding;
	private final PageURL url;
	private final int responseCode;

	/**
	 * Create a response.
	 * @param pageUrl the url
	 * @param theResponseCode the response code
	 * @param theHeaders the headers
	 * @param theBody the body
	 * @param theEncoding the encoding
	 * @param theSize the size
	 */
	public HTMLPageResponse(PageURL pageUrl, int theResponseCode,
			Map<String, String> theHeaders, String theBody, String theEncoding,
			long theSize) {
		encoding = theEncoding;
		url = pageUrl;
		responseCode = theResponseCode;

		// special hack:
		// if the path contains a . (.html etc) then use the full path,
		//
		// relative links using ../ get's confused if the path don't
		// ends with an /

		final String baseUri = pageUrl.getUri().getScheme()
				+ "://"
				+ pageUrl.getUri().getHost()
				+ ((pageUrl.getUri().getPort() != NO_HTTP_PORT) ? ":" + pageUrl
						.getUri().getPort() : "")
				+ ((pageUrl.getUri().getPath().contains(".")) ? pageUrl
						.getUri().getPath() : pageUrl.getUri().getPath()
						+ (pageUrl.getUri().getPath().endsWith("/") ? "" : "/"));
	
		doc = Jsoup.parse(theBody, baseUri);

{'fraction_non_alphanumeric': 0.18000429092469428, 'fraction_numerical': 0.004290924694271616, 'mean_word_length': 3.676028084252758, 'pattern_counts': {'":': 3, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '5628181', 'n_tokens_mistral': 1446, 'n_tokens_neox': 1296, 'n_words': 445}