<commit_before>package toget

import (
	"errors"
	"net/http"
	"time"
)

type response struct {
	resp *http.Response
	err  error
}

var TimeoutError = errors.New("http get timeout")

func Get(url string, to time.Duration) (*http.Response, error) {

	var (
		tr     = &http.Transport{}
		client = &http.Client{Transport: tr}
		ret    = make(chan response, 1)
	)

	req, err := http.NewRequest("GET", url, nil)
	if err != nil {
		return nil, err
	}

	go func() {
		resp, err := client.Do(req)
		ret <- response{resp, err}
	}()

	select {
	case r := <-ret:
		return r.resp, r.err
	case <-time.After(to):
		tr.CancelRequest(req)
		return nil, TimeoutError
	}

}<commit_msg>More helpers and test<commit_after>package toget

import (
	"errors"
	"io"
	"net/http"
	"time"
)

var TimeoutError = errors.New("http get timeout")

func Head(url string, timeout time.Duration) (*http.Response, error) {

	req, err := http.NewRequest("HEAD", url, nil)
	if err != nil {
		return nil, err
	}

	return Do(req, timeout)

}

func Get(url string, timeout time.Duration) (*http.Response, error) {

	req, err := http.NewRequest("GET", url, nil)
	if err != nil {
		return nil, err
	}

	return Do(req, timeout)

}

func Post(url string, body io.Reader, timeout time.Duration) (*http.Response, error) {

	req, err := http.NewRequest("POST", url, body)
	if err != nil {
		return nil, err
	}

	return Do(req, timeout)

}

func Put(url string, body io.Reader, timeout time.Duration) (*http.Response, error) {

	req, err := http.NewRequest("PUT", url, body)
	if err != nil {
		return nil, err
	}

	return Do(req, timeout)

}

func Delete(url string, timeout time.Duration) (*http.Response, error) {

	req, err := http.NewRequest("DELETE", url, nil)
	if err != nil {
		return nil, err
	}

	return Do(req, timeout)

}

func Do(req *http.Request, timeout time.Duration) (*http.Response, error) {

	type response struct {
		resp *http.Response
		err  error
	}

	var (
		tr     = &http.Transport{}
		client = &http.Client{Transport: tr}
		ret    = make(chan response, 1)
	)

	go func() {
		resp, err := client.Do(req)
		ret <- response{resp, err}
	}()

	select {
	case r := <-ret:
		return r.resp, r.err
	case <-time.After(timeout):
		tr.CancelRequest(req)
		return nil, TimeoutError
	}

}
{'fraction_non_alphanumeric': 0.15186500888099466, 'fraction_numerical': 0.0008880994671403197, 'mean_word_length': 3.4437869822485205, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 3, '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': '1928853', 'n_tokens_mistral': 873, 'n_tokens_neox': 823, 'n_words': 236}