 import Foundation
 
 public class ClientRequest: ETWriter {
-    
+
     static private var lock = 0
 
     public var headers = [String: String]()
-    
+
     private var url: String
     private var method: String = "get"
     private var userName: String? = nil
     private var password: String? = nil
-    
+
     private var maxRedirects = 10
     private var handle: UnsafeMutablePointer<Void>?
     private var headersList: UnsafeMutablePointer<curl_slist> = nil
     private var writeBuffers = BufferList()
-    
+
     private var response = ClientResponse()
     private var callback: ClientRequestCallback
-    
+
     init(url: String, callback: ClientRequestCallback) {
         self.url = url
         self.callback = callback
     }
-    
+
     init(options: [ClientRequestOptions], callback: ClientRequestCallback) {
         self.callback = callback
-        
-        var theProtocol = "http://"
+
+        var theSchema = "http://"
         var hostName = "localhost"
         var path = "/"
         var port:Int16 = 80
-        
+
         for  option in options  {
             switch(option) {
                 case .Method(let method):
                     self.method = method
-                case .Protocol(let prot):
-                    theProtocol = prot
+                case .Schema(let schema):
+                    theSchema = schema
                 case .Hostname(let host):
                     hostName = host
                 case .Port(let thePort):

            curl_slist_free_all(headersList)
        }
    }
    
    public func writeString(str: String) {
        if  let data = StringUtils.toUtf8String(str)  {
            writeData(data)
        }
    }
    
    public func writeData(data: NSData) {
        writeBuffers.appendData(data)
    }
    
    public func end(data: String) {
        writeString(data)
        end()
    }
    
    public func end(data: NSData) {
        writeData(data)
        end()
    }
    
    public func end() {
        SysUtils.doOnce(&ClientRequest.lock) {
            curl_global_init(Int(CURL_GLOBAL_SSL))
        }
        
        var callCallback = true
        let urlBuf = StringUtils.toNullTerminatedUtf8String(url)
        if  let _ = urlBuf {
            prepareHandle(urlBuf!)
            
            let invoker = CurlInvoker(handle: handle!, maxRedirects: maxRedirects)
            invoker.delegate = self


}

public enum ClientRequestOptions {
    case Method(String), Schema(String), Hostname(String), Port(Int16), Path(String),
    Headers([String: String]), Username(String), Password(String), MaxRedirects(Int)
}

