Skip to content

Commit a2ddb51

Browse files
committed
Fix object.patch to use http request body
1 parent c93131a commit a2ddb51

File tree

2 files changed

+10
-5
lines changed

2 files changed

+10
-5
lines changed

src/main/java/org/ipfs/api/IPFS.java

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -227,13 +227,11 @@ public MerkleNode patch(Multihash base, String command, Optional<byte[]> data, O
227227
case "set-data":
228228
if (!data.isPresent())
229229
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));
232231
case "append-data":
233232
if (!data.isPresent())
234233
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));
237235
default:
238236
throw new IllegalStateException("Unimplemented");
239237
}
@@ -431,6 +429,11 @@ private static byte[] get(URL target) throws IOException {
431429
return resp.toByteArray();
432430
}
433431

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+
434437
private static byte[] post(URL target, byte[] body, Map<String, String> headers) throws IOException {
435438
HttpURLConnection conn = (HttpURLConnection) target.openConnection();
436439
for (String key: headers.keySet())

src/test/java/org/ipfs/api/Test.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,9 @@ public void objectPatch() {
9898
throw new RuntimeException("Adding not inverse of removing link!");
9999

100100
// data tests
101-
byte[] data = "somerandomdata".getBytes();
101+
byte[] data = "some random textual data".getBytes();
102+
// byte[] data = new byte[1024];
103+
// new Random().nextBytes(data);
102104
MerkleNode patched = ipfs.object.patch(base, "set-data", Optional.of(data), Optional.empty(), Optional.empty());
103105
MerkleNode patchedResult = ipfs.object.get(patched.hash);
104106
if (!Arrays.equals(patchedResult.data.get(), data))

0 commit comments

Comments
 (0)