Skip to content

Commit

Permalink
Send Host header in rTorrent requests, fixes #563
Browse files Browse the repository at this point in the history
  • Loading branch information
erickok committed May 23, 2021
1 parent 10a31cc commit 276593f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
10 changes: 7 additions & 3 deletions app/src/main/java/de/timroes/axmlrpc/XMLRPCClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,8 @@ public class XMLRPCClient {

private DefaultHttpClient httpclient;

private String hostname;

private String url;

private Map<Long,Caller> backgroundCalls = new ConcurrentHashMap<Long, Caller>();
Expand All @@ -161,11 +163,12 @@ public class XMLRPCClient {
* @param url The URL to send the requests to.
* @param flags A combination of flags to be set.
*/
public XMLRPCClient(DefaultHttpClient httpclient, String url, int flags) {
public XMLRPCClient(DefaultHttpClient httpclient, String hostname, String url, int flags) {

this.serializerHandler = new SerializerHandler(flags);

this.httpclient = httpclient;
this.hostname = hostname;
this.url = url;
this.flags = flags;

Expand All @@ -181,8 +184,8 @@ public XMLRPCClient(DefaultHttpClient httpclient, String url, int flags) {
* @param httpclient The already-initialized Apache HttpClient to use for connection.
* @param url The url to send the requests to.
*/
public XMLRPCClient(DefaultHttpClient httpclient, String url) {
this(httpclient, url, FLAGS_NONE);
public XMLRPCClient(DefaultHttpClient httpclient, String hostname, String url) {
this(httpclient, hostname, url, FLAGS_NONE);
}

/**
Expand Down Expand Up @@ -381,6 +384,7 @@ public Object call(String methodName, Object[] params) throws XMLRPCException, C
HttpPost post = new HttpPost(url);
post.getParams().setParameter(ClientPNames.HANDLE_REDIRECTS, false);
post.setHeader(CONTENT_TYPE, TYPE_XML);
post.setHeader(HOST, hostname);
StringEntity entity = new StringEntity(c.getXML(), HTTP.UTF_8);
entity.setContentType(TYPE_XML);
post.setEntity(entity);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,8 @@ private Object makeRtorrentCall(Log log, String serverMethod, Object[] arguments
private void initialise() throws DaemonException, MalformedURLException {

int flags = XMLRPCClient.FLAGS_8BYTE_INT;
this.rpcclient = new XMLRPCClient(HttpHelper.createStandardHttpClient(settings, true), buildWebUIUrl(), flags);
this.rpcclient = new XMLRPCClient(HttpHelper.createStandardHttpClient(settings, true),
settings.getAddress(), buildWebUIUrl(), flags);

}

Expand Down

0 comments on commit 276593f

Please sign in to comment.