<commit_before>package ciolite

// Imports
import (
	"bytes"
	"encoding/json"
	"fmt"
	"io"
	"io/ioutil"
	"net/http"
	"time"

	"github.com/garyburd/go-oauth/oauth"
)

// clientRequest defines information that can be used to make a request
type clientRequest struct {
	method      string
	path        string
	formValues  CioParams
	queryValues CioParams
}

const (
	// The default host of API
	host = "https://api.context.io/lite"

	// The default timeout duration used on HTTP requests
	defaultTimeout = 20 * time.Second
)

// doFormRequest makes the actual request
func (cioLite CioLite) doFormRequest(request clientRequest, result interface{}) error {

	// Construct the url
	url := host + request.path + request.queryValues.QueryString()

	// Construct the body
	var bodyReader io.Reader
	bodyValues := request.formValues.FormValues()
	bodyString := bodyValues.Encode()
	if len(bodyString) > 0 {
		bodyReader = bytes.NewReader([]byte(bodyString))
	}
	if cioLite.log != nil {
		cioLite.log.Println("Creating new request to: " + url + " with payload: " + bodyString)
	}

	// Construct the request
	httpReq, err := http.NewRequest(request.method, url, bodyReader)
	if err != nil {
		return fmt.Errorf("Could not create request: %s", err)
	}

	// oAuth signature
	var client oauth.Client
	client.Credentials = oauth.Credentials{Token: cioLite.apiKey, Secret: cioLite.apiSecret}

	// Add headers
	httpReq.Header.Add("Content-Type", "application/x-www-form-urlencoded")
	httpReq.Header.Add("Accept", "application/json")
	httpReq.Header.Add("Accept-Charset", "utf-8")
	httpReq.Header.Set("User-Agent", "Golang CIOLite library v0.1")
	httpReq.Header.Add("Authorization", client.AuthorizationHeader(nil, request.method, httpReq.URL, bodyValues))

	// Create the HTTP client
	httpClient := &http.Client{
		Transport: http.DefaultTransport,
		Timeout:   defaultTimeout,
	}

	// Make the request
	res, err := httpClient.Do(httpReq)
	if err != nil {
		return fmt.Errorf("Failed to make request: %s", err)
	}

	// Parse the response
	defer func() {
		if closeErr := res.Body.Close(); closeErr != nil {
			cioLite.log.Println("Unable to close response body, with error: " + closeErr.Error())
		}
	}()

	resBody, err := ioutil.ReadAll(res.Body)
	if err != nil {
		return fmt.Errorf("Could not read response: %s", err)
	}
	if cioLite.log != nil {
		cioLite.log.Println("Received response from: " + url +
			" with status code: " + fmt.Sprintf("%d", res.StatusCode) +
			" and payload: " + string(resBody))
	}

	// Determine status
	if res.StatusCode >= 400 {
		return fmt.Errorf("Invalid status code: %d", res.StatusCode)
	}

	// Unmarshal result
	return json.Unmarshal(resBody, &result)
}
<commit_msg>changing headers from ADD to SET<commit_after>package ciolite

// Imports
import (
	"bytes"
	"encoding/json"
	"fmt"
	"io"
	"io/ioutil"
	"net/http"
	"time"

	"github.com/garyburd/go-oauth/oauth"
)

// clientRequest defines information that can be used to make a request
type clientRequest struct {
	method      string
	path        string
	formValues  CioParams
	queryValues CioParams
}

const (
	// The default host of API
	host = "https://api.context.io/lite"

	// The default timeout duration used on HTTP requests
	defaultTimeout = 20 * time.Second
)

// doFormRequest makes the actual request
func (cioLite CioLite) doFormRequest(request clientRequest, result interface{}) error {

	// Construct the url
	url := host + request.path + request.queryValues.QueryString()

	// Construct the body
	var bodyReader io.Reader
	bodyValues := request.formValues.FormValues()
	bodyString := bodyValues.Encode()
	if len(bodyString) > 0 {
		bodyReader = bytes.NewReader([]byte(bodyString))
	}
	if cioLite.log != nil {
		cioLite.log.Println("Creating new request to: " + url + " with payload: " + bodyString)
	}

	// Construct the request
	httpReq, err := http.NewRequest(request.method, url, bodyReader)
	if err != nil {
		return fmt.Errorf("Could not create request: %s", err)
	}

	// oAuth signature
	var client oauth.Client
	client.Credentials = oauth.Credentials{Token: cioLite.apiKey, Secret: cioLite.apiSecret}

	// Add headers
	httpReq.Header.Set("Content-Type", "application/x-www-form-urlencoded")
	httpReq.Header.Set("Accept", "application/json")
	httpReq.Header.Set("Accept-Charset", "utf-8")
	httpReq.Header.Set("User-Agent", "Golang CIOLite library v0.1")
	httpReq.Header.Set("Authorization", client.AuthorizationHeader(nil, request.method, httpReq.URL, bodyValues))

	// Create the HTTP client
	httpClient := &http.Client{
		Transport: http.DefaultTransport,
		Timeout:   defaultTimeout,
	}

	// Make the request
	res, err := httpClient.Do(httpReq)
	if err != nil {
		return fmt.Errorf("Failed to make request: %s", err)
	}

	// Parse the response
	defer func() {
		if closeErr := res.Body.Close(); closeErr != nil {
			cioLite.log.Println("Unable to close response body, with error: " + closeErr.Error())
		}
	}()

	resBody, err := ioutil.ReadAll(res.Body)
	if err != nil {
		return fmt.Errorf("Could not read response: %s", err)
	}
	if cioLite.log != nil {
		cioLite.log.Println("Received response from: " + url +
			" with status code: " + fmt.Sprintf("%d", res.StatusCode) +
			" and payload: " + string(resBody))
	}

	// Determine status
	if res.StatusCode >= 400 {
		return fmt.Errorf("Invalid status code: %d", res.StatusCode)
	}

	// Unmarshal result
	return json.Unmarshal(resBody, &result)
}

{'fraction_non_alphanumeric': 0.13276469497496754, 'fraction_numerical': 0.0033376599295382903, 'mean_word_length': 3.9215328467153285, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, 'https://': 2, 'lorem ipsum': 0, 'www.': 2, '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': '7405070', 'n_tokens_mistral': 1846, 'n_tokens_neox': 1799, 'n_words': 471}