<commit_before>package main

import (
	"crypto/tls"
	"crypto/x509"
	"errors"
	"fmt"
	"io/ioutil"
	"net"
	"net/http"
	"net/url"
	"os"
	"time"
)

func main() {
	var host, port, caFileName string
	switch len(os.Args) {
	case 4:
		caFileName = os.Args[3]
		fallthrough
	case 3:
		host = os.Args[1]
		port = os.Args[2]
	default:
		fmt.Printf("usage: %v <host> <port> [cafile]\n", os.Args[0])
		os.Exit(1)
	}

	if err := checkTLS(host, port, caFileName); err != nil {
		fmt.Println("FATAL:", err)
		os.Exit(1)
	}
}

func checkTLS(host, port, caFileName string) error {
	client := &http.Client{
		Timeout: 5 * time.Second,
	}

	if caFileName != "" {
		roots, err := loadRootCA(caFileName)
		if err != nil {
			return err
		}
		client.Transport = &http.Transport{
			TLSClientConfig: &tls.Config{RootCAs: roots},
		}
	}

	uri := "https://" + net.JoinHostPort(host, port)
	if _, err := client.Get(uri); err != nil {
		if urlerr, ok := err.(*url.Error); ok {
			if _, ok := urlerr.Err.(*net.OpError); ok {
				// Connection errors are fatal without verdict
				return err
			}
		}
		fmt.Println(err.Error())
		fmt.Println("REJECT")
		return nil
	}
	fmt.Println("ACCEPT")
	return nil
}

func loadRootCA(fileName string) (roots *x509.CertPool, err error) {<commit_msg>Go stub: only explicitly connection errors are fatal<commit_after>package main

import (
	"crypto/tls"
	"crypto/x509"
	"errors"
	"fmt"
	"io/ioutil"
	"net"
	"net/http"
	"net/url"
	"os"
	"time"
)

func main() {
	var host, port, caFileName string
	switch len(os.Args) {
	case 4:
		caFileName = os.Args[3]
		fallthrough
	case 3:
		host = os.Args[1]
		port = os.Args[2]
	default:
		fmt.Printf("usage: %v <host> <port> [cafile]\n", os.Args[0])
		os.Exit(1)
	}

	if err := checkTLS(host, port, caFileName); err != nil {
		fmt.Println("FATAL:", err)
		os.Exit(1)
	}
}

func checkTLS(host, port, caFileName string) error {
	client := &http.Client{
		Timeout: 5 * time.Second,
	}

	if caFileName != "" {
		roots, err := loadRootCA(caFileName)
		if err != nil {
			return err
		}
		client.Transport = &http.Transport{
			TLSClientConfig: &tls.Config{RootCAs: roots},
		}
	}

	uri := "https://" + net.JoinHostPort(host, port)
	if _, err := client.Get(uri); err != nil {
		if urlerr, ok := err.(*url.Error); ok {
			if operr, ok := urlerr.Err.(*net.OpError); ok {
				if operr.Op == "dial" {
					// Connection errors are fatal without verdict
					return err
				}
			}
		}
		fmt.Println(err.Error())
		fmt.Println("REJECT")
		return nil
	}
	fmt.Println("ACCEPT")
	return nil
}

func loadRootCA(fileName string) (roots *x509.CertPool, err error) {
{'fraction_non_alphanumeric': 0.1682747973755307, 'fraction_numerical': 0.011578541103820918, 'mean_word_length': 3.312811980033278, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, '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': '1272628', 'n_tokens_mistral': 1131, 'n_tokens_neox': 1035, 'n_words': 245}