<commit_before>//
//  UrlRequestExtensions.swift
//  StartAppsKitExtensions
//
//  Created by <NAME> on 7/11/16.
//
//

import Foundation

public extension URLRequest {
    
    public mutating func setHttpBody(_ body: Data) throws {
        let data = body
        self.setValue("\(data.count)", forHTTPHeaderField: "Content-Length")
        self.httpMethod = "POST"
        self.httpBody = data
    }
    
    public mutating func setHttpBody(_ body: String) throws {
        let data = body.data(using: .utf8)!
        self.setValue("\(data.count)", forHTTPHeaderField: "Content-Length")
        self.httpMethod = "POST"
        self.httpBody = data
    }
    
    #if os(iOS)
    
    public mutating func setHttpBody(_ body: UIImage) throws {
        let data = UIImagePNGRepresentation(body)
        self.setValue("application/x-www-form-urlencoded", forHTTPHeaderField: "Content-Type")
        self.setValue("\(data.count)", forHTTPHeaderField: "Content-Length")
        self.httpMethod = "POST"
        self.httpBody = data
    }
    
    #endif<commit_msg>Fixed urlrequest image extension<commit_after>//
//  UrlRequestExtensions.swift
//  StartAppsKitExtensions
//
//  Created by <NAME> on 7/11/16.
//
//

import Foundation

public extension URLRequest {
    
    public mutating func setHttpBody(_ body: Data) throws {
        let data = body
        self.setValue("\(data.count)", forHTTPHeaderField: "Content-Length")
        self.httpMethod = "POST"
        self.httpBody = data
    }
    
    public mutating func setHttpBody(_ body: String) throws {
        let data = body.data(using: .utf8)!
        self.setValue("\(data.count)", forHTTPHeaderField: "Content-Length")
        self.httpMethod = "POST"
        self.httpBody = data
    }
    
    #if os(iOS)
    
    public mutating func setHttpBody(_ body: UIImage) throws {
        let data = UIImagePNGRepresentation(body)!
        self.setValue("application/x-www-form-urlencoded", forHTTPHeaderField: "Content-Type")
        self.setValue("\(data.count)", forHTTPHeaderField: "Content-Length")
        self.httpMethod = "POST"
        self.httpBody = data
    }
    
    #endif
{'fraction_non_alphanumeric': 0.11953488372093023, 'fraction_numerical': 0.005581395348837209, 'mean_word_length': 2.5378289473684212, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, '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': '7371286', 'n_tokens_mistral': 652, 'n_tokens_neox': 646, 'n_words': 144}