@@ -227,13 +227,11 @@ public MerkleNode patch(Multihash base, String command, Optional<byte[]> data, O
227
227
case "set-data" :
228
228
if (!data .isPresent ())
229
229
throw new IllegalStateException ("set-data requires data!" );
230
- targetPath += "&arg=" +new String (data .get ());
231
- return MerkleNode .fromJSON (retrieveMap (targetPath ));
230
+ return MerkleNode .fromJSON (postMap (targetPath , data .get (), Collections .EMPTY_MAP ));
232
231
case "append-data" :
233
232
if (!data .isPresent ())
234
233
throw new IllegalStateException ("append-data requires data!" );
235
- targetPath += "&arg=" +new String (data .get ());
236
- return MerkleNode .fromJSON (retrieveMap (targetPath ));
234
+ return MerkleNode .fromJSON (postMap (targetPath , data .get (), Collections .EMPTY_MAP ));
237
235
default :
238
236
throw new IllegalStateException ("Unimplemented" );
239
237
}
@@ -431,6 +429,11 @@ private static byte[] get(URL target) throws IOException {
431
429
return resp .toByteArray ();
432
430
}
433
431
432
+ private Map postMap (String path , byte [] body , Map <String , String > headers ) throws IOException {
433
+ URL target = new URL ("http" , host , port , version + path );
434
+ return (Map ) JSONParser .parse (new String (post (target , body , headers )));
435
+ }
436
+
434
437
private static byte [] post (URL target , byte [] body , Map <String , String > headers ) throws IOException {
435
438
HttpURLConnection conn = (HttpURLConnection ) target .openConnection ();
436
439
for (String key : headers .keySet ())
0 commit comments