comparison src/luan/modules/url/LuanUrl.java @ 1759:6668513a11d7

fix PUT
author Franklin Schmidt <fschmidt@gmail.com>
date Mon, 10 Apr 2023 17:43:47 -0600
parents 83780735ad9c
children
comparison
equal deleted inserted replaced
1757:0e59609c3173 1759:6668513a11d7
98 } 98 }
99 Map params = removeMap(options,"parameters"); 99 Map params = removeMap(options,"parameters");
100 String enctype = Utils.removeString(options,"enctype"); 100 String enctype = Utils.removeString(options,"enctype");
101 Object content = options.remove("content"); 101 Object content = options.remove("content");
102 if( content != null ) { 102 if( content != null ) {
103 if( this.method != Method.POST ) 103 if( this.method != Method.POST && this.method != Method.PUT )
104 throw new LuanException( "content can only be used with POST" ); 104 throw new LuanException( "content can only be used with POST or PUT" );
105 if( params != null ) 105 if( params != null )
106 throw new LuanException( "content cannot be used with parameters" ); 106 throw new LuanException( "content cannot be used with parameters" );
107 if( content instanceof String ) { 107 if( content instanceof String ) {
108 this.content = ((String)content).getBytes(); 108 this.content = ((String)content).getBytes();
109 } else if( content instanceof byte[] ) { 109 } else if( content instanceof byte[] ) {
112 throw new LuanException( "content must be String or byte[]" ); 112 throw new LuanException( "content must be String or byte[]" );
113 } 113 }
114 if( enctype != null ) { 114 if( enctype != null ) {
115 if( !enctype.equals("multipart/form-data") ) 115 if( !enctype.equals("multipart/form-data") )
116 throw new LuanException( "unrecognized enctype: "+enctype ); 116 throw new LuanException( "unrecognized enctype: "+enctype );
117 if( this.method != Method.POST ) 117 if( this.method != Method.POST && this.method != Method.PUT )
118 throw new LuanException( "multipart/form-data can only be used with POST" ); 118 throw new LuanException( "multipart/form-data can only be used with POST or PUT" );
119 if( params==null ) 119 if( params==null )
120 throw new LuanException( "multipart/form-data requires parameters" ); 120 throw new LuanException( "multipart/form-data requires parameters" );
121 if( params.isEmpty() ) 121 if( params.isEmpty() )
122 throw new LuanException( "multipart/form-data parameters can't be empty" ); 122 throw new LuanException( "multipart/form-data parameters can't be empty" );
123 multipart = new MultipartClient(params); 123 multipart = new MultipartClient(params);
245 if( method==Method.DELETE ) { 245 if( method==Method.DELETE ) {
246 httpCon.setRequestMethod("DELETE"); 246 httpCon.setRequestMethod("DELETE");
247 return getInputStream(httpCon,authorization); 247 return getInputStream(httpCon,authorization);
248 } 248 }
249 249
250 /*
250 if( method==Method.PUT ) { 251 if( method==Method.PUT ) {
251 httpCon.setRequestMethod("PUT"); 252 httpCon.setRequestMethod("PUT");
252 return getInputStream(httpCon,authorization); 253 return getInputStream(httpCon,authorization);
253 } 254 }
254 255 */
255 // POST 256
257 // POST or PUT
256 258
257 // httpCon.setRequestProperty("content-type","application/x-www-form-urlencoded"); 259 // httpCon.setRequestProperty("content-type","application/x-www-form-urlencoded");
258 httpCon.setDoOutput(true); 260 httpCon.setDoOutput(true);
259 httpCon.setRequestMethod("POST"); 261 httpCon.setRequestMethod(method.toString());
260 262
261 OutputStream out; 263 OutputStream out;
262 if( multipart != null ) { 264 if( multipart != null ) {
263 out = multipart.write(httpCon); 265 out = multipart.write(httpCon);
264 } else { 266 } else {