@@ -95,7 +95,8 @@ public List<MerkleNode> add(NamedStreamable file, boolean wrap, boolean hashOnly
95
95
}
96
96
97
97
public List <MerkleNode > add (List <NamedStreamable > files , boolean wrap , boolean hashOnly ) throws IOException {
98
- Multipart m = new Multipart (protocol + "://" + host + ":" + port + version + "add?stream-channels=true&w=" + wrap + "&n=" + hashOnly , "UTF-8" );
98
+ Multipart m = new Multipart (protocol + "://" + host + ":" + port + version + "add?stream-channels=true&w=" + wrap + "&n=" + hashOnly , "UTF-8" , headers );
99
+
99
100
for (NamedStreamable file : files ) {
100
101
if (file .isDirectory ()) {
101
102
m .addSubtree (Paths .get ("" ), file );
@@ -306,7 +307,7 @@ public List<MerkleNode> put(List<byte[]> data, Optional<String> format) throws I
306
307
307
308
public MerkleNode put (byte [] data , Optional <String > format ) throws IOException {
308
309
String fmt = format .map (f -> "&format=" + f ).orElse ("" );
309
- Multipart m = new Multipart (protocol + "://" + host + ":" + port + version + "block/put?stream-channels=true" + fmt , "UTF-8" );
310
+ Multipart m = new Multipart (protocol + "://" + host + ":" + port + version + "block/put?stream-channels=true" + fmt , "UTF-8" , headers );
310
311
try {
311
312
m .addFilePart ("file" , Paths .get ("" ), new NamedStreamable .ByteArrayWrapper (data ));
312
313
String res = m .finish ();
@@ -325,7 +326,7 @@ public Map stat(Multihash hash) throws IOException {
325
326
*/
326
327
public class IPFSObject {
327
328
public List <MerkleNode > put (List <byte []> data ) throws IOException {
328
- Multipart m = new Multipart (protocol + "://" + host + ":" + port + version + "object/put?stream-channels=true" , "UTF-8" );
329
+ Multipart m = new Multipart (protocol + "://" + host + ":" + port + version + "object/put?stream-channels=true" , "UTF-8" , headers );
329
330
for (byte [] f : data )
330
331
m .addFilePart ("file" , Paths .get ("" ), new NamedStreamable .ByteArrayWrapper (f ));
331
332
String res = m .finish ();
@@ -335,7 +336,7 @@ public List<MerkleNode> put(List<byte[]> data) throws IOException {
335
336
public List <MerkleNode > put (String encoding , List <byte []> data ) throws IOException {
336
337
if (!"json" .equals (encoding ) && !"protobuf" .equals (encoding ))
337
338
throw new IllegalArgumentException ("Encoding must be json or protobuf" );
338
- Multipart m = new Multipart (protocol + "://" + host + ":" + port + version + "object/put?stream-channels=true&encoding=" + encoding , "UTF-8" );
339
+ Multipart m = new Multipart (protocol + "://" + host + ":" + port + version + "object/put?stream-channels=true&encoding=" + encoding , "UTF-8" , headers );
339
340
for (byte [] f : data )
340
341
m .addFilePart ("file" , Paths .get ("" ), new NamedStreamable .ByteArrayWrapper (f ));
341
342
String res = m .finish ();
@@ -389,7 +390,7 @@ public MerkleNode patch(Multihash base, String command, Optional<byte[]> data, O
389
390
case "append-data" :
390
391
if (!data .isPresent ())
391
392
throw new IllegalStateException ("set-data requires data!" );
392
- Multipart m = new Multipart (protocol + "://" + host + ":" + port + version + "object/patch/" + command + "?arg=" + base .toBase58 () + "&stream-channels=true" , "UTF-8" );
393
+ Multipart m = new Multipart (protocol + "://" + host + ":" + port + version + "object/patch/" + command + "?arg=" + base .toBase58 () + "&stream-channels=true" , "UTF-8" , headers );
393
394
m .addFilePart ("file" , Paths .get ("" ), new NamedStreamable .ByteArrayWrapper (data .get ()));
394
395
String res = m .finish ();
395
396
return MerkleNode .fromJSON (JSONParser .parse (res ));
@@ -534,7 +535,7 @@ public MerkleNode put(byte[] object, String outputFormat) throws IOException {
534
535
535
536
public MerkleNode put (String inputFormat , byte [] object , String outputFormat ) throws IOException {
536
537
String prefix = protocol + "://" + host + ":" + port + version ;
537
- Multipart m = new Multipart (prefix + "dag/put/?stream-channels=true&input-enc=" + inputFormat + "&f=" + outputFormat , "UTF-8" );
538
+ Multipart m = new Multipart (prefix + "dag/put/?stream-channels=true&input-enc=" + inputFormat + "&f=" + outputFormat , "UTF-8" , headers );
538
539
m .addFilePart ("file" , Paths .get ("" ), new NamedStreamable .ByteArrayWrapper (object ));
539
540
String res = m .finish ();
540
541
return MerkleNode .fromJSON (JSONParser .parse (res ));
@@ -589,7 +590,7 @@ public Map show() throws IOException {
589
590
}
590
591
591
592
public void replace (NamedStreamable file ) throws IOException {
592
- Multipart m = new Multipart (protocol + "://" + host + ":" + port + version + "config/replace?stream-channels=true" , "UTF-8" );
593
+ Multipart m = new Multipart (protocol + "://" + host + ":" + port + version + "config/replace?stream-channels=true" , "UTF-8" , headers );
593
594
m .addFilePart ("file" , Paths .get ("" ), file );
594
595
String res = m .finish ();
595
596
}
@@ -748,7 +749,7 @@ private static byte[] post(URL target, byte[] body, Map<String, String> headers)
748
749
return readFully (in );
749
750
}
750
751
751
- private static void addHeaders (HttpURLConnection conn , Map <String , String > headers ) {
752
+ public static void addHeaders (HttpURLConnection conn , Map <String , String > headers ) {
752
753
// add headers
753
754
for (Map .Entry <String , String > header : headers .entrySet ()) {
754
755
conn .setRequestProperty (header .getKey (), header .getValue ());
0 commit comments