Skip to content

Commit 7258a36

Browse files
committed
Added URL port support
This does not work for bare IP addresses.
1 parent 21ab373 commit 7258a36

File tree

3 files changed

+34
-6
lines changed

3 files changed

+34
-6
lines changed

MacroscopeStandards/MacroscopeRobots.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,7 @@ public static string GenerateRobotUrl ( string Url )
179179
DebugMsg( string.Format( "ROBOTS Disabled: {0}", Url ), true );
180180

181181
Uri BaseUri = null;
182+
string BaseUriPort = "";
182183
Uri RobotsUri = null;
183184
string RobotsTxtUrl = null;
184185

@@ -187,11 +188,17 @@ public static string GenerateRobotUrl ( string Url )
187188

188189
BaseUri = new Uri ( Url, UriKind.Absolute );
189190

191+
if( BaseUri.Port > 0 )
192+
{
193+
BaseUriPort = string.Format( ":{0}", BaseUri.Port );
194+
}
195+
190196
RobotsUri = new Uri (
191197
string.Format(
192-
"{0}://{1}{2}",
198+
"{0}://{1}{2}{3}",
193199
BaseUri.Scheme,
194200
BaseUri.Host,
201+
BaseUriPort,
195202
"/robots.txt"
196203
),
197204
UriKind.Absolute

MacroscopeTools/MacroscopeUrlUtils.cs

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ public static string MakeUrlAbsolute ( string BaseUrl, string Url )
101101

102102
string UrlFixed;
103103
Uri BaseUri = null;
104+
string BaseUriPort = "";
104105
Uri NewUri = null;
105106

106107
Regex reHTTP = new Regex ( "^https?:" );
@@ -110,13 +111,22 @@ public static string MakeUrlAbsolute ( string BaseUrl, string Url )
110111
Regex reHash = new Regex ( "^#" );
111112
Regex reUnsupportedScheme = new Regex ( "^[^:]+:" );
112113

114+
BaseUrl = HtmlEntity.DeEntitize( BaseUrl );
115+
BaseUrl = Uri.UnescapeDataString( BaseUrl );
116+
113117
Url = HtmlEntity.DeEntitize( Url );
114-
115118
Url = Uri.UnescapeDataString( Url );
116119

117120
try
118121
{
122+
119123
BaseUri = new Uri ( BaseUrl, UriKind.Absolute );
124+
125+
if( BaseUri.Port > 0 )
126+
{
127+
BaseUriPort = string.Format( ":{0}", BaseUri.Port );
128+
}
129+
120130
}
121131
catch( UriFormatException ex )
122132
{
@@ -193,9 +203,10 @@ public static string MakeUrlAbsolute ( string BaseUrl, string Url )
193203
{
194204
NewUri = new Uri (
195205
string.Format(
196-
"{0}://{1}{2}",
206+
"{0}://{1}{2}{3}",
197207
BaseUri.Scheme,
198208
BaseUri.Host,
209+
BaseUriPort,
199210
Url
200211
),
201212
UriKind.Absolute
@@ -220,9 +231,10 @@ public static string MakeUrlAbsolute ( string BaseUrl, string Url )
220231
{
221232
NewUri = new Uri (
222233
string.Format(
223-
"{0}://{1}{2}{3}",
234+
"{0}://{1}{2}{3}{4}",
224235
BaseUri.Scheme,
225236
BaseUri.Host,
237+
BaseUriPort,
226238
BaseUri.AbsolutePath,
227239
Url
228240
),
@@ -252,9 +264,10 @@ public static string MakeUrlAbsolute ( string BaseUrl, string Url )
252264
{
253265
NewUri = new Uri (
254266
string.Format(
255-
"{0}://{1}{2}",
267+
"{0}://{1}{2}{3}",
256268
BaseUri.Scheme,
257269
BaseUri.Host,
270+
BaseUriPort,
258271
NewUrl
259272
),
260273
UriKind.Absolute
@@ -313,9 +326,10 @@ public static string MakeUrlAbsolute ( string BaseUrl, string Url )
313326
{
314327
NewUri = new Uri (
315328
string.Format(
316-
"{0}://{1}{2}",
329+
"{0}://{1}{2}{3}",
317330
BaseUri.Scheme,
318331
BaseUri.Host,
332+
BaseUriPort,
319333
NewPath
320334
),
321335
UriKind.Absolute

notes.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,10 @@ HTTP Protocol tests: http://httpbin.org/
66
Google Search Console API Documentation:
77

88
https://developers.google.com/webmaster-tools/
9+
10+
11+
12+
13+
14+
15+
http://10.0.1.8:4000/manual/

0 commit comments

Comments
 (0)