<commit_before>package management

import (
	"bytes"
	"encoding/xml"
	"fmt"
	"github.com/MSOpenTech/azure-sdk-for-go/core/http"
	"github.com/MSOpenTech/azure-sdk-for-go/core/tls"
)

const (
	msVersionHeader           = "x-ms-version"
	msVersionHeaderValue      = "2014-10-01"
	contentHeader             = "Content-Type"
	defaultContentHeaderValue = "application/xml"
	requestIdHeader           = "X-Ms-Request-Id"
)

//sendAzureGetRequest sends a request to the management API using the HTTP GET method
//and returns the response body or an error.
func (client *Client) SendAzureGetRequest(url string) ([]byte, error) {
	if url == "" {
		return nil, fmt.Errorf(errParamNotSpecified, "url")
	}

	response, err := client.sendAzureRequest(url, "GET", "", nil)
	if err != nil {
		return nil, err
	}

	responseContent := getResponseBody(response)
	return responseContent, nil
}

//sendAzurePostRequest sends a request to the management API using the HTTP POST method
//and returns the request ID or an error.
func (client *Client) SendAzurePostRequest(url string, data []byte) (string, error) {
	if url == "" {
		return "", fmt.Errorf(errParamNotSpecified, "url")
	}

	response, err := client.sendAzureRequest(url, "POST", "", data)
	if err != nil {
		return "", err
	}

	requestId := response.Header[requestIdHeader]
	return requestId[0], nil
}

//sendAzurePutRequest sends a request to the management API using the HTTP PUT method
//and returns the request ID or an error. The content type can be specified, however
//if an empty string is passed, the default of "application/xml" will be used.
func (client *Client) SendAzurePutRequest(url string, contentType string, data []byte) (string, error) {
	if url == "" {
		return "", fmt.Errorf(errParamNotSpecified, contentType, "url")
	}

	response, err := client.sendAzureRequest(url, "PUT", contentType, data)
	if err != nil {
		return "", err
	}

	requestId := response.Header[requestIdHeader]
	return requestId[0], nil
}

//sendAzureDeleteRequest sends a request to the management API using the HTTP DELETE method
//and returns the request ID or an error.
func (client *Client) SendAzureDeleteRequest(url string) (string, error) {
	if url == "" {
		return "", fmt.Errorf(errParamNotSpecified, "url")
	}

	response, err := client.sendAzureRequest(url, "DELETE", "", nil)
	if err != nil {
		return "", err
	}

	requestId := response.Header[requestIdHeader]
	return requestId[0], nil
}

//sendAzureRequest constructs an HTTP client for the request, sends it to the
//management API and returns the response or an error.
func (client *Client) sendAzureRequest(url string, requestType string, contentType string, data []byte) (*http.Response, error) {
	if url == "" {
		return nil, fmt.Errorf(errParamNotSpecified, "url")
	}
	if requestType == "" {
		return nil, fmt.Errorf(errParamNotSpecified, "requestType")
	}

	httpClient := client.createHttpClient()

	response, err := client.sendRequest(httpClient, url, requestType, contentType, data, 7)
	if err != nil {
		return nil, err
	}

	return response, nil
}

//createHttpClient creates an HTTP Client configured with the key pair for
//the subscription for this client.
func (client *Client) createHttpClient() *http.Client {
	cert, _ := tls.X509KeyPair(client.publishSettings.SubscriptionCert, client.publishSettings.SubscriptionKey)

	ssl := &tls.Config{}
	ssl.Certificates = []tls.Certificate{cert}

	httpClient := &http.Client{
		Transport: &http.Transport{
			TLSClientConfig: ssl,
		},
	}

	return httpClient
}<commit_msg>Take HTTP proxy from environment<commit_after>package management

import (
	"bytes"
	"encoding/xml"
	"fmt"
	"github.com/MSOpenTech/azure-sdk-for-go/core/http"
	"github.com/MSOpenTech/azure-sdk-for-go/core/tls"
)

const (
	msVersionHeader           = "x-ms-version"
	msVersionHeaderValue      = "2014-10-01"
	contentHeader             = "Content-Type"
	defaultContentHeaderValue = "application/xml"
	requestIdHeader           = "X-Ms-Request-Id"
)

//sendAzureGetRequest sends a request to the management API using the HTTP GET method
//and returns the response body or an error.
func (client *Client) SendAzureGetRequest(url string) ([]byte, error) {
	if url == "" {
		return nil, fmt.Errorf(errParamNotSpecified, "url")
	}

	response, err := client.sendAzureRequest(url, "GET", "", nil)
	if err != nil {
		return nil, err
	}

	responseContent := getResponseBody(response)
	return responseContent, nil
}

//sendAzurePostRequest sends a request to the management API using the HTTP POST method
//and returns the request ID or an error.
func (client *Client) SendAzurePostRequest(url string, data []byte) (string, error) {
	if url == "" {
		return "", fmt.Errorf(errParamNotSpecified, "url")
	}

	response, err := client.sendAzureRequest(url, "POST", "", data)
	if err != nil {
		return "", err
	}

	requestId := response.Header[requestIdHeader]
	return requestId[0], nil
}

//sendAzurePutRequest sends a request to the management API using the HTTP PUT method
//and returns the request ID or an error. The content type can be specified, however
//if an empty string is passed, the default of "application/xml" will be used.
func (client *Client) SendAzurePutRequest(url string, contentType string, data []byte) (string, error) {
	if url == "" {
		return "", fmt.Errorf(errParamNotSpecified, contentType, "url")
	}

	response, err := client.sendAzureRequest(url, "PUT", contentType, data)
	if err != nil {
		return "", err
	}

	requestId := response.Header[requestIdHeader]
	return requestId[0], nil
}

//sendAzureDeleteRequest sends a request to the management API using the HTTP DELETE method
//and returns the request ID or an error.
func (client *Client) SendAzureDeleteRequest(url string) (string, error) {
	if url == "" {
		return "", fmt.Errorf(errParamNotSpecified, "url")
	}

	response, err := client.sendAzureRequest(url, "DELETE", "", nil)
	if err != nil {
		return "", err
	}

	requestId := response.Header[requestIdHeader]
	return requestId[0], nil
}

//sendAzureRequest constructs an HTTP client for the request, sends it to the
//management API and returns the response or an error.
func (client *Client) sendAzureRequest(url string, requestType string, contentType string, data []byte) (*http.Response, error) {
	if url == "" {
		return nil, fmt.Errorf(errParamNotSpecified, "url")
	}
	if requestType == "" {
		return nil, fmt.Errorf(errParamNotSpecified, "requestType")
	}

	httpClient := client.createHttpClient()

	response, err := client.sendRequest(httpClient, url, requestType, contentType, data, 7)
	if err != nil {
		return nil, err
	}

	return response, nil
}

//createHttpClient creates an HTTP Client configured with the key pair for
//the subscription for this client.
func (client *Client) createHttpClient() *http.Client {
	cert, _ := tls.X509KeyPair(client.publishSettings.SubscriptionCert, client.publishSettings.SubscriptionKey)

	ssl := &tls.Config{}
	ssl.Certificates = []tls.Certificate{cert}

	httpClient := &http.Client{
		Transport: &http.Transport{
			Proxy:           http.ProxyFromEnvironment,
			TLSClientConfig: ssl,
		},
	}

	return httpClient
}
{'fraction_non_alphanumeric': 0.11912798874824192, 'fraction_numerical': 0.004219409282700422, 'mean_word_length': 4.342599549211119, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 6}, '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': '612214', 'n_tokens_mistral': 2230, 'n_tokens_neox': 2148, 'n_words': 690}