<commit_before>package proxy

import (
	"bytes"
	"crypto/tls"
	"io/ioutil"
	"net"
	"net/http"
	"net/http/httputil"
	"net/url"
	"strconv"
	"strings"
)

// NewReverseProxy returns new reverse proxy handler that replaces text in response
func NewReverseProxy(host, search, replace string) (http.Handler, error) {
	if !strings.Contains(host, "https") {
		host = "https://" + host
	}

	hostUrl, err := url.Parse(host)
	if err != nil {
		return nil, err
	}

	reverseProxy := httputil.NewSingleHostReverseProxy(hostUrl)
	reverseProxy.Transport = &http.Transport{DialTLS: dialTLS}

	director := reverseProxy.Director
	reverseProxy.Director = func(req *http.Request) {
		director(req)
		req.Host = req.URL.Host
	}

	reverseProxy.ModifyResponse = func(resp *http.Response) (err error) {
		b, err := ioutil.ReadAll(resp.Body)
		if err != nil {
			return
		}<commit_msg>- HTTP works. Problems with HTTPS traffic<commit_after>package proxy

import (
	"bytes"
	"crypto/tls"
	"io/ioutil"
	"net"
	"net/http"
	"net/http/httputil"
	"net/url"
	"strconv"
	"strings"
)

// NewReverseProxy returns new reverse proxy handler that replaces text in response
func NewReverseProxy(host, search, replace string) (http.Handler, error) {
	if !strings.Contains(host, "http") {
		host = "http://" + host
	}

	hostUrl, err := url.Parse(host)
	if err != nil {
		return nil, err
	}

	reverseProxy := httputil.NewSingleHostReverseProxy(hostUrl)
	// TODO Uncomment when HTTPS will be fixed
	//reverseProxy.Transport = &http.Transport{DialTLS: dialTLS}

	director := reverseProxy.Director
	reverseProxy.Director = func(req *http.Request) {
		director(req)
		req.Host = req.URL.Host
	}

	reverseProxy.ModifyResponse = func(resp *http.Response) (err error) {
		b, err := ioutil.ReadAll(resp.Body)
		if err != nil {
			return
		}
{'fraction_non_alphanumeric': 0.1331096196868009, 'fraction_numerical': 0.0, 'mean_word_length': 4.140804597701149, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 1, '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': '6163712', 'n_tokens_mistral': 680, 'n_tokens_neox': 633, 'n_words': 153}