Skip to content

Commit 941b921

Browse files
committed
API Client: added option for proxy port
1 parent 7c32afd commit 941b921

File tree

9 files changed

+86
-30
lines changed

9 files changed

+86
-30
lines changed

src/Tools/SmartStore.WebApi.Client/App.config

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@
4040
<setting name="FileUpload" serializeAs="String">
4141
<value />
4242
</setting>
43+
<setting name="ApiProxyPort" serializeAs="String">
44+
<value />
45+
</setting>
4346
</SmartStore.WebApi.Client.Properties.Settings>
4447

4548
</userSettings>

src/Tools/SmartStore.WebApi.Client/MainForm.Designer.cs

Lines changed: 43 additions & 19 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Tools/SmartStore.WebApi.Client/MainForm.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ public MainForm()
3030
txtPublicKey.Text = s.ApiPublicKey;
3131
txtSecretKey.Text = s.ApiSecretKey;
3232
txtUrl.Text = s.ApiUrl;
33+
txtProxyPort.Text = s.ApiProxyPort;
3334
txtVersion.Text = s.ApiVersion;
3435
cboPath.Items.FromString(s.ApiPaths);
3536
cboQuery.Items.FromString(s.ApiQuery);
@@ -77,6 +78,7 @@ public MainForm()
7778
s.ApiPublicKey = txtPublicKey.Text;
7879
s.ApiSecretKey = txtSecretKey.Text;
7980
s.ApiUrl = txtUrl.Text;
81+
s.ApiProxyPort = txtProxyPort.Text;
8082
s.ApiVersion = txtVersion.Text;
8183
Settings.Default[radioOdata.Checked ? "ApiPaths" : "ApiPaths2"] = cboPath.Items.IntoString();
8284
s.ApiQuery = cboQuery.Items.IntoString();
@@ -100,11 +102,14 @@ private void CallTheApi()
100102
cboPath.Text = "/" + cboPath.Text;
101103
}
102104

105+
int.TryParse(txtProxyPort.Text, out var proxyPort);
106+
103107
var context = new WebApiRequestContext
104108
{
105109
PublicKey = txtPublicKey.Text,
106110
SecretKey = txtSecretKey.Text,
107111
Url = txtUrl.Text + (radioOdata.Checked ? "odata/" : "api/") + txtVersion.Text + cboPath.Text,
112+
ProxyPort = proxyPort,
108113
HttpMethod = cboMethod.Text,
109114
HttpAcceptType = radioJson.Checked ? ApiConsumer.JsonAcceptType : ApiConsumer.XmlAcceptType,
110115
AdditionalHeaders = cboHeaders.Text

src/Tools/SmartStore.WebApi.Client/Program.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ namespace SmartStore.WebApi.Client
55
{
66
static class Program
77
{
8-
public static string AppName => "SmartStore Web API Client v.1.7";
9-
public static string ConsumerName => "My shopping data consumer v.1.7";
8+
public static string AppName => "SmartStore Web API Client v.1.8";
9+
public static string ConsumerName => "My shopping data consumer v.1.8";
1010

1111
[STAThread]
1212
static void Main()

src/Tools/SmartStore.WebApi.Client/Properties/AssemblyInfo.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
[assembly: AssemblyConfiguration("")]
1010
[assembly: AssemblyCompany("")]
1111
[assembly: AssemblyProduct("SmartStoreWebApiClient")]
12-
[assembly: AssemblyCopyright("Copyright © SmartStore AG 2020")]
12+
[assembly: AssemblyCopyright("Copyright © SmartStore AG 2021")]
1313
[assembly: AssemblyTrademark("")]
1414
[assembly: AssemblyCulture("")]
1515

@@ -31,5 +31,5 @@
3131
// Sie können alle Werte angeben oder die standardmäßigen Build- und Revisionsnummern
3232
// übernehmen, indem Sie "*" eingeben:
3333
// [assembly: AssemblyVersion("1.0.*")]
34-
[assembly: AssemblyVersion("1.7.0.0")]
35-
[assembly: AssemblyFileVersion("1.7.0.0")]
34+
[assembly: AssemblyVersion("1.8.0.0")]
35+
[assembly: AssemblyFileVersion("1.8.0.0")]

src/Tools/SmartStore.WebApi.Client/Properties/Settings.Designer.cs

Lines changed: 13 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Tools/SmartStore.WebApi.Client/Properties/Settings.settings

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,5 +32,8 @@
3232
<Setting Name="FileUpload" Type="System.String" Scope="User">
3333
<Value Profile="(Default)" />
3434
</Setting>
35+
<Setting Name="ApiProxyPort" Type="System.String" Scope="User">
36+
<Value Profile="(Default)" />
37+
</Setting>
3538
</Settings>
3639
</SettingsFile>

src/Tools/SmartStore.WebApi.Client/WebApi/WebApiConsumer.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -343,6 +343,12 @@ public HttpWebRequest StartRequest(WebApiRequestContext context, string content,
343343
request.Headers.Add(HttpRequestHeader.ContentMd5, contentMd5Hash);
344344
}
345345

346+
// API behind a reverse proxy?
347+
if (context.ProxyPort > 0)
348+
{
349+
context.Url = new UriBuilder(context.Url) { Port = context.ProxyPort }.Uri.ToString();
350+
}
351+
346352
var messageRepresentation = CreateMessageRepresentation(context, contentMd5Hash, timestamp, true);
347353
//Debug.WriteLine(messageRepresentation);
348354
var signature = CreateSignature(context.SecretKey, messageRepresentation);

src/Tools/SmartStore.WebApi.Client/WebApi/WebApiCore.cs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,22 +8,25 @@ public class WebApiRequestContext
88
public string SecretKey { get; set; }
99

1010
public string Url { get; set; }
11+
public int ProxyPort { get; set; }
1112
public string HttpMethod { get; set; }
1213
public string HttpAcceptType { get; set; }
1314
public string AdditionalHeaders { get; set; }
1415

1516
public bool IsValid => !string.IsNullOrWhiteSpace(PublicKey) && !string.IsNullOrWhiteSpace(SecretKey) &&
1617
!string.IsNullOrWhiteSpace(Url) &&
1718
!string.IsNullOrWhiteSpace(HttpMethod) && !string.IsNullOrWhiteSpace(HttpAcceptType);
19+
1820
public override string ToString()
1921
{
2022
var sb = new StringBuilder();
2123

22-
sb.AppendLine(string.Format("PublicKey: ", PublicKey));
23-
sb.AppendLine(string.Format("SecretKey: ", SecretKey));
24-
sb.AppendLine(string.Format("Url: ", Url));
25-
sb.AppendLine(string.Format("HttpMethod: ", HttpMethod));
26-
sb.AppendLine(string.Format("HttpAcceptType: ", HttpAcceptType));
24+
sb.AppendLine("PublicKey: " + PublicKey);
25+
sb.AppendLine("SecretKey: " + SecretKey);
26+
sb.AppendLine("Url: " + Url);
27+
sb.AppendLine("Proxy Port: " + (ProxyPort > 0 ? ProxyPort.ToString() : ""));
28+
sb.AppendLine("HttpMethod: " + HttpMethod);
29+
sb.AppendLine("HttpAcceptType: " + HttpAcceptType);
2730

2831
return sb.ToString();
2932
}

0 commit comments

Comments
 (0)