<commit_before>#!/usr/bin/python
######################################################################
# Cloud Routes Availability Manager: http-keyword module
# ------------------------------------------------------------------
# This is a module for performing http keyword searches.
# This will return true if no errors or false if there are errors
# ------------------------------------------------------------------
# Version: Alpha.20140827
# Original Author: <NAME> - <EMAIL>
# Contributors:
# - your name here
######################################################################

import requests
import re
import cStringIO

# currently the http get size limit is 2MB
# change the following function to allow for per user, size limit
def get_max_size():
    return 2*1024*1024 


def check(data):
    """ Perform a http get request and validate the return code """
    headers = {'host': data['data']['host']}
    timeout = 3.00
    url = data['data']['url']
    try:
        result = requests.get(
            url, timeout=timeout, headers=headers, verify=False, stream=True)

        stream = cStringIO.StringIO()
        length = 0
        for chunk in result.iter_content(2048, decode_unicode=True):
            stream.write(chunk)
            length += len(chunk)
            if length > get_max_size():
                break
        
        retext = stream.getvalue()<commit_msg>8192 is a good compromise between speed and memory usage for chunk size<commit_after>#!/usr/bin/python
######################################################################
# Cloud Routes Availability Manager: http-keyword module
# ------------------------------------------------------------------
# This is a module for performing http keyword searches.
# This will return true if no errors or false if there are errors
# ------------------------------------------------------------------
# Version: Alpha.20140827
# Original Author: <NAME> - <EMAIL>
# Contributors:
# - your name here
######################################################################

import requests
import re
import cStringIO

# currently the http get size limit is 2MB
# change the following function to allow for per user, size limit
def get_max_size():
    return 2*1024*1024 


def check(data):
    """ Perform a http get request and validate the return code """
    headers = {'host': data['data']['host']}
    timeout = 3.00
    url = data['data']['url']
    try:
        result = requests.get(
            url, timeout=timeout, headers=headers, verify=False, stream=True)

        stream = cStringIO.StringIO()
        length = 0
        for chunk in result.iter_content(8192, decode_unicode=True):
            stream.write(chunk)
            length += len(chunk)
            if length > get_max_size():
                break
        
        retext = stream.getvalue()
{'fraction_non_alphanumeric': 0.2687719298245614, 'fraction_numerical': 0.019649122807017545, 'mean_word_length': 2.2732491389207805, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 9, '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': '7548576', 'n_tokens_mistral': 716, 'n_tokens_neox': 651, 'n_words': 237}