mirror of
https://github.com/vanitasvitae/Smack.git
synced 2024-11-22 03:52:06 +01:00
Allow adding custom HTTP headers to bosh communications
This commit is contained in:
parent
7059b60672
commit
c83d717a26
3 changed files with 19 additions and 1 deletions
|
@ -4,5 +4,5 @@ This API is considered beta quality."""
|
|||
|
||||
dependencies {
|
||||
compile project(':smack-core')
|
||||
compile 'org.igniterealtime.jbosh:jbosh:[0.9,0.10)'
|
||||
compile 'org.igniterealtime.jbosh:jbosh:[0.9.1,0.10)'
|
||||
}
|
||||
|
|
|
@ -19,6 +19,8 @@ package org.jivesoftware.smack.bosh;
|
|||
|
||||
import java.net.URI;
|
||||
import java.net.URISyntaxException;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.jivesoftware.smack.ConnectionConfiguration;
|
||||
import org.jivesoftware.smack.proxy.ProxyInfo;
|
||||
|
@ -34,6 +36,7 @@ public final class BOSHConfiguration extends ConnectionConfiguration {
|
|||
|
||||
private final boolean https;
|
||||
private final String file;
|
||||
private Map<String, String> httpHeaders;
|
||||
|
||||
private BOSHConfiguration(Builder builder) {
|
||||
super(builder);
|
||||
|
@ -49,6 +52,7 @@ public final class BOSHConfiguration extends ConnectionConfiguration {
|
|||
} else {
|
||||
file = builder.file;
|
||||
}
|
||||
httpHeaders = builder.httpHeaders;
|
||||
}
|
||||
|
||||
public boolean isProxyEnabled() {
|
||||
|
@ -76,6 +80,10 @@ public final class BOSHConfiguration extends ConnectionConfiguration {
|
|||
return new URI((https ? "https://" : "http://") + this.host + ":" + this.port + file);
|
||||
}
|
||||
|
||||
public Map<String, String> getHttpHeaders() {
|
||||
return httpHeaders;
|
||||
}
|
||||
|
||||
public static Builder builder() {
|
||||
return new Builder();
|
||||
}
|
||||
|
@ -83,6 +91,7 @@ public final class BOSHConfiguration extends ConnectionConfiguration {
|
|||
public static final class Builder extends ConnectionConfiguration.Builder<Builder, BOSHConfiguration> {
|
||||
private boolean https;
|
||||
private String file;
|
||||
private Map<String, String> httpHeaders = new HashMap<>();
|
||||
|
||||
private Builder() {
|
||||
}
|
||||
|
@ -101,6 +110,11 @@ public final class BOSHConfiguration extends ConnectionConfiguration {
|
|||
return this;
|
||||
}
|
||||
|
||||
public Builder addHttpHeader(String name, String value) {
|
||||
httpHeaders.put(name, value);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BOSHConfiguration build() {
|
||||
return new BOSHConfiguration(this);
|
||||
|
|
|
@ -22,6 +22,7 @@ import java.io.PipedReader;
|
|||
import java.io.PipedWriter;
|
||||
import java.io.StringReader;
|
||||
import java.io.Writer;
|
||||
import java.util.Map;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
|
@ -156,6 +157,9 @@ public class XMPPBOSHConnection extends AbstractXMPPConnection {
|
|||
if (config.isProxyEnabled()) {
|
||||
cfgBuilder.setProxy(config.getProxyAddress(), config.getProxyPort());
|
||||
}
|
||||
for (Map.Entry<String, String> h : config.getHttpHeaders().entrySet()) {
|
||||
cfgBuilder.addHttpHeader(h.getKey(), h.getValue());
|
||||
}
|
||||
client = BOSHClient.create(cfgBuilder.build());
|
||||
|
||||
client.addBOSHClientConnListener(new BOSHConnectionListener());
|
||||
|
|
Loading…
Reference in a new issue