Mercurial Hosting > luan
comparison src/luan/modules/url/LuanUrl.java @ 1354:2449ca95dc1e
minor
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Mon, 25 Mar 2019 16:55:17 -0600 |
parents | 0cceff521abb |
children | 1a7b8e38921a |
comparison
equal
deleted
inserted
replaced
1353:8d95711f6615 | 1354:2449ca95dc1e |
---|---|
28 | 28 |
29 public final class LuanUrl extends IoLuan.LuanIn { | 29 public final class LuanUrl extends IoLuan.LuanIn { |
30 | 30 |
31 private static enum Method { GET, POST, DELETE } | 31 private static enum Method { GET, POST, DELETE } |
32 | 32 |
33 private URL url; | 33 public final URL url; |
34 private Method method = Method.GET; | 34 private Method method = Method.GET; |
35 private final Map<String,Object> headers = new HashMap<String,Object>(); | 35 private final Map<String,Object> headers = new HashMap<String,Object>(); |
36 private String content = ""; | 36 private String content = ""; |
37 private MultipartClient multipart = null; | 37 private MultipartClient multipart = null; |
38 private int timeout = 0; | 38 private int timeout = 0; |
39 private String authUsername = null; | 39 private String authUsername = null; |
40 private String authPassword = null; | 40 private String authPassword = null; |
41 | 41 |
42 public LuanUrl(URL url,LuanTable options) throws LuanException { | 42 public LuanUrl(URL url,LuanTable options) throws LuanException { |
43 this.url = url; | |
44 if( options != null ) { | 43 if( options != null ) { |
45 Map map = options.asMap(); | 44 Map map = options.asMap(); |
46 String methodStr = getString(map,"method"); | 45 String methodStr = getString(map,"method"); |
47 if( methodStr != null ) { | 46 if( methodStr != null ) { |
48 methodStr = methodStr.toUpperCase(); | 47 methodStr = methodStr.toUpperCase(); |
129 } | 128 } |
130 } | 129 } |
131 if( this.method==Method.POST ) { | 130 if( this.method==Method.POST ) { |
132 content = sb.toString(); | 131 content = sb.toString(); |
133 } else { | 132 } else { |
134 String urlS = this.url.toString(); | 133 String urlS = url.toString(); |
135 if( urlS.indexOf('?') == -1 ) { | 134 if( urlS.indexOf('?') == -1 ) { |
136 urlS += '?'; | 135 urlS += '?'; |
137 } else { | 136 } else { |
138 urlS += '&'; | 137 urlS += '&'; |
139 } | 138 } |
140 urlS += sb; | 139 urlS += sb; |
141 try { | 140 try { |
142 this.url = new URL(urlS); | 141 url = new URL(urlS); |
143 } catch(IOException e) { | 142 } catch(IOException e) { |
144 throw new RuntimeException(e); | 143 throw new RuntimeException(e); |
145 } | 144 } |
146 } | 145 } |
147 } | 146 } |
149 if( timeout != null ) | 148 if( timeout != null ) |
150 this.timeout = timeout; | 149 this.timeout = timeout; |
151 if( !map.isEmpty() ) | 150 if( !map.isEmpty() ) |
152 throw new LuanException( "unrecognized options: "+map ); | 151 throw new LuanException( "unrecognized options: "+map ); |
153 } | 152 } |
153 this.url = url; | |
154 } | 154 } |
155 | 155 |
156 private static void and(StringBuilder sb) { | 156 private static void and(StringBuilder sb) { |
157 if( sb.length() > 0 ) | 157 if( sb.length() > 0 ) |
158 sb.append('&'); | 158 sb.append('&'); |