<commit_before>const http = require("http"),
	url = require("url"),
	path = require("path"),
	regex = require(path.join(__dirname, "regex.js")),
	pkg = require(path.join(__dirname, "..", "package.json")),
	jar = new Map(),
	captured = new Map(),
	etags = new Map(),
	jsonMimetype = "application/json";

let http2;

try {
	http2 = require("http2");
} catch (e) {
	http2 = null;
}

class TinyHTTPTest {
	constructor (uri, method, headers, body, timeout, isHttp2) {
		const parsed = url.parse(uri);

		this.body = "";
		this.capture = new Set();
		this.etag = false;
		this.expects = new Map();

		this.expects.set("status", 0);
		this.expects.set("body", "");
		this.expects.set("headers", new Map());
		this.expects.set("values", new Map());

		this.headers = {};
		this.http2 = isHttp2;
		this.options = {
			body: body,
			hostname: parsed.hostname,
			uri: uri,
			method: method,
			path: parsed.path,
			port: parsed.port,
			protocol: parsed.protocol,
			headers: headers,
			timeout: timeout
		};

		this.options.headers["user-agent"] = "tiny-httptest bot/" + pkg.version + " (" + pkg.homepage + ")";

		if (parsed.auth) {
			this.options.auth = parsed.auth;
		}

		if (this.options.body) {
			this.send(this.options.body);
		}

		this.jar = false;
		this.req = null;
		this.res = null;
		this.reuse = new Set();
		this.status = 0;
	}

	captureHeader (name) {
		if (!this.capture.has(name)) {
			this.capture.add(name);
		}

		return this;
	}

	cookies (state = true) {
		this.jar = state;

		return this;
	}

	cors (arg) {
		const origin = arg || this.options.hostname;

		this.options.headers.origin = origin;
		this.options.headers["access-control-request-headers"] = "content-type";
		this.expectHeader("access-control-allow-methods", regex.headersGet);
		this.expectHeader("access-control-allow-origin", origin);
		this.expectHeader("access-control-allow-credentials", "true");

		if (this.options.method === "OPTIONS") {
			this.expectHeader("access-control-allow-headers", regex.headersContentType);
		} else {
			this.expectHeader("access-control-expose-headers", regex.headersContentType);
		}

		return this;
	}

	end () {
		return new Promise((resolve, reject) => {
			const done = err => {
				if (err !== void 0) {
					reject(err);
				} else {
					try {
						this.process();
						resolve(this);
					} catch (e) {
						reject(e);
					}
				}
			};

			let cookie, etag;

			if (!this.req) {
				if (this.jar) {
					cookie = jar.get(this.options.hostname + ":" + this.options.port);

					if (cookie) {
						this.options.headers.cookie = cookie;
					}
				}

				if (this.etag) {
					etag = etags.get(this.options.hostname + ":" + this.options.port + this.options.path);

					if (etag) {
						this.options.headers["if-none-match"] = etag;
					}
				}

				if (this.reuse.size > 0) {
					this.reuse.forEach(k => {
						if (captured.has(k)) {
							this.options.headers[k] = captured.get(k);
						}
					});
				}

				if (this.http2 === false) {
					this.req = http.request(this.options, res => {
						this.res = res;
						res.setEncoding("utf8");

						res.on("data", chunk => {
							this.body += chunk;
						});

						res.on("end", done);
					});

					this.req.on("error", done);

					if (this.options.body) {
						this.req.write(this.options.body);
					}

					this.req.end();
				} else if (http2 === null) {
					done(new Error("http2 is not available"));
				} else {
					const client = http2.connect((this.options.protocol || "https://") + this.options.hostname + ":" + this.options.port, {
							rejectUnauthorized: false
						}),
						doned = () => {
							client.destroy();
							done();
						};

					client.on("error", doned);
					client.on("socketError", doned);

					this.options.headers[":path"] = this.options.path;
					this.options.headers[":method"] = this.options.method;

					this.req = client.request(this.options.headers);
					this.req.setEncoding("utf8");
					this.res = {headers: {}, statusCode: 0};

					this.req.on("response", headers => {
						const dupe = JSON.parse(JSON.stringify(headers));

						this.res.statusCode = dupe[":status"];

						Object.keys(dupe).filter(i => regex.http2MetaHeader.test(i)).forEach(i => {
							delete dupe[i];
						});

						this.res.headers = dupe;
					});

					this.req.on("data", chunk => {
						this.body += chunk;
					});

					this.req.on("end", doned);
					this.req.end();
				}
			} else {
				done();
			}
		});
	}

	etags (state = true) {
		this.etag = state;

		return this;
	}

	expectBody (value = regex.notEmpty) {
		this.expects.set("body", value);

		return this;
	}
<commit_msg>Sending the `body` on the `request`<commit_after>const http = require("http"),
	url = require("url"),
	path = require("path"),
	regex = require(path.join(__dirname, "regex.js")),
	pkg = require(path.join(__dirname, "..", "package.json")),
	jar = new Map(),
	captured = new Map(),
	etags = new Map(),
	jsonMimetype = "application/json";

let http2;

try {
	http2 = require("http2");
} catch (e) {
	http2 = null;
}

class TinyHTTPTest {
	constructor (uri, method, headers, body, timeout, isHttp2) {
		const parsed = url.parse(uri);

		this.body = "";
		this.capture = new Set();
		this.etag = false;
		this.expects = new Map();

		this.expects.set("status", 0);
		this.expects.set("body", "");
		this.expects.set("headers", new Map());
		this.expects.set("values", new Map());

		this.headers = {};
		this.http2 = isHttp2;
		this.options = {
			body: body,
			hostname: parsed.hostname,
			uri: uri,
			method: method,
			path: parsed.path,
			port: parsed.port,
			protocol: parsed.protocol,
			headers: headers,
			timeout: timeout
		};

		this.options.headers["user-agent"] = "tiny-httptest bot/" + pkg.version + " (" + pkg.homepage + ")";

		if (parsed.auth) {
			this.options.auth = parsed.auth;
		}

		if (this.options.body) {
			this.send(this.options.body);
		}

		this.jar = false;
		this.req = null;
		this.res = null;
		this.reuse = new Set();
		this.status = 0;
	}

	captureHeader (name) {
		if (!this.capture.has(name)) {
			this.capture.add(name);
		}

		return this;
	}

	cookies (state = true) {
		this.jar = state;

		return this;
	}

	cors (arg) {
		const origin = arg || this.options.hostname;

		this.options.headers.origin = origin;
		this.options.headers["access-control-request-headers"] = "content-type";
		this.expectHeader("access-control-allow-methods", regex.headersGet);
		this.expectHeader("access-control-allow-origin", origin);
		this.expectHeader("access-control-allow-credentials", "true");

		if (this.options.method === "OPTIONS") {
			this.expectHeader("access-control-allow-headers", regex.headersContentType);
		} else {
			this.expectHeader("access-control-expose-headers", regex.headersContentType);
		}

		return this;
	}

	end () {
		return new Promise((resolve, reject) => {
			const done = err => {
				if (err !== void 0) {
					reject(err);
				} else {
					try {
						this.process();
						resolve(this);
					} catch (e) {
						reject(e);
					}
				}
			};

			let cookie, etag;

			if (!this.req) {
				if (this.jar) {
					cookie = jar.get(this.options.hostname + ":" + this.options.port);

					if (cookie) {
						this.options.headers.cookie = cookie;
					}
				}

				if (this.etag) {
					etag = etags.get(this.options.hostname + ":" + this.options.port + this.options.path);

					if (etag) {
						this.options.headers["if-none-match"] = etag;
					}
				}

				if (this.reuse.size > 0) {
					this.reuse.forEach(k => {
						if (captured.has(k)) {
							this.options.headers[k] = captured.get(k);
						}
					});
				}

				if (this.http2 === false) {
					this.req = http.request(this.options, res => {
						this.res = res;
						res.setEncoding("utf8");

						res.on("data", chunk => {
							this.body += chunk;
						});

						res.on("end", done);
					});

					this.req.on("error", done);

					if (this.options.body) {
						this.req.write(this.options.body);
					}

					this.req.end();
				} else if (http2 === null) {
					done(new Error("http2 is not available"));
				} else {
					const client = http2.connect((this.options.protocol || "https://") + this.options.hostname + ":" + this.options.port, {
							rejectUnauthorized: false
						}),
						doned = () => {
							client.destroy();
							done();
						};

					client.on("error", doned);
					client.on("socketError", doned);

					this.options.headers[":path"] = this.options.path;
					this.options.headers[":method"] = this.options.method;

					this.req = client.request(this.options.headers);
					this.req.setEncoding("utf8");
					this.res = {headers: {}, statusCode: 0};

					this.req.on("response", headers => {
						const dupe = JSON.parse(JSON.stringify(headers));

						this.res.statusCode = dupe[":status"];

						Object.keys(dupe).filter(i => regex.http2MetaHeader.test(i)).forEach(i => {
							delete dupe[i];
						});

						this.res.headers = dupe;
					});

					this.req.on("data", chunk => {
						this.body += chunk;
					});

					this.req.on("end", doned);

					if (this.options.body) {
						this.req.write(this.options.body);
					}

					this.req.end();
				}
			} else {
				done();
			}
		});
	}

	etags (state = true) {
		this.etag = state;

		return this;
	}

	expectBody (value = regex.notEmpty) {
		this.expects.set("body", value);

		return this;
	}

{'fraction_non_alphanumeric': 0.1813421671297286, 'fraction_numerical': 0.004060696730070528, 'mean_word_length': 2.628925940286933, 'pattern_counts': {'":': 12, '<': 3, '<?xml version=': 0, '>': 25, 'https://': 2, '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': '190830', 'n_tokens_mistral': 4146, 'n_tokens_neox': 3244, 'n_words': 594}