changeset 1364:45363886f256

add url methods
author Franklin Schmidt <fschmidt@gmail.com>
date Wed, 29 May 2019 19:03:25 -0600
parents 1a7b8e38921a
children 6617763dfd76
files src/luan/modules/Boot.luan src/luan/modules/url/LuanUrl.java
diffstat 2 files changed, 29 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/src/luan/modules/Boot.luan	Wed May 29 15:11:51 2019 -0600
+++ b/src/luan/modules/Boot.luan	Wed May 29 19:03:25 2019 -0600
@@ -109,8 +109,34 @@
 	return Io.stdin
 end
 
+
+local function new_LuanUrl(io)
+	local this = new_LuanIn(io)
+
+	local function check()
+		io.httpCon or error "must open first"
+	end
+
+	function this.get_header(name)
+		check()
+		return io.httpCon.getHeaderField(name)
+	end
+
+	function this.get_response_code()
+		check()
+		return io.httpCon.getResponseCode()
+	end
+
+	function this.get_response_message()
+		check()
+		return io.httpCon.getResponseMessage()
+	end
+
+	return this
+end
+
 local function url(path,options)
-	return new_LuanIn( LuanUrl.new(URL.new(path),options) )
+	return new_LuanUrl( LuanUrl.new(URL.new(path),options) )
 end
 
 function schemes.http(path,options)
--- a/src/luan/modules/url/LuanUrl.java	Wed May 29 15:11:51 2019 -0600
+++ b/src/luan/modules/url/LuanUrl.java	Wed May 29 19:03:25 2019 -0600
@@ -39,6 +39,7 @@
 	private int timeout = 0;
 	private String authUsername = null;
 	private String authPassword = null;
+	public HttpURLConnection httpCon;
 
 	public LuanUrl(URL url,LuanTable options) throws LuanException {
 		if( options != null ) {
@@ -249,7 +250,7 @@
 			return con.getInputStream();
 		}
 
-		HttpURLConnection httpCon = (HttpURLConnection)con;
+		httpCon = (HttpURLConnection)con;
 
 		if( method==Method.GET ) {
 			return getInputStream(httpCon,authorization);