Skip to content

Commit

Permalink
Merge pull request #1036 from DigDes/revert-1034-develop
Browse files Browse the repository at this point in the history
Revert "support for X-Forwarded-Host header"
  • Loading branch information
andersjonsson authored Mar 7, 2024
2 parents a5dd30a + 182db6c commit 4855660
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 27 deletions.
2 changes: 0 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@ To use it, add a setting like this to appsettings
```json
"FileWSDL": {
"UrlOverride": "",
"SchemeOverride": "",
"VirtualPath": "",
"WebServiceWSDLMapping": {
"Service.asmx": {
Expand All @@ -94,7 +93,6 @@ To use it, add a setting like this to appsettings
```

* UrlOverride - can be used to override the URL in the service description. This can be useful if you are behind a firewall.
* SchemeOverride - can be used to override the HTTP Scheme in the service description. This can be useful if you are behind a firewall and the firewall sets the X-Forwarded-Host header, but the internal HTTP scheme is not the same as the external.
* VirualPath - can be used if you like to add a path between the base URL and service.
* WebServiceWSDLMapping
* UrlOverride - can be used to override the URL for a specific WSDL mapping. This can be useful if you want to host different services under different folder.
Expand Down
24 changes: 19 additions & 5 deletions src/SoapCore/SoapEndpointMiddleware.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
using System.IO;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Reflection;
using System.Runtime.CompilerServices;
Expand All @@ -21,7 +20,6 @@
using Microsoft.AspNetCore.WebUtilities;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
using Microsoft.Extensions.Primitives;
using SoapCore.DocumentationWriter;
using SoapCore.Extensibility;
Expand Down Expand Up @@ -986,7 +984,16 @@ private MetaFromFile GetMeta(HttpContext httpContext)

meta.WSDLFolder = mapping.WSDLFolder;
meta.XsdFolder = mapping.SchemaFolder;
meta.ServerUrl = options.GetServerUrl(httpContext);

if (options.UrlOverride != string.Empty)
{
meta.ServerUrl = options.UrlOverride;
}
else
{
meta.ServerUrl = httpContext.Request.Scheme + "://" + httpContext.Request.Host + "/";
}

return meta;
}

Expand Down Expand Up @@ -1065,9 +1072,16 @@ private async Task ProcessMetaFromFile(HttpContext httpContext, bool showDocumen
meta.CurrentWebService = mapping.UrlOverride;
}

meta.WSDLFolder = mapping.WSDLFolder;
meta.XsdFolder = mapping.SchemaFolder;
meta.ServerUrl = options.GetServerUrl(httpContext);
meta.WSDLFolder = mapping.WSDLFolder;
if (options.UrlOverride != string.Empty)
{
meta.ServerUrl = options.UrlOverride;
}
else
{
meta.ServerUrl = httpContext.Request.Scheme + "://" + httpContext.Request.Host + "/";
}

string wsdlfile = mapping.WsdlFile;

Expand Down
20 changes: 0 additions & 20 deletions src/SoapCore/WSDLFileOptions.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
using Microsoft.AspNetCore.Http;
using System;
using System.Collections.Generic;

Expand All @@ -8,27 +7,8 @@ public class WsdlFileOptions
{
public virtual Dictionary<string, WebServiceWSDLMapping> WebServiceWSDLMapping { get; set; } = new Dictionary<string, WebServiceWSDLMapping>();
public string UrlOverride { get; set; }
public string SchemeOverride { get; set; }
public string VirtualPath { get; set; }
public string AppPath { get; set; }

public virtual string GetServerUrl(HttpContext httpContext)
{
if (!string.IsNullOrEmpty(UrlOverride))
{
return UrlOverride;
}

string scheme = string.IsNullOrEmpty(SchemeOverride) ? httpContext.Request.Scheme : SchemeOverride;
string host = httpContext.Request.Host.ToString();
var forwardedHost = httpContext.Request.Headers["X-Forwarded-Host"];
if (forwardedHost.Count != 0)
{
host = forwardedHost[0];
}

return scheme + "://" + host + "/";
}
}

public class WsdlFileOptionsCaseInsensitive : WsdlFileOptions
Expand Down

0 comments on commit 4855660

Please sign in to comment.