Skip to content

Commit

Permalink
Add default HTTP headers support for uploads in S3, Azure and Cloud F…
Browse files Browse the repository at this point in the history
…iles. #5364.
  • Loading branch information
dkocher committed Dec 1, 2010
1 parent 86b1a79 commit c98ce48
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 2 deletions.
10 changes: 9 additions & 1 deletion source/ch/cyberduck/core/Preferences.java
Expand Up @@ -533,6 +533,8 @@ protected void setDefaults() {
* Default metadata for uploads. Format must be "key1=value1 key2=value2"
*/
defaults.put("s3.metadata.default", "");
defaults.put("cf.metadata.default", "");
defaults.put("azure.metadata.default", "");

defaults.put("webdav.followRedirects", String.valueOf(true));

Expand Down Expand Up @@ -671,6 +673,10 @@ protected void setDefaults() {
defaults.put("ssh.publickey", "ssh-rsa");
defaults.put("ssh.compression", "none"); //zlib

defaults.put("ssh.authentication.publikey.default.enable", String.valueOf(true));
defaults.put("ssh.authentication.publickey.default.rsa", "~/.ssh/id_rsa");
defaults.put("ssh.authentication.publickey.default.dsa", "~/.ssh/id_dsa");

defaults.put("archive.default", "tar.gz");

/**
Expand Down Expand Up @@ -723,7 +729,9 @@ public String getDefault(String property) {
* @param property
* @return
*/
public abstract List<String> getList(String property);
public List<String> getList(String property) {
return Arrays.asList(this.getProperty(property).split("\\p{javaWhitespace}+"));
}

/**
* Give value in user settings or default value if not customized.
Expand Down
26 changes: 26 additions & 0 deletions source/ch/cyberduck/core/azure/AzurePath.java
Expand Up @@ -26,6 +26,7 @@
import ch.cyberduck.ui.DateFormatterFactory;

import org.apache.commons.io.IOUtils;
import org.apache.commons.lang.StringUtils;
import org.apache.http.Header;
import org.apache.http.HttpEntity;
import org.apache.log4j.Logger;
Expand Down Expand Up @@ -470,6 +471,31 @@ protected void upload(final BandwidthThrottle throttle, final StreamListener lis
AzureSession.AzureContainer container = this.getSession().getContainer(this.getContainerName());
final BlobProperties properties = new BlobProperties(this.getKey());
properties.setContentType(this.getLocal().getMimeType());
NameValueCollection metadata = new NameValueCollection();
// Default metadata for new files
for(String m : Preferences.instance().getList("azure.metadata.default")) {
if(StringUtils.isBlank(m)) {
log.warn("Invalid header " + m);
continue;
}
if(!m.contains("=")) {
log.warn("Invalid header " + m);
continue;
}
int split = m.indexOf('=');
String name = m.substring(0, split);
if(StringUtils.isBlank(name)) {
log.warn("Missing key in " + m);
continue;
}
String value = m.substring(split + 1);
if(StringUtils.isEmpty(value)) {
log.warn("Missing value in " + m);
continue;
}
metadata.put(name, value);
}
properties.setMetadata(metadata);
boolean blob = container.createBlob(properties, new HttpEntity() {
public boolean isRepeatable() {
return false;
Expand Down
23 changes: 23 additions & 0 deletions source/ch/cyberduck/core/cf/CFPath.java
Expand Up @@ -319,6 +319,29 @@ protected void upload(final BandwidthThrottle throttle, final StreamListener lis
String etag = null;
try {
final HashMap<String, String> metadata = new HashMap<String, String>();
// Default metadata for new files
for(String m : Preferences.instance().getList("cf.metadata.default")) {
if(StringUtils.isBlank(m)) {
log.warn("Invalid header " + m);
continue;
}
if(!m.contains("=")) {
log.warn("Invalid header " + m);
continue;
}
int split = m.indexOf('=');
String name = m.substring(0, split);
if(StringUtils.isBlank(name)) {
log.warn("Missing key in " + m);
continue;
}
String value = m.substring(split + 1);
if(StringUtils.isEmpty(value)) {
log.warn("Missing value in " + m);
continue;
}
metadata.put(name, value);
}
etag = this.getSession().getClient().storeObjectAs(this.getContainerName(), this.getKey(),
new InputStreamRequestEntity(in,
this.getLocal().attributes().getSize() - status.getCurrent(),
Expand Down
2 changes: 1 addition & 1 deletion source/ch/cyberduck/core/s3/S3Path.java
Expand Up @@ -546,7 +546,7 @@ else if(acl.equals(this.getSession().getPublicAcl(this.getContainerName(), true,
// Storage class
object.setStorageClass(Preferences.instance().getProperty("s3.storage.class"));
// Default metadata for new files
for(String m : Preferences.instance().getProperty("s3.metadata.default").split("\\p{javaWhitespace}+")) {
for(String m : Preferences.instance().getList("s3.metadata.default")) {
if(StringUtils.isBlank(m)) {
log.warn("Invalid header " + m);
continue;
Expand Down

0 comments on commit c98ce48

Please sign in to comment.