Mercurial Hosting > luan
diff src/luan/modules/url/LuanUrl.java @ 1267:9fa8b8389578
add LuanTable.luan;
support metatable __gc();
add luan.sql;
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Mon, 12 Nov 2018 02:10:41 -0700 |
parents | d1911842c2be |
children | 781ec0a92bb5 |
line wrap: on
line diff
--- a/src/luan/modules/url/LuanUrl.java Sun Sep 30 19:10:48 2018 -0600 +++ b/src/luan/modules/url/LuanUrl.java Mon Nov 12 02:10:41 2018 -0700 @@ -34,10 +34,10 @@ private MultipartClient multipart = null; private int timeout = 0; - public LuanUrl(LuanState luan,URL url,LuanTable options) throws LuanException { + public LuanUrl(URL url,LuanTable options) throws LuanException { this.url = url; if( options != null ) { - Map map = options.asMap(luan); + Map map = options.asMap(); String methodStr = getString(map,"method"); if( methodStr != null ) { methodStr = methodStr.toUpperCase(); @@ -47,7 +47,7 @@ throw new LuanException( "invalid method: "+methodStr ); } } - Map headerMap = getMap(luan,map,"headers"); + Map headerMap = getMap(map,"headers"); if( headerMap != null ) { headers = new HashMap(); for( Object hack : headerMap.entrySet() ) { @@ -66,7 +66,7 @@ } } } - Map auth = getMap(luan,map,"authorization"); + Map auth = getMap(map,"authorization"); if( auth != null ) { if( headers!=null && headers.containsKey("authorization") ) throw new LuanException( "can't define authorization with header 'authorization' defined" ); @@ -85,7 +85,7 @@ headers = new HashMap(); headers.put("authorization",val); } - Map params = getMap(luan,map,"parameters"); + Map params = getMap(map,"parameters"); String enctype = getString(map,"enctype"); if( enctype != null ) { if( !enctype.equals("multipart/form-data") ) @@ -184,12 +184,12 @@ return (LuanTable)val; } - private static Map getMap(LuanState luan,Map map,String key) throws LuanException { + private static Map getMap(Map map,String key) throws LuanException { LuanTable t = getTable(map,key); - return t==null ? null : t.asMap(luan); + return t==null ? null : t.asMap(); } - @Override public InputStream inputStream() throws IOException, LuanException { + @Override public InputStream inputStream(LuanState luan) throws IOException, LuanException { URLConnection con = url.openConnection(); if( timeout != 0 ) { con.setConnectTimeout(timeout); @@ -219,12 +219,12 @@ HttpURLConnection httpCon = (HttpURLConnection)con; if( method==Method.GET ) { - return getInputStream(httpCon); + return getInputStream(luan,httpCon); } if( method==Method.DELETE ) { httpCon.setRequestMethod("DELETE"); - return getInputStream(httpCon); + return getInputStream(luan,httpCon); } // POST @@ -244,13 +244,13 @@ } out.flush(); try { - return getInputStream(httpCon); + return getInputStream(luan,httpCon); } finally { out.close(); } } - private static InputStream getInputStream(HttpURLConnection httpCon) throws IOException, LuanException { + private static InputStream getInputStream(LuanState luan,HttpURLConnection httpCon) throws IOException, LuanException { try { return httpCon.getInputStream(); } catch(IOException e) { @@ -263,7 +263,7 @@ String msg = Utils.readAll(in); in.close(); LuanException le = new LuanException(msg,e); - LuanTable tbl = le.table(); + LuanTable tbl = le.table(luan); tbl.rawPut("response_code",responseCode); tbl.rawPut("response_message",responseMessage); throw le;