diff src/luan/modules/url/LuanUrl.java @ 1420:225808b90cee

options handling
author Franklin Schmidt <fschmidt@gmail.com>
date Sat, 26 Oct 2019 22:21:09 -0600
parents 27efb1fcbcb5
children 8ab2f0fc3829
line wrap: on
line diff
--- a/src/luan/modules/url/LuanUrl.java	Fri Oct 25 22:12:06 2019 -0600
+++ b/src/luan/modules/url/LuanUrl.java	Sat Oct 26 22:21:09 2019 -0600
@@ -43,8 +43,8 @@
 
 	public LuanUrl(URL url,LuanTable options) throws LuanException {
 		if( options != null ) {
-			Map map = options.asMap();
-			String methodStr = Utils.removeString(map,"method");
+			options = new LuanTable(options);
+			String methodStr = Utils.removeString(options,"method");
 			if( methodStr != null ) {
 				methodStr = methodStr.toUpperCase();
 				try {
@@ -53,7 +53,7 @@
 					throw new LuanException( "invalid method: "+methodStr );
 				}
 			}
-			Map headerMap = removeMap(map,"headers");
+			Map headerMap = removeMap(options,"headers");
 			if( headerMap != null ) {
 				for( Object hack : headerMap.entrySet() ) {
 					Map.Entry entry = (Map.Entry)hack;
@@ -71,7 +71,7 @@
 					}
 				}
 			}
-			Map auth = removeMap(map,"authorization");
+			LuanTable auth = Utils.removeTable(options,"authorization");
 			if( auth != null ) {
 				if( headers!=null && headers.containsKey("authorization") )
 					throw new LuanException( "can't define authorization with header 'authorization' defined" );
@@ -92,9 +92,9 @@
 					authPassword = password;
 				}
 			}
-			Map params = removeMap(map,"parameters");
-			String enctype = Utils.removeString(map,"enctype");
-			Object content = map.remove("content");
+			Map params = removeMap(options,"parameters");
+			String enctype = Utils.removeString(options,"enctype");
+			Object content = options.remove("content");
 			if( content != null ) {
 				if( this.method != Method.POST )
 					throw new LuanException( "content can only be used with POST" );
@@ -159,10 +159,10 @@
 					}
 				}
 			}
-			Integer timeout = Utils.removeInteger(map,"time_out");
+			Integer timeout = Utils.removeInteger(options,"time_out");
 			if( timeout != null )
 				this.timeout = timeout;
-			Utils.checkEmpty(map);
+			Utils.checkEmpty(options);
 		}
 		this.url = url;
 	}
@@ -180,8 +180,8 @@
 		}
 	}
 
-	private static Map removeMap(Map map,String key) throws LuanException {
-		LuanTable t = Utils.removeTable(map,key);
+	private static Map removeMap(LuanTable options,String key) throws LuanException {
+		LuanTable t = Utils.removeTable(options,key);
 		return t==null ? null : t.asMap();
 	}