Browse Source

[std] replace List -> Array for Http classes

Simon Krajewski 7 years ago
parent
commit
d6ba4fa404
5 changed files with 181 additions and 168 deletions
  1. 18 18
      std/flash/_std/haxe/Http.hx
  2. 37 24
      std/haxe/http/HttpBase.hx
  3. 3 3
      std/haxe/http/HttpNodeJs.hx
  4. 27 27
      std/js/_std/haxe/Http.hx
  5. 96 96
      std/sys/Http.hx

+ 18 - 18
std/flash/_std/haxe/Http.hx

@@ -40,22 +40,22 @@ class HttpFlash extends haxe.http.HttpBase {
 	public override function request(?post:Bool) {
 	public override function request(?post:Bool) {
 		responseData = null;
 		responseData = null;
 		var loader = req = new flash.net.URLLoader();
 		var loader = req = new flash.net.URLLoader();
-		loader.addEventListener( "complete", function(e) {
+		loader.addEventListener("complete", function(e) {
 			req = null;
 			req = null;
 			responseData = loader.data;
 			responseData = loader.data;
-			onData( loader.data );
+			onData(loader.data);
 		});
 		});
-		loader.addEventListener( "httpStatus", function(e:flash.events.HTTPStatusEvent){
+		loader.addEventListener("httpStatus", function(e:flash.events.HTTPStatusEvent) {
 			// on Firefox 1.5, Flash calls onHTTPStatus with 0 (!??)
 			// on Firefox 1.5, Flash calls onHTTPStatus with 0 (!??)
-			if( e.status != 0 )
-				onStatus( e.status );
+			if(e.status != 0)
+				onStatus(e.status);
 		});
 		});
-		loader.addEventListener( "ioError", function(e:flash.events.IOErrorEvent){
+		loader.addEventListener("ioError", function(e:flash.events.IOErrorEvent) {
 			req = null;
 			req = null;
 			responseData = loader.data;
 			responseData = loader.data;
 			onError(e.text);
 			onError(e.text);
 		});
 		});
-		loader.addEventListener( "securityError", function(e:flash.events.SecurityErrorEvent){
+		loader.addEventListener("securityError", function(e:flash.events.SecurityErrorEvent) {
 			req = null;
 			req = null;
 			onError(e.text);
 			onError(e.text);
 		});
 		});
@@ -63,14 +63,14 @@ class HttpFlash extends haxe.http.HttpBase {
 		// headers
 		// headers
 		var param = false;
 		var param = false;
 		var vars = new flash.net.URLVariables();
 		var vars = new flash.net.URLVariables();
-		for( p in params ){
+		for(p in params) {
 			param = true;
 			param = true;
-			Reflect.setField(vars,p.param,p.value);
+			Reflect.setField(vars,p.name,p.value);
 		}
 		}
 		var small_url = url;
 		var small_url = url;
-		if( param && !post ){
+		if(param && !post) {
 			var k = url.split("?");
 			var k = url.split("?");
-			if( k.length > 1 ) {
+			if(k.length > 1) {
 				small_url = k.shift();
 				small_url = k.shift();
 				vars.decode(k.join("?"));
 				vars.decode(k.join("?"));
 			}
 			}
@@ -78,21 +78,21 @@ class HttpFlash extends haxe.http.HttpBase {
 		// Bug in flash player 9 ???
 		// Bug in flash player 9 ???
 		small_url.split("xxx");
 		small_url.split("xxx");
 
 
-		var request = new flash.net.URLRequest( small_url );
-		for( h in headers )
-			request.requestHeaders.push( new flash.net.URLRequestHeader(h.header,h.value) );
+		var request = new flash.net.URLRequest(small_url);
+		for(h in headers)
+			request.requestHeaders.push(new flash.net.URLRequestHeader(h.name,h.value));
 
 
-		if( postData != null ) {
+		if(postData != null) {
 			request.data = postData;
 			request.data = postData;
 			request.method = "POST";
 			request.method = "POST";
 		} else {
 		} else {
 			request.data = vars;
 			request.data = vars;
-			request.method = if( post ) "POST" else "GET";
+			request.method = if(post) "POST" else "GET";
 		}
 		}
 
 
 		try {
 		try {
-			loader.load( request );
-		}catch( e : Dynamic ){
+			loader.load(request);
+		}catch(e : Dynamic) {
 			req = null;
 			req = null;
 			onError("Exception: "+Std.string(e));
 			onError("Exception: "+Std.string(e));
 		}
 		}

+ 37 - 24
std/haxe/http/HttpBase.hx

@@ -21,7 +21,10 @@
  */
  */
 package haxe.http;
 package haxe.http;
 
 
-import haxe.ds.List;
+private typedef StringKeyValue = {
+	var name:String;
+	var value:String;
+}
 
 
 /**
 /**
 	This class can be used to handle Http requests consistently across
 	This class can be used to handle Http requests consistently across
@@ -39,11 +42,11 @@ class HttpBase {
 		can be changed in order to send the same request to different target
 		can be changed in order to send the same request to different target
 		Urls.
 		Urls.
 	**/
 	**/
-	public var url : String;
-	public var responseData(default, null) : Null<String>;
-	var postData : String;
-	var headers : List<{ header:String, value:String }>;
-	var params : List<{ param:String, value:String }>;
+	public var url:String;
+	public var responseData(default, null):Null<String>;
+	var postData:String;
+	var headers:Array<StringKeyValue>;
+	var params:Array<StringKeyValue>;
 
 
 	/**
 	/**
 		Creates a new Http instance with `url` as parameter.
 		Creates a new Http instance with `url` as parameter.
@@ -56,10 +59,10 @@ class HttpBase {
 		(Php) Https (SSL) connections are allowed only if the OpenSSL extension
 		(Php) Https (SSL) connections are allowed only if the OpenSSL extension
 		is enabled.
 		is enabled.
 	**/
 	**/
-	public function new( url : String ) {
+	public function new(url:String) {
 		this.url = url;
 		this.url = url;
-		headers = new List<{ header:String, value:String }>();
-		params = new List<{ param:String, value:String }>();
+		headers = [];
+		params = [];
 	}
 	}
 
 
 	/**
 	/**
@@ -69,14 +72,19 @@ class HttpBase {
 
 
 		This method provides a fluent interface.
 		This method provides a fluent interface.
 	**/
 	**/
-	public function setHeader( header : String, value : String ) {
-		headers = Lambda.filter(headers, function(h) return h.header != header);
-		headers.push({ header:header, value:value });
+	public function setHeader(name:String, value:String) {
+		for (i in 0...headers.length) {
+			if (headers[i].name == name) {
+				headers[i] = { name: name, value: value };
+				return this;
+			}
+		}
+		headers.push({ name: name, value: value });
 		return this;
 		return this;
 	}
 	}
 
 
-	public function addHeader( header : String, value : String ) {
-		headers.push({ header:header, value:value });
+	public function addHeader(header:String, value:String) {
+		headers.push({ name:header, value:value });
 		return this;
 		return this;
 	}
 	}
 
 
@@ -87,14 +95,19 @@ class HttpBase {
 
 
 		This method provides a fluent interface.
 		This method provides a fluent interface.
 	**/
 	**/
-	public function setParameter( param : String, value : String ) {
-		params = Lambda.filter(params, function(p) return p.param != param);
-		params.push({ param:param, value:value });
+	public function setParameter(name:String, value:String) {
+		for (i in 0...params.length) {
+			if (params[i].name == name) {
+				params[i] = { name: name, value: value };
+				return this;
+			}
+		}
+		params.push({ name: name, value: value });
 		return this;
 		return this;
 	}
 	}
 
 
-	public function addParameter( param : String, value : String ) {
-		params.push({ param:param, value:value });
+	public function addParameter(name:String, value:String) {
+		params.push({ name: name, value: value });
 		return this;
 		return this;
 	}
 	}
 
 
@@ -108,7 +121,7 @@ class HttpBase {
 
 
 		This method provides a fluent interface.
 		This method provides a fluent interface.
 	**/
 	**/
-	public function setPostData( data : String ) {
+	public function setPostData(data:String) {
 		postData = data;
 		postData = data;
 		return this;
 		return this;
 	}
 	}
@@ -130,7 +143,7 @@ class HttpBase {
 		[js] If `this.async` is false, the callback functions are called before
 		[js] If `this.async` is false, the callback functions are called before
 		this method returns.
 		this method returns.
 	**/
 	**/
-	public function request( ?post : Bool ) : Void {
+	public function request(?post:Bool):Void {
 		throw "not implemented";
 		throw "not implemented";
 	}
 	}
 
 
@@ -142,7 +155,7 @@ class HttpBase {
 		The intended usage is to bind it to a custom function:
 		The intended usage is to bind it to a custom function:
 		`httpInstance.onData = function(data) { // handle result }`
 		`httpInstance.onData = function(data) { // handle result }`
 	**/
 	**/
-	public dynamic function onData( data : String ) {
+	public dynamic function onData(data:String) {
 	}
 	}
 
 
 	/**
 	/**
@@ -152,7 +165,7 @@ class HttpBase {
 		The intended usage is to bind it to a custom function:
 		The intended usage is to bind it to a custom function:
 		`httpInstance.onError = function(msg) { // handle error }`
 		`httpInstance.onError = function(msg) { // handle error }`
 	**/
 	**/
-	public dynamic function onError( msg : String ) {
+	public dynamic function onError(msg:String) {
 	}
 	}
 
 
 	/**
 	/**
@@ -162,6 +175,6 @@ class HttpBase {
 		The intended usage is to bind it to a custom function:
 		The intended usage is to bind it to a custom function:
 		`httpInstance.onStatus = function(status) { // handle status }`
 		`httpInstance.onStatus = function(status) { // handle status }`
 	**/
 	**/
-	public dynamic function onStatus( status : Int ) {
+	public dynamic function onStatus(status:Int) {
 	}
 	}
 }
 }

+ 3 - 3
std/haxe/http/HttpNodeJs.hx

@@ -50,10 +50,10 @@ class HttpNodeJs extends haxe.http.HttpBase {
 		var port = if (parsedUrl.port != null) Std.parseInt(parsedUrl.port) else (secure ? 443 : 80);
 		var port = if (parsedUrl.port != null) Std.parseInt(parsedUrl.port) else (secure ? 443 : 80);
 		var h:Dynamic = {};
 		var h:Dynamic = {};
 		for (i in headers) {
 		for (i in headers) {
-			var arr = Reflect.field(h, i.header);
+			var arr = Reflect.field(h, i.name);
 			if (arr == null) {
 			if (arr == null) {
 				arr = new Array<String>();
 				arr = new Array<String>();
-				Reflect.setField(h, i.header, arr);
+				Reflect.setField(h, i.name, arr);
 			}
 			}
 
 
 			arr.push(i.value);
 			arr.push(i.value);
@@ -66,7 +66,7 @@ class HttpNodeJs extends haxe.http.HttpBase {
 				uri = "";
 				uri = "";
 			else
 			else
 				uri += "&";
 				uri += "&";
-			uri += StringTools.urlEncode(p.param)+"="+StringTools.urlEncode(p.value);
+			uri += StringTools.urlEncode(p.name)+"="+StringTools.urlEncode(p.value);
 		}
 		}
 		var question = path.split("?").length <= 1;
 		var question = path.split("?").length <= 1;
 		if (!post && uri != null) path += (if( question ) "?" else "&") + uri;
 		if (!post && uri != null) path += (if( question ) "?" else "&") + uri;

+ 27 - 27
std/js/_std/haxe/Http.hx

@@ -24,8 +24,8 @@ package haxe;
 typedef Http = HttpJs;
 typedef Http = HttpJs;
 
 
 class HttpJs extends haxe.http.HttpBase {
 class HttpJs extends haxe.http.HttpBase {
-	public var async : Bool;
-	public var withCredentials : Bool;
+	public var async:Bool;
+	public var withCredentials:Bool;
 	var req:js.html.XMLHttpRequest;
 	var req:js.html.XMLHttpRequest;
 
 
 	public function new(url:String) {
 	public function new(url:String) {
@@ -49,31 +49,31 @@ class HttpJs extends haxe.http.HttpBase {
 		responseData = null;
 		responseData = null;
 		var r = req = js.Browser.createXMLHttpRequest();
 		var r = req = js.Browser.createXMLHttpRequest();
 		var onreadystatechange = function(_) {
 		var onreadystatechange = function(_) {
-			if( r.readyState != 4 )
+			if(r.readyState != 4)
 				return;
 				return;
-			var s = try r.status catch( e : Dynamic ) null;
-			if ( s != null && untyped __js__('"undefined" !== typeof window') ) {
+			var s = try r.status catch(e:Dynamic) null;
+			if (s != null && untyped __js__('"undefined" !== typeof window')) {
 				// If the request is local and we have data: assume a success (jQuery approach):
 				// If the request is local and we have data: assume a success (jQuery approach):
 				var protocol = js.Browser.location.protocol.toLowerCase();
 				var protocol = js.Browser.location.protocol.toLowerCase();
 				var rlocalProtocol = ~/^(?:about|app|app-storage|.+-extension|file|res|widget):$/;
 				var rlocalProtocol = ~/^(?:about|app|app-storage|.+-extension|file|res|widget):$/;
-				var isLocal = rlocalProtocol.match( protocol );
-				if ( isLocal ) {
-					s = r.responseText != null ? 200 : 404;
+				var isLocal = rlocalProtocol.match(protocol);
+				if (isLocal) {
+					s = r.responseText != null ? 200:404;
 				}
 				}
 			}
 			}
-			if( s == untyped __js__("undefined") )
+			if(s == untyped __js__("undefined"))
 				s = null;
 				s = null;
-			if( s != null )
+			if(s != null)
 				onStatus(s);
 				onStatus(s);
-			if( s != null && s >= 200 && s < 400 ) {
+			if(s != null && s >= 200 && s < 400) {
 				req = null;
 				req = null;
 				onData(responseData = r.responseText);
 				onData(responseData = r.responseText);
 			}
 			}
-			else if ( s == null ) {
+			else if (s == null) {
 				req = null;
 				req = null;
 				onError("Failed to connect or resolve host");
 				onError("Failed to connect or resolve host");
 			}
 			}
-			else switch( s ) {
+			else switch(s) {
 			case 12029:
 			case 12029:
 				req = null;
 				req = null;
 				onError("Failed to connect to host");
 				onError("Failed to connect to host");
@@ -86,40 +86,40 @@ class HttpJs extends haxe.http.HttpBase {
 				onError("Http Error #"+r.status);
 				onError("Http Error #"+r.status);
 			}
 			}
 		};
 		};
-		if( async )
+		if(async)
 			r.onreadystatechange = onreadystatechange;
 			r.onreadystatechange = onreadystatechange;
 		var uri = postData;
 		var uri = postData;
-		if( uri != null )
+		if(uri != null)
 			post = true;
 			post = true;
-		else for( p in params ) {
-			if( uri == null )
+		else for(p in params) {
+			if(uri == null)
 				uri = "";
 				uri = "";
 			else
 			else
 				uri += "&";
 				uri += "&";
-			uri += StringTools.urlEncode(p.param)+"="+StringTools.urlEncode(p.value);
+			uri += StringTools.urlEncode(p.name)+"="+StringTools.urlEncode(p.value);
 		}
 		}
 		try {
 		try {
-			if( post )
+			if(post)
 				r.open("POST",url,async);
 				r.open("POST",url,async);
-			else if( uri != null ) {
+			else if(uri != null) {
 				var question = url.split("?").length <= 1;
 				var question = url.split("?").length <= 1;
-				r.open("GET",url+(if( question ) "?" else "&")+uri,async);
+				r.open("GET",url+(if(question) "?" else "&")+uri,async);
 				uri = null;
 				uri = null;
 			} else
 			} else
 				r.open("GET",url,async);
 				r.open("GET",url,async);
-		} catch( e : Dynamic ) {
+		} catch(e:Dynamic) {
 			req = null;
 			req = null;
 			onError(e.toString());
 			onError(e.toString());
 			return;
 			return;
 		}
 		}
 		r.withCredentials = withCredentials;
 		r.withCredentials = withCredentials;
-		if( !Lambda.exists(headers, function(h) return h.header == "Content-Type") && post && postData == null )
+		if(!Lambda.exists(headers, function(h) return h.name == "Content-Type") && post && postData == null)
 			r.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
 			r.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
 
 
-		for( h in headers )
-			r.setRequestHeader(h.header,h.value);
+		for(h in headers)
+			r.setRequestHeader(h.name,h.value);
 		r.send(uri);
 		r.send(uri);
-		if( !async )
+		if(!async)
 			onreadystatechange(null);
 			onreadystatechange(null);
 	}
 	}
 
 
@@ -131,7 +131,7 @@ class HttpJs extends haxe.http.HttpBase {
 
 
 		If `url` is null, the result is unspecified.
 		If `url` is null, the result is unspecified.
 	**/
 	**/
-	public static function requestUrl( url : String ) : String {
+	public static function requestUrl(url:String):String {
 		var h = new Http(url);
 		var h = new Http(url);
 		h.async = false;
 		h.async = false;
 		var r = null;
 		var r = null;

+ 96 - 96
std/sys/Http.hx

@@ -25,14 +25,14 @@ import sys.net.Host;
 import sys.net.Socket;
 import sys.net.Socket;
 
 
 class Http extends haxe.http.HttpBase {
 class Http extends haxe.http.HttpBase {
-	public var noShutdown : Bool;
-	public var cnxTimeout : Float;
-	public var responseHeaders : Map<String,String>;
-	var chunk_size : Null<Int>;
-	var chunk_buf : haxe.io.Bytes;
-	var file : { param : String, filename : String, io : haxe.io.Input, size : Int, mimeType : String };
+	public var noShutdown:Bool;
+	public var cnxTimeout:Float;
+	public var responseHeaders:Map<String,String>;
+	var chunk_size:Null<Int>;
+	var chunk_buf:haxe.io.Bytes;
+	var file:{ param:String, filename:String, io:haxe.io.Input, size:Int, mimeType:String };
 
 
-	public static var PROXY : { host : String, port : Int, auth : { user : String, pass : String } } = null;
+	public static var PROXY:{ host:String, port:Int, auth:{ user:String, pass:String } } = null;
 
 
 	public function new(url:String) {
 	public function new(url:String) {
 		cnxTimeout = 10;
 		cnxTimeout = 10;
@@ -58,7 +58,7 @@ class Http extends haxe.http.HttpBase {
 			onError(e);
 			onError(e);
 		}
 		}
 		customRequest(post,output);
 		customRequest(post,output);
-		if( !err )
+		if(!err)
 		#if neko
 		#if neko
 			onData(responseData = neko.Lib.stringReference(output.getBytes()));
 			onData(responseData = neko.Lib.stringReference(output.getBytes()));
 		#else
 		#else
@@ -68,24 +68,24 @@ class Http extends haxe.http.HttpBase {
 
 
 	@:noCompletion
 	@:noCompletion
 	@:deprecated("Use fileTransfer instead")
 	@:deprecated("Use fileTransfer instead")
-	inline public function fileTransfert( argname : String, filename : String, file : haxe.io.Input, size : Int, mimeType = "application/octet-stream" ) {
+	inline public function fileTransfert(argname:String, filename:String, file:haxe.io.Input, size:Int, mimeType = "application/octet-stream") {
 	    fileTransfer(argname, filename, file, size, mimeType);
 	    fileTransfer(argname, filename, file, size, mimeType);
     }
     }
 
 
-	public function fileTransfer( argname : String, filename : String, file : haxe.io.Input, size : Int, mimeType = "application/octet-stream" ) {
-		this.file = { param : argname, filename : filename, io : file, size : size, mimeType : mimeType };
+	public function fileTransfer(argname:String, filename:String, file:haxe.io.Input, size:Int, mimeType = "application/octet-stream") {
+		this.file = { param:argname, filename:filename, io:file, size:size, mimeType:mimeType };
 	}
 	}
 
 
-	public function customRequest( post : Bool, api : haxe.io.Output, ?sock : sys.net.Socket, ?method : String  ) {
+	public function customRequest(post:Bool, api:haxe.io.Output, ?sock:sys.net.Socket, ?method:String) {
 		this.responseData = null;
 		this.responseData = null;
 		var url_regexp = ~/^(https?:\/\/)?([a-zA-Z\.0-9_-]+)(:[0-9]+)?(.*)$/;
 		var url_regexp = ~/^(https?:\/\/)?([a-zA-Z\.0-9_-]+)(:[0-9]+)?(.*)$/;
-		if( !url_regexp.match(url) ) {
+		if(!url_regexp.match(url)) {
 			onError("Invalid URL");
 			onError("Invalid URL");
 			return;
 			return;
 		}
 		}
 		var secure = (url_regexp.matched(1) == "https://");
 		var secure = (url_regexp.matched(1) == "https://");
-		if( sock == null ) {
-			if( secure ) {
+		if(sock == null) {
+			if(secure) {
 				#if php
 				#if php
 				sock = new php.net.SslSocket();
 				sock = new php.net.SslSocket();
 				#elseif java
 				#elseif java
@@ -101,25 +101,25 @@ class Http extends haxe.http.HttpBase {
 		var host = url_regexp.matched(2);
 		var host = url_regexp.matched(2);
 		var portString = url_regexp.matched(3);
 		var portString = url_regexp.matched(3);
 		var request = url_regexp.matched(4);
 		var request = url_regexp.matched(4);
-		if( request == "" )
+		if(request == "")
 			request = "/";
 			request = "/";
-		var port = if ( portString == null || portString == "" ) secure ? 443 : 80 else Std.parseInt(portString.substr(1, portString.length - 1));
+		var port = if (portString == null || portString == "") secure ? 443:80 else Std.parseInt(portString.substr(1, portString.length - 1));
 
 
 		var multipart = (file != null);
 		var multipart = (file != null);
 		var boundary = null;
 		var boundary = null;
 		var uri = null;
 		var uri = null;
-		if( multipart ) {
+		if(multipart) {
 			post = true;
 			post = true;
 			boundary = Std.string(Std.random(1000))+Std.string(Std.random(1000))+Std.string(Std.random(1000))+Std.string(Std.random(1000));
 			boundary = Std.string(Std.random(1000))+Std.string(Std.random(1000))+Std.string(Std.random(1000))+Std.string(Std.random(1000));
-			while( boundary.length < 38 )
+			while(boundary.length < 38)
 				boundary = "-" + boundary;
 				boundary = "-" + boundary;
 			var b = new StringBuf();
 			var b = new StringBuf();
-			for( p in params ) {
+			for(p in params) {
 				b.add("--");
 				b.add("--");
 				b.add(boundary);
 				b.add(boundary);
 				b.add("\r\n");
 				b.add("\r\n");
 				b.add('Content-Disposition: form-data; name="');
 				b.add('Content-Disposition: form-data; name="');
-				b.add(p.param);
+				b.add(p.name);
 				b.add('"');
 				b.add('"');
 				b.add("\r\n");
 				b.add("\r\n");
 				b.add("\r\n");
 				b.add("\r\n");
@@ -138,48 +138,48 @@ class Http extends haxe.http.HttpBase {
 			b.add("Content-Type: "+file.mimeType+"\r\n"+"\r\n");
 			b.add("Content-Type: "+file.mimeType+"\r\n"+"\r\n");
 			uri = b.toString();
 			uri = b.toString();
 		} else {
 		} else {
-			for( p in params ) {
-				if( uri == null )
+			for(p in params) {
+				if(uri == null)
 					uri = "";
 					uri = "";
 				else
 				else
 					uri += "&";
 					uri += "&";
-				uri += StringTools.urlEncode(p.param)+"="+StringTools.urlEncode(p.value);
+				uri += StringTools.urlEncode(p.name)+"="+StringTools.urlEncode(p.value);
 			}
 			}
 		}
 		}
 
 
 		var b = new StringBuf();
 		var b = new StringBuf();
-		if( method != null ) {
+		if(method != null) {
 			b.add(method);
 			b.add(method);
 			b.add(" ");
 			b.add(" ");
-		} else if( post )
+		} else if(post)
 			b.add("POST ");
 			b.add("POST ");
 		else
 		else
 			b.add("GET ");
 			b.add("GET ");
 
 
-		if( Http.PROXY != null ) {
+		if(Http.PROXY != null) {
 			b.add("http://");
 			b.add("http://");
 			b.add(host);
 			b.add(host);
-			if( port != 80 ) {
+			if(port != 80) {
 				b.add(":");
 				b.add(":");
 				b.add(port);
 				b.add(port);
 			}
 			}
 		}
 		}
 		b.add(request);
 		b.add(request);
 
 
-		if( !post && uri != null ) {
-			if( request.indexOf("?",0) >= 0 )
+		if(!post && uri != null) {
+			if(request.indexOf("?",0) >= 0)
 				b.add("&");
 				b.add("&");
 			else
 			else
 				b.add("?");
 				b.add("?");
 			b.add(uri);
 			b.add(uri);
 		}
 		}
 		b.add(" HTTP/1.1\r\nHost: "+host+"\r\n");
 		b.add(" HTTP/1.1\r\nHost: "+host+"\r\n");
-		if( postData != null )
+		if(postData != null)
 			b.add("Content-Length: "+postData.length+"\r\n");
 			b.add("Content-Length: "+postData.length+"\r\n");
-		else if( post && uri != null ) {
-			if( multipart || !Lambda.exists(headers, function(h) return h.header == "Content-Type") ) {
+		else if(post && uri != null) {
+			if(multipart || !Lambda.exists(headers, function(h) return h.name == "Content-Type")) {
 				b.add("Content-Type: ");
 				b.add("Content-Type: ");
-				if( multipart ) {
+				if(multipart) {
 					b.add("multipart/form-data");
 					b.add("multipart/form-data");
 					b.add("; boundary=");
 					b.add("; boundary=");
 					b.add(boundary);
 					b.add(boundary);
@@ -187,38 +187,38 @@ class Http extends haxe.http.HttpBase {
 					b.add("application/x-www-form-urlencoded");
 					b.add("application/x-www-form-urlencoded");
 				b.add("\r\n");
 				b.add("\r\n");
 			}
 			}
-			if( multipart )
+			if(multipart)
 				b.add("Content-Length: "+(uri.length+file.size+boundary.length+6)+"\r\n");
 				b.add("Content-Length: "+(uri.length+file.size+boundary.length+6)+"\r\n");
 			else
 			else
 				b.add("Content-Length: "+uri.length+"\r\n");
 				b.add("Content-Length: "+uri.length+"\r\n");
 		}
 		}
 		b.add("Connection: close\r\n");
 		b.add("Connection: close\r\n");
-		for( h in headers ) {
-			b.add(h.header);
+		for(h in headers) {
+			b.add(h.name);
 			b.add(": ");
 			b.add(": ");
 			b.add(h.value);
 			b.add(h.value);
 			b.add("\r\n");
 			b.add("\r\n");
 		}
 		}
 		b.add("\r\n");
 		b.add("\r\n");
-		if( postData != null)
+		if(postData != null)
 			b.add(postData);
 			b.add(postData);
-		else if( post && uri != null )
+		else if(post && uri != null)
 			b.add(uri);
 			b.add(uri);
 		try {
 		try {
-			if( Http.PROXY != null )
+			if(Http.PROXY != null)
 				sock.connect(new Host(Http.PROXY.host),Http.PROXY.port);
 				sock.connect(new Host(Http.PROXY.host),Http.PROXY.port);
 			else
 			else
 				sock.connect(new Host(host),port);
 				sock.connect(new Host(host),port);
 			sock.write(b.toString());
 			sock.write(b.toString());
-			if( multipart ) {
+			if(multipart) {
 				var bufsize = 4096;
 				var bufsize = 4096;
 				var buf = haxe.io.Bytes.alloc(bufsize);
 				var buf = haxe.io.Bytes.alloc(bufsize);
-				while( file.size > 0 ) {
-					var size = if( file.size > bufsize ) bufsize else file.size;
+				while(file.size > 0) {
+					var size = if(file.size > bufsize) bufsize else file.size;
 					var len = 0;
 					var len = 0;
 					try {
 					try {
 						len = file.io.readBytes(buf,0,size);
 						len = file.io.readBytes(buf,0,size);
-					} catch( e : haxe.io.Eof ) break;
+					} catch(e:haxe.io.Eof) break;
 					sock.output.writeFullBytes(buf,0,len);
 					sock.output.writeFullBytes(buf,0,len);
 					file.size -= len;
 					file.size -= len;
 				}
 				}
@@ -229,53 +229,53 @@ class Http extends haxe.http.HttpBase {
 			}
 			}
 			readHttpResponse(api,sock);
 			readHttpResponse(api,sock);
 			sock.close();
 			sock.close();
-		} catch( e : Dynamic ) {
-			try sock.close() catch( e : Dynamic ) { };
+		} catch(e:Dynamic) {
+			try sock.close() catch(e:Dynamic) { };
 			onError(Std.string(e));
 			onError(Std.string(e));
 		}
 		}
 	}
 	}
 
 
-	function readHttpResponse( api : haxe.io.Output, sock : sys.net.Socket ) {
+	function readHttpResponse(api:haxe.io.Output, sock:sys.net.Socket) {
 		// READ the HTTP header (until \r\n\r\n)
 		// READ the HTTP header (until \r\n\r\n)
 		var b = new haxe.io.BytesBuffer();
 		var b = new haxe.io.BytesBuffer();
 		var k = 4;
 		var k = 4;
 		var s = haxe.io.Bytes.alloc(4);
 		var s = haxe.io.Bytes.alloc(4);
 		sock.setTimeout(cnxTimeout);
 		sock.setTimeout(cnxTimeout);
-		while( true ) {
+		while(true) {
 			var p = sock.input.readBytes(s,0,k);
 			var p = sock.input.readBytes(s,0,k);
-			while( p != k )
+			while(p != k)
 				p += sock.input.readBytes(s,p,k - p);
 				p += sock.input.readBytes(s,p,k - p);
 			b.addBytes(s,0,k);
 			b.addBytes(s,0,k);
-			switch( k ) {
+			switch(k) {
 			case 1:
 			case 1:
 				var c = s.get(0);
 				var c = s.get(0);
-				if( c == 10 )
+				if(c == 10)
 					break;
 					break;
-				if( c == 13 )
+				if(c == 13)
 					k = 3;
 					k = 3;
 				else
 				else
 					k = 4;
 					k = 4;
 			case 2:
 			case 2:
 				var c = s.get(1);
 				var c = s.get(1);
-				if( c == 10 ) {
-					if( s.get(0) == 13 )
+				if(c == 10) {
+					if(s.get(0) == 13)
 						break;
 						break;
 					k = 4;
 					k = 4;
-				} else if( c == 13 )
+				} else if(c == 13)
 					k = 3;
 					k = 3;
 				else
 				else
 					k = 4;
 					k = 4;
 			case 3:
 			case 3:
 				var c = s.get(2);
 				var c = s.get(2);
-				if( c == 10 ) {
-					if( s.get(1) != 13 )
+				if(c == 10) {
+					if(s.get(1) != 13)
 						k = 4;
 						k = 4;
-					else if( s.get(0) != 10 )
+					else if(s.get(0) != 10)
 						k = 2;
 						k = 2;
 					else
 					else
 						break;
 						break;
-				} else if( c == 13 ) {
-					if( s.get(1) != 10 || s.get(0) != 13 )
+				} else if(c == 13) {
+					if(s.get(1) != 10 || s.get(0) != 13)
 						k = 1;
 						k = 1;
 					else
 					else
 						k = 3;
 						k = 3;
@@ -283,15 +283,15 @@ class Http extends haxe.http.HttpBase {
 					k = 4;
 					k = 4;
 			case 4:
 			case 4:
 				var c = s.get(3);
 				var c = s.get(3);
-				if( c == 10 ) {
-					if( s.get(2) != 13 )
+				if(c == 10) {
+					if(s.get(2) != 13)
 						continue;
 						continue;
-					else if( s.get(1) != 10 || s.get(0) != 13 )
+					else if(s.get(1) != 10 || s.get(0) != 13)
 						k = 2;
 						k = 2;
 					else
 					else
 						break;
 						break;
-				} else if( c == 13 ) {
-					if( s.get(2) != 10 || s.get(1) != 13 )
+				} else if(c == 13) {
+					if(s.get(2) != 10 || s.get(1) != 13)
 						k = 3;
 						k = 3;
 					else
 					else
 						k = 1;
 						k = 1;
@@ -306,7 +306,7 @@ class Http extends haxe.http.HttpBase {
 		var response = headers.shift();
 		var response = headers.shift();
 		var rp = response.split(" ");
 		var rp = response.split(" ");
 		var status = Std.parseInt(rp[1]);
 		var status = Std.parseInt(rp[1]);
-		if( status == 0 || status == null )
+		if(status == 0 || status == null)
 			throw "Response status error";
 			throw "Response status error";
 
 
 		// remove the two lasts \r\n\r\n
 		// remove the two lasts \r\n\r\n
@@ -315,11 +315,11 @@ class Http extends haxe.http.HttpBase {
 		responseHeaders = new haxe.ds.StringMap();
 		responseHeaders = new haxe.ds.StringMap();
 		var size = null;
 		var size = null;
 		var chunked = false;
 		var chunked = false;
-		for( hline in headers ) {
+		for(hline in headers) {
 			var a = hline.split(": ");
 			var a = hline.split(": ");
 			var hname = a.shift();
 			var hname = a.shift();
-			var hval = if( a.length == 1 ) a[0] else a.join(": ");
-			hval = StringTools.ltrim( StringTools.rtrim( hval ) );
+			var hval = if(a.length == 1) a[0] else a.join(": ");
+			hval = StringTools.ltrim(StringTools.rtrim(hval));
 			responseHeaders.set(hname, hval);
 			responseHeaders.set(hname, hval);
 			switch(hname.toLowerCase())
 			switch(hname.toLowerCase())
 			{
 			{
@@ -338,48 +338,48 @@ class Http extends haxe.http.HttpBase {
 
 
 		var bufsize = 1024;
 		var bufsize = 1024;
 		var buf = haxe.io.Bytes.alloc(bufsize);
 		var buf = haxe.io.Bytes.alloc(bufsize);
-		if( chunked ) {
+		if(chunked) {
 			try {
 			try {
-				while( true ) {
+				while(true) {
 					var len = sock.input.readBytes(buf,0,bufsize);
 					var len = sock.input.readBytes(buf,0,bufsize);
-					if( !readChunk(chunk_re,api,buf,len) )
+					if(!readChunk(chunk_re,api,buf,len))
 						break;
 						break;
 				}
 				}
-			} catch ( e : haxe.io.Eof ) {
+			} catch (e:haxe.io.Eof) {
 				throw "Transfer aborted";
 				throw "Transfer aborted";
 			}
 			}
-		} else if( size == null ) {
-			if( !noShutdown )
+		} else if(size == null) {
+			if(!noShutdown)
 				sock.shutdown(false,true);
 				sock.shutdown(false,true);
 			try {
 			try {
-				while( true ) {
+				while(true) {
 					var len = sock.input.readBytes(buf,0,bufsize);
 					var len = sock.input.readBytes(buf,0,bufsize);
 					api.writeBytes(buf,0,len);
 					api.writeBytes(buf,0,len);
 				}
 				}
-			} catch( e : haxe.io.Eof ) {
+			} catch(e:haxe.io.Eof) {
 			}
 			}
 		} else {
 		} else {
 			api.prepare(size);
 			api.prepare(size);
 			try {
 			try {
-				while( size > 0 ) {
-					var len = sock.input.readBytes(buf,0,if( size > bufsize ) bufsize else size);
+				while(size > 0) {
+					var len = sock.input.readBytes(buf,0,if(size > bufsize) bufsize else size);
 					api.writeBytes(buf,0,len);
 					api.writeBytes(buf,0,len);
 					size -= len;
 					size -= len;
 				}
 				}
-			} catch( e : haxe.io.Eof ) {
+			} catch(e:haxe.io.Eof) {
 				throw "Transfer aborted";
 				throw "Transfer aborted";
 			}
 			}
 		}
 		}
-		if( chunked && (chunk_size != null || chunk_buf != null) )
+		if(chunked && (chunk_size != null || chunk_buf != null))
 			throw "Invalid chunk";
 			throw "Invalid chunk";
-		if( status < 200 || status >= 400 )
+		if(status < 200 || status >= 400)
 			throw "Http Error #"+status;
 			throw "Http Error #"+status;
 		api.close();
 		api.close();
 	}
 	}
 
 
-	function readChunk(chunk_re : EReg, api : haxe.io.Output, buf : haxe.io.Bytes, len ) {
-		if( chunk_size == null ) {
-			if( chunk_buf != null ) {
+	function readChunk(chunk_re:EReg, api:haxe.io.Output, buf:haxe.io.Bytes, len) {
+		if(chunk_size == null) {
+			if(chunk_buf != null) {
 				var b = new haxe.io.BytesBuffer();
 				var b = new haxe.io.BytesBuffer();
 				b.add(chunk_buf);
 				b.add(chunk_buf);
 				b.addBytes(buf,0,len);
 				b.addBytes(buf,0,len);
@@ -388,15 +388,15 @@ class Http extends haxe.http.HttpBase {
 				chunk_buf = null;
 				chunk_buf = null;
 			}
 			}
 			#if neko
 			#if neko
-			if( chunk_re.match(neko.Lib.stringReference(buf)) ) {
+			if(chunk_re.match(neko.Lib.stringReference(buf))) {
 			#else
 			#else
-			if( chunk_re.match(buf.toString()) ) {
+			if(chunk_re.match(buf.toString())) {
 			#end
 			#end
 				var p = chunk_re.matchedPos();
 				var p = chunk_re.matchedPos();
-				if( p.len <= len ) {
+				if(p.len <= len) {
 					var cstr = chunk_re.matched(1);
 					var cstr = chunk_re.matched(1);
 					chunk_size = Std.parseInt("0x"+cstr);
 					chunk_size = Std.parseInt("0x"+cstr);
-					if( cstr == "0" ) {
+					if(cstr == "0") {
 						chunk_size = null;
 						chunk_size = null;
 						chunk_buf = null;
 						chunk_buf = null;
 						return false;
 						return false;
@@ -406,29 +406,29 @@ class Http extends haxe.http.HttpBase {
 				}
 				}
 			}
 			}
 			// prevent buffer accumulation
 			// prevent buffer accumulation
-			if( len > 10 ) {
+			if(len > 10) {
 				onError("Invalid chunk");
 				onError("Invalid chunk");
 				return false;
 				return false;
 			}
 			}
 			chunk_buf = buf.sub(0,len);
 			chunk_buf = buf.sub(0,len);
 			return true;
 			return true;
 		}
 		}
-		if( chunk_size > len ) {
+		if(chunk_size > len) {
 			chunk_size -= len;
 			chunk_size -= len;
 			api.writeBytes(buf,0,len);
 			api.writeBytes(buf,0,len);
 			return true;
 			return true;
 		}
 		}
 		var end = chunk_size + 2;
 		var end = chunk_size + 2;
-		if( len >= end ) {
-			if( chunk_size > 0 )
+		if(len >= end) {
+			if(chunk_size > 0)
 				api.writeBytes(buf,0,chunk_size);
 				api.writeBytes(buf,0,chunk_size);
 			len -= end;
 			len -= end;
 			chunk_size = null;
 			chunk_size = null;
-			if( len == 0 )
+			if(len == 0)
 				return true;
 				return true;
 			return readChunk(chunk_re,api,buf.sub(end,len),len);
 			return readChunk(chunk_re,api,buf.sub(end,len),len);
 		}
 		}
-		if( chunk_size > 0 )
+		if(chunk_size > 0)
 			api.writeBytes(buf,0,chunk_size);
 			api.writeBytes(buf,0,chunk_size);
 		chunk_size -= len;
 		chunk_size -= len;
 		return true;
 		return true;
@@ -442,7 +442,7 @@ class Http extends haxe.http.HttpBase {
 
 
 		If `url` is null, the result is unspecified.
 		If `url` is null, the result is unspecified.
 	**/
 	**/
-	public static function requestUrl( url : String ) : String {
+	public static function requestUrl(url:String):String {
 		var h = new Http(url);
 		var h = new Http(url);
 		var r = null;
 		var r = null;
 		h.onData = function(d){
 		h.onData = function(d){