<commit_before>/*****************************************************************************
*  Copyright 2011 <NAME>
*
*  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.
* *****************************************************************************/

/*****
 * Author: <NAME> <EMAIL>
 *
 * Slow HTTP attack vulnerability test tool
 *  http://code.google.com/p/slowhttptest/
 *****/
#include "config.h"
#include "slowhttptest.h"

#include <errno.h>
#include <math.h>
#include <stdio.h>
#include <unistd.h>

#include <numeric>
#include <sstream>
#include <string>
#include <cstring>
#include <vector>

#include <netdb.h>
#include <netinet/in.h>
#ifdef HAVE_POLL
#include <sys/poll.h>
#endif
#include <sys/time.h>
#include <sys/resource.h>
#include <sys/socket.h>

#include "range-generator.h"
#include "slowlog.h"
#include "slowsocket.h"
#include "slowhttptest.h"
#include "slowstats.h"
#include "text-generator.h"

// Global flag to indicate if we need to run.
extern int g_running;

namespace {
static const int kBufSize = 65537;
// update ExitStatusType too
static const char* exit_status_msg[] = {
    "Hit test time limit",
    "No open connections left",
    "Cannot establish connection",
    "Connection refused",
    "Cancelled by user",
    "Unexpected error"
};
// update ProxyType too 
static const char* proxy_type_name[] = {
    "HTTP proxy at ",
    "HTTP tunnel at ",
    "SOCKS 4 at ",
    "SOCKS 5 at ",
    "probe proxy at ",
    "no proxy"
};
static const char* test_type_name[] = {
    "SLOW HEADERS",
    "SLOW BODY",
    "RANGE",
    "SLOW READ"
};
static const char* user_agents[] = {
    "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/33.0.1750.152 Safari/537.36"
    "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_2) AppleWebKit/537.75.14 (KHTML, like Gecko) Version/7.0.3 Safari/537.75.14",
    "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.9; rv:27.0) Gecko/20100101 Firefox/27.0"
    "AppleWebKit/533.21.1 (KHTML, like Gecko) Version/5.0.5 Safari/533.21.1",
    "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.7; rv:5.0.1) "
    "msnbot-131-253-46-102.search.msn.com",
    "Mozilla/5.0 (Windows NT 6.1; WOW64; Trident/7.0; rv:11.0) like Gecko"
    "AppleWebKit/534.30 (KHTML, like Gecko) Chrome/12.0.742.122 Safari/534.30",
    "Opera/9.80 (Macintosh; Intel Mac OS X 10.7.0; U; Edition MacAppStore; en) "
    "Mozilla/5.0 (Macintosh; Intel Mac OS X) AppleWebKit/534.34 (KHTML,like Gecko) PhantomJS/1.9.0 (development) Safari/534.34",
    "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; Trident/4.0; SLCC2)"
};
static const char referer[] = 
    "Referer: https://github.com/shekyan/slowhttptest/\r\n";
static const char content_type_default[] = "Content-Type: application/x-www-form-urlencoded\r\n";
static const char accept_default[] = "Accept: text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5\r\n"; 
static const char post_request[] = "Connection: close\r\n"
    "\r\n"
    "foo=bar";
// per RFC 2616 section 4.2, header can be any US_ASCII character (0-127),
// but we'll start with X-
static const char header_prefix[] = "X-";
static const char header_separator[] = ": ";

static const char body_prefix[] = "&";
static const char body_separator[] = "=";

static const char crlf[] = "\r\n";
static const char peer_closed[] = "Peer closed connection";

}  // namespace

namespace slowhttptest {
SlowHTTPTest::SlowHTTPTest(int delay, int duration, 
                           int interval, int con_cnt,
                           int max_random_data_len,
                           int content_length, SlowTestType type,
                           bool need_stats, int pipeline_factor, 
                           int probe_interval,<commit_msg>Update default Referer header value<commit_after>/*****************************************************************************
*  Copyright 2011 <NAME>
*
*  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.
* *****************************************************************************/

/*****
 * Author: <NAME> <EMAIL>
 *
 * Slow HTTP attack vulnerability test tool
 *  http://code.google.com/p/slowhttptest/
 *****/
#include "config.h"
#include "slowhttptest.h"

#include <errno.h>
#include <math.h>
#include <stdio.h>
#include <unistd.h>

#include <numeric>
#include <sstream>
#include <string>
#include <cstring>
#include <vector>

#include <netdb.h>
#include <netinet/in.h>
#ifdef HAVE_POLL
#include <sys/poll.h>
#endif
#include <sys/time.h>
#include <sys/resource.h>
#include <sys/socket.h>

#include "range-generator.h"
#include "slowlog.h"
#include "slowsocket.h"
#include "slowhttptest.h"
#include "slowstats.h"
#include "text-generator.h"

// Global flag to indicate if we need to run.
extern int g_running;

namespace {
static const int kBufSize = 65537;
// update ExitStatusType too
static const char* exit_status_msg[] = {
    "Hit test time limit",
    "No open connections left",
    "Cannot establish connection",
    "Connection refused",
    "Cancelled by user",
    "Unexpected error"
};
// update ProxyType too 
static const char* proxy_type_name[] = {
    "HTTP proxy at ",
    "HTTP tunnel at ",
    "SOCKS 4 at ",
    "SOCKS 5 at ",
    "probe proxy at ",
    "no proxy"
};
static const char* test_type_name[] = {
    "SLOW HEADERS",
    "SLOW BODY",
    "RANGE",
    "SLOW READ"
};
static const char* user_agents[] = {
    "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/33.0.1750.152 Safari/537.36"
    "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_2) AppleWebKit/537.75.14 (KHTML, like Gecko) Version/7.0.3 Safari/537.75.14",
    "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.9; rv:27.0) Gecko/20100101 Firefox/27.0"
    "AppleWebKit/533.21.1 (KHTML, like Gecko) Version/5.0.5 Safari/533.21.1",
    "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.7; rv:5.0.1) "
    "msnbot-131-253-46-102.search.msn.com",
    "Mozilla/5.0 (Windows NT 6.1; WOW64; Trident/7.0; rv:11.0) like Gecko"
    "AppleWebKit/534.30 (KHTML, like Gecko) Chrome/12.0.742.122 Safari/534.30",
    "Opera/9.80 (Macintosh; Intel Mac OS X 10.7.0; U; Edition MacAppStore; en) "
    "Mozilla/5.0 (Macintosh; Intel Mac OS X) AppleWebKit/534.34 (KHTML,like Gecko) PhantomJS/1.9.0 (development) Safari/534.34",
    "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; Trident/4.0; SLCC2)"
};
static const char referer[] = 
    "Referer: TESTING_PURPOSES_ONLY\r\n";
static const char content_type_default[] = "Content-Type: application/x-www-form-urlencoded\r\n";
static const char accept_default[] = "Accept: text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5\r\n"; 
static const char post_request[] = "Connection: close\r\n"
    "\r\n"
    "foo=bar";
// per RFC 2616 section 4.2, header can be any US_ASCII character (0-127),
// but we'll start with X-
static const char header_prefix[] = "X-";
static const char header_separator[] = ": ";

static const char body_prefix[] = "&";
static const char body_separator[] = "=";

static const char crlf[] = "\r\n";
static const char peer_closed[] = "Peer closed connection";

}  // namespace

namespace slowhttptest {
SlowHTTPTest::SlowHTTPTest(int delay, int duration, 
                           int interval, int con_cnt,
                           int max_random_data_len,
                           int content_length, SlowTestType type,
                           bool need_stats, int pipeline_factor, 
                           int probe_interval,
{'fraction_non_alphanumeric': 0.16882192430893345, 'fraction_numerical': 0.0460315577174042, 'mean_word_length': 3.496, 'pattern_counts': {'":': 2, '<': 39, '<?xml version=': 0, '>': 39, 'https://': 1, 'lorem ipsum': 0, 'www.': 4, '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': '3176033', 'n_tokens_mistral': 3132, 'n_tokens_neox': 2853, 'n_words': 837}