Nicolas Cannasse 14 years ago
parent
commit
e2d9fd48a2
2 changed files with 53 additions and 0 deletions
  1. 1 0
      doc/CHANGES.txt
  2. 52 0
      std/haxe/web/Request.hx

+ 1 - 0
doc/CHANGES.txt

@@ -8,6 +8,7 @@
 	sys : added "in" operator for spod macros, added relation access in expressions
 	sys : added "in" operator for spod macros, added relation access in expressions
 	macro : added ECheckType
 	macro : added ECheckType
 	macro : added TLazy for not-yet-typed class fields
 	macro : added TLazy for not-yet-typed class fields
+	js/php/neko : added haxe.web.Request
 
 
 2011-09-25: 2.08
 2011-09-25: 2.08
 	js : added js.JQuery
 	js : added js.JQuery

+ 52 - 0
std/haxe/web/Request.hx

@@ -0,0 +1,52 @@
+package haxe.web;
+
+class Request {
+
+	/**
+		Returns the current page GET and POST parameters (only GET parameters for Javascript)
+	**/
+	public static function getParams() : Hash<String> {
+		#if neko
+		return neko.Web.getParams();
+		#elseif php
+		return php.Web.getParams();
+		#elseif js
+		var get : String = untyped window.location.search.substr(1);
+		var params = new Hash();
+		for( p in ~/[&;]/g.split(get) ) {
+			var pl = p.split("=");
+			if( pl.length < 2 ) continue;
+			var name = pl.shift();
+			params.set(StringTools.urlDecode(name), StringTools.urlDecode(pl.join("=")));
+		}
+		return params;
+		#end
+	}
+
+	/**
+		Returns the local server host name
+	**/
+	public static function getHostName() : String {
+		#if neko
+		return neko.Web.getHostName();
+		#elseif php
+		return php.Web.getHostName();
+		#elseif js
+		return untyped window.location.host; // includes port
+		#end
+	}
+
+	/**
+		Returns the original request URL (before any server internal redirections)
+	**/
+	public static function getURI() : String {
+		#if neko
+		return neko.Web.getURI();
+		#elseif php
+		return php.Web.getURI();
+		#elseif js
+		return untyped window.location.pathname;
+		#end
+	}
+	
+}