aboutsummaryrefslogtreecommitdiff
path: root/Mono.Nat
diff options
context:
space:
mode:
Diffstat (limited to 'Mono.Nat')
-rw-r--r--Mono.Nat/Upnp/Messages/GetServicesMessage.cs39
-rw-r--r--Mono.Nat/Upnp/Messages/UpnpMessage.cs49
-rw-r--r--Mono.Nat/Upnp/UpnpNatDevice.cs4
3 files changed, 31 insertions, 61 deletions
diff --git a/Mono.Nat/Upnp/Messages/GetServicesMessage.cs b/Mono.Nat/Upnp/Messages/GetServicesMessage.cs
index 72b4c2b25..f619f5ca4 100644
--- a/Mono.Nat/Upnp/Messages/GetServicesMessage.cs
+++ b/Mono.Nat/Upnp/Messages/GetServicesMessage.cs
@@ -25,50 +25,37 @@
//
using System;
-using System.Diagnostics;
using System.Net;
using MediaBrowser.Common.Net;
-using Microsoft.Extensions.Logging;
namespace Mono.Nat.Upnp
{
internal class GetServicesMessage : MessageBase
{
- private string servicesDescriptionUrl;
- private EndPoint hostAddress;
- private readonly ILogger _logger;
+ private string _servicesDescriptionUrl;
+ private EndPoint _hostAddress;
- public GetServicesMessage(string description, EndPoint hostAddress, ILogger logger)
+ public GetServicesMessage(string description, EndPoint hostAddress)
: base(null)
{
if (string.IsNullOrEmpty(description))
- _logger.LogWarning("Description is null");
-
- if (hostAddress == null)
- _logger.LogWarning("hostaddress is null");
-
- this.servicesDescriptionUrl = description;
- this.hostAddress = hostAddress;
- _logger = logger;
- }
-
- public override string Method
- {
- get
{
- return "GET";
+ throw new ArgumentException("Description is null/empty", nameof(description));
}
+
+ this._servicesDescriptionUrl = description;
+ this._hostAddress = hostAddress ?? throw new ArgumentNullException(nameof(hostAddress));
}
+ public override string Method => "GET";
+
public override HttpRequestOptions Encode()
{
- var req = new HttpRequestOptions();
-
- // The periodic request logging may keep some devices awake
- req.LogRequestAsDebug = true;
- req.LogErrors = false;
+ var req = new HttpRequestOptions()
+ {
+ Url = $"http://{this._hostAddress}{this._servicesDescriptionUrl}"
+ };
- req.Url = "http://" + this.hostAddress.ToString() + this.servicesDescriptionUrl;
req.RequestHeaders.Add("ACCEPT-LANGUAGE", "en");
return req;
diff --git a/Mono.Nat/Upnp/Messages/UpnpMessage.cs b/Mono.Nat/Upnp/Messages/UpnpMessage.cs
index 1151dd997..d47241d4a 100644
--- a/Mono.Nat/Upnp/Messages/UpnpMessage.cs
+++ b/Mono.Nat/Upnp/Messages/UpnpMessage.cs
@@ -24,13 +24,8 @@
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
-using System;
-using System.Diagnostics;
using System.Xml;
-using System.Net;
-using System.IO;
using System.Text;
-using System.Globalization;
using MediaBrowser.Common.Net;
namespace Mono.Nat.Upnp
@@ -46,41 +41,31 @@ namespace Mono.Nat.Upnp
protected HttpRequestOptions CreateRequest(string upnpMethod, string methodParameters)
{
- string ss = "http://" + this.device.HostEndPoint.ToString() + this.device.ControlUrl;
+ var req = new HttpRequestOptions()
+ {
+ Url = $"http://{this.device.HostEndPoint}{this.device.ControlUrl}",
+ EnableKeepAlive = false,
+ RequestContentType = "text/xml",
+ RequestContent = "<s:Envelope "
+ + "xmlns:s=\"http://schemas.xmlsoap.org/soap/envelope/\" "
+ + "s:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\">"
+ + "<s:Body>"
+ + "<u:" + upnpMethod + " "
+ + "xmlns:u=\"" + device.ServiceType + "\">"
+ + methodParameters
+ + "</u:" + upnpMethod + ">"
+ + "</s:Body>"
+ + "</s:Envelope>\r\n\r\n"
+ };
- var req = new HttpRequestOptions();
- req.LogErrors = false;
-
- // The periodic request logging may keep some devices awake
- req.LogRequestAsDebug = true;
-
- req.Url = ss;
- req.EnableKeepAlive = false;
- req.RequestContentType = "text/xml";
- req.AppendCharsetToMimeType = true;
req.RequestHeaders.Add("SOAPACTION", "\"" + device.ServiceType + "#" + upnpMethod + "\"");
- string bodyString = "<s:Envelope "
- + "xmlns:s=\"http://schemas.xmlsoap.org/soap/envelope/\" "
- + "s:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\">"
- + "<s:Body>"
- + "<u:" + upnpMethod + " "
- + "xmlns:u=\"" + device.ServiceType + "\">"
- + methodParameters
- + "</u:" + upnpMethod + ">"
- + "</s:Body>"
- + "</s:Envelope>\r\n\r\n";
-
- req.RequestContentBytes = System.Text.Encoding.UTF8.GetBytes(bodyString);
return req;
}
public abstract HttpRequestOptions Encode();
- public virtual string Method
- {
- get { return "POST"; }
- }
+ public virtual string Method => "POST";
protected void WriteFullElement(XmlWriter writer, string element, string value)
{
diff --git a/Mono.Nat/Upnp/UpnpNatDevice.cs b/Mono.Nat/Upnp/UpnpNatDevice.cs
index fd408ee63..3ff1eeb90 100644
--- a/Mono.Nat/Upnp/UpnpNatDevice.cs
+++ b/Mono.Nat/Upnp/UpnpNatDevice.cs
@@ -27,11 +27,9 @@
//
using System;
-using System.IO;
using System.Net;
using System.Xml;
using System.Text;
-using System.Diagnostics;
using System.Threading.Tasks;
using MediaBrowser.Common.Net;
using Microsoft.Extensions.Logging;
@@ -96,7 +94,7 @@ namespace Mono.Nat.Upnp
public async Task GetServicesList()
{
// Create a HTTPWebRequest to download the list of services the device offers
- var message = new GetServicesMessage(this.serviceDescriptionUrl, this.hostEndPoint, _logger);
+ var message = new GetServicesMessage(this.serviceDescriptionUrl, this.hostEndPoint);
using (var response = await _httpClient.SendAsync(message.Encode(), message.Method).ConfigureAwait(false))
{