Fix server variable exception messages

This commit is contained in:
Mikael Mengistu 2016-11-03 16:45:33 -07:00 committed by GitHub
parent 222addf264
commit 623333a919
4 changed files with 67 additions and 48 deletions

View File

@ -38,51 +38,51 @@ namespace Microsoft.AspNetCore.Rewrite.Internal.ApacheModRewrite
case "HTTP_FORWARDED": case "HTTP_FORWARDED":
return new HeaderSegment("Forwarded"); return new HeaderSegment("Forwarded");
case "AUTH_TYPE": case "AUTH_TYPE":
throw new NotSupportedException("Rules using the AUTH_TYPE server variable are not supported"); throw new NotSupportedException(Resources.FormatError_UnsupportedServerVariable(serverVariable));
case "CONN_REMOTE_ADDR": case "CONN_REMOTE_ADDR":
return new RemoteAddressSegment(); return new RemoteAddressSegment();
case "CONTEXT_PREFIX": case "CONTEXT_PREFIX":
throw new NotSupportedException("Rules using the CONTEXT_PREFIX server variable are not supported"); throw new NotSupportedException(Resources.FormatError_UnsupportedServerVariable(serverVariable));
case "CONTEXT_DOCUMENT_ROOT": case "CONTEXT_DOCUMENT_ROOT":
throw new NotSupportedException("Rules using the CONTEXT_DOCUMENT_ROOT server variable are not supported"); throw new NotSupportedException(Resources.FormatError_UnsupportedServerVariable(serverVariable));
case "IPV6": case "IPV6":
return new IsIPV6Segment(); return new IsIPV6Segment();
case "PATH_INFO": case "PATH_INFO":
throw new NotImplementedException("Rules using the PATH_INFO server variable are not implemented"); throw new NotImplementedException(Resources.FormatError_UnsupportedServerVariable(serverVariable));
case "QUERY_STRING": case "QUERY_STRING":
return new QueryStringSegment(); return new QueryStringSegment();
case "REMOTE_ADDR": case "REMOTE_ADDR":
return new RemoteAddressSegment(); return new RemoteAddressSegment();
case "REMOTE_HOST": case "REMOTE_HOST":
throw new NotSupportedException("Rules using the REMOTE_HOST server variable are not supported"); throw new NotSupportedException(Resources.FormatError_UnsupportedServerVariable(serverVariable));
case "REMOTE_IDENT": case "REMOTE_IDENT":
throw new NotSupportedException("Rules using the REMOTE_IDENT server variable are not supported"); throw new NotSupportedException(Resources.FormatError_UnsupportedServerVariable(serverVariable));
case "REMOTE_PORT": case "REMOTE_PORT":
return new RemotePortSegment(); return new RemotePortSegment();
case "REMOTE_USER": case "REMOTE_USER":
throw new NotSupportedException("Rules using the REMOTE_USER server variable are not supported"); throw new NotSupportedException(Resources.FormatError_UnsupportedServerVariable(serverVariable));
case "REQUEST_METHOD": case "REQUEST_METHOD":
return new RequestMethodSegment(); return new RequestMethodSegment();
case "SCRIPT_FILENAME": case "SCRIPT_FILENAME":
return new RequestFileNameSegment(); return new RequestFileNameSegment();
case "DOCUMENT_ROOT": case "DOCUMENT_ROOT":
throw new NotSupportedException("Rules using the DOCUMENT_ROOT server variable are not supported"); throw new NotSupportedException(Resources.FormatError_UnsupportedServerVariable(serverVariable));
case "SCRIPT_GROUP": case "SCRIPT_GROUP":
throw new NotSupportedException("Rules using the SCRIPT_GROUP server variable are not supported"); throw new NotSupportedException(Resources.FormatError_UnsupportedServerVariable(serverVariable));
case "SCRIPT_USER": case "SCRIPT_USER":
throw new NotSupportedException("Rules using the SCRIPT_USER server variable are not supported"); throw new NotSupportedException(Resources.FormatError_UnsupportedServerVariable(serverVariable));
case "SERVER_ADDR": case "SERVER_ADDR":
return new LocalAddressSegment(); return new LocalAddressSegment();
case "SERVER_ADMIN": case "SERVER_ADMIN":
throw new NotSupportedException("Rules using the SERVER_ADMIN server variable are not supported"); throw new NotSupportedException(Resources.FormatError_UnsupportedServerVariable(serverVariable));
case "SERVER_NAME": case "SERVER_NAME":
throw new NotSupportedException("Rules using the SERVER_NAME server variable are not supported"); throw new NotSupportedException(Resources.FormatError_UnsupportedServerVariable(serverVariable));
case "SERVER_PORT": case "SERVER_PORT":
return new LocalPortSegment(); return new LocalPortSegment();
case "SERVER_PROTOCOL": case "SERVER_PROTOCOL":
return new ServerProtocolSegment(); return new ServerProtocolSegment();
case "SERVER_SOFTWARE": case "SERVER_SOFTWARE":
throw new NotSupportedException("Rules using the SERVER_SOFTWARE server variable are not supported"); throw new NotSupportedException(Resources.FormatError_UnsupportedServerVariable(serverVariable));
case "TIME_YEAR": case "TIME_YEAR":
return new DateTimeSegment(serverVariable); return new DateTimeSegment(serverVariable);
case "TIME_MON": case "TIME_MON":
@ -100,13 +100,13 @@ namespace Microsoft.AspNetCore.Rewrite.Internal.ApacheModRewrite
case "TIME": case "TIME":
return new DateTimeSegment(serverVariable); return new DateTimeSegment(serverVariable);
case "API_VERSION": case "API_VERSION":
throw new NotSupportedException("Rules using the API_VERSION server variable are not supported"); throw new NotSupportedException(Resources.FormatError_UnsupportedServerVariable(serverVariable));
case "HTTPS": case "HTTPS":
return new IsHttpsModSegment(); return new IsHttpsModSegment();
case "HTTP2": case "HTTP2":
throw new NotSupportedException("Rules using the HTTP2 server variable are not supported"); throw new NotSupportedException(Resources.FormatError_UnsupportedServerVariable(serverVariable));
case "IS_SUBREQ": case "IS_SUBREQ":
throw new NotSupportedException("Rules using the IS_SUBREQ server variable are not supported"); throw new NotSupportedException(Resources.FormatError_UnsupportedServerVariable(serverVariable));
case "REQUEST_FILENAME": case "REQUEST_FILENAME":
return new RequestFileNameSegment(); return new RequestFileNameSegment();
case "REQUEST_SCHEME": case "REQUEST_SCHEME":
@ -114,7 +114,7 @@ namespace Microsoft.AspNetCore.Rewrite.Internal.ApacheModRewrite
case "REQUEST_URI": case "REQUEST_URI":
return new UrlSegment(); return new UrlSegment();
case "THE_REQUEST": case "THE_REQUEST":
throw new NotSupportedException("Rules using the THE_REQUEST server variable are not supported"); throw new NotSupportedException(Resources.FormatError_UnsupportedServerVariable(serverVariable));
default: default:
throw new FormatException(Resources.FormatError_InputParserUnrecognizedParameter(serverVariable, context.Index)); throw new FormatException(Resources.FormatError_InputParserUnrecognizedParameter(serverVariable, context.Index));
} }

View File

@ -15,9 +15,9 @@ namespace Microsoft.AspNetCore.Rewrite.Internal.IISUrlRewrite
{ {
// TODO Add all server variables here. // TODO Add all server variables here.
case "ALL_RAW": case "ALL_RAW":
throw new NotSupportedException("Rules using the ALL_RAW server variable are not supported"); throw new NotSupportedException(Resources.FormatError_UnsupportedServerVariable(serverVariable));
case "APP_POOL_ID": case "APP_POOL_ID":
throw new NotSupportedException("Rules using the APP_POOL_ID server variable are not supported"); throw new NotSupportedException(Resources.FormatError_UnsupportedServerVariable(serverVariable));
case "CONTENT_LENGTH": case "CONTENT_LENGTH":
return new HeaderSegment(HeaderNames.ContentLength); return new HeaderSegment(HeaderNames.ContentLength);
case "CONTENT_TYPE": case "CONTENT_TYPE":
@ -41,13 +41,13 @@ namespace Microsoft.AspNetCore.Rewrite.Internal.IISUrlRewrite
case "LOCAL_ADDR": case "LOCAL_ADDR":
return new LocalAddressSegment(); return new LocalAddressSegment();
case "HTTP_PROXY_CONNECTION": case "HTTP_PROXY_CONNECTION":
throw new NotSupportedException("Rules using the HTTP_PROXY_CONNECTION server variable are not supported"); throw new NotSupportedException(Resources.FormatError_UnsupportedServerVariable(serverVariable));
case "QUERY_STRING": case "QUERY_STRING":
return new QueryStringSegment(); return new QueryStringSegment();
case "REMOTE_ADDR": case "REMOTE_ADDR":
return new RemoteAddressSegment(); return new RemoteAddressSegment();
case "REMOTE_HOST": case "REMOTE_HOST":
throw new NotSupportedException("Rules using the REMOTE_HOST server variable are not supported"); throw new NotSupportedException(Resources.FormatError_UnsupportedServerVariable(serverVariable));
case "REMOTE_PORT": case "REMOTE_PORT":
return new RemotePortSegment(); return new RemotePortSegment();
case "REQUEST_FILENAME": case "REQUEST_FILENAME":

View File

@ -202,6 +202,22 @@ namespace Microsoft.AspNetCore.Rewrite
return string.Format(CultureInfo.CurrentCulture, GetString("Error_UrlRewriteParseError"), p0, p1, p2); return string.Format(CultureInfo.CurrentCulture, GetString("Error_UrlRewriteParseError"), p0, p1, p2);
} }
/// <summary>
/// Rules using the '{0}' server variable are not supported
/// </summary>
internal static string Error_UnsupportedServerVariable
{
get { return GetString("Error_UnsupportedServerVariable"); }
}
/// <summary>
/// Rules using the '{0}' server variable are not supported
/// </summary>
internal static string FormatError_UnsupportedServerVariable(object p0)
{
return string.Format(CultureInfo.CurrentCulture, GetString("Error_UnsupportedServerVariable"), p0);
}
private static string GetString(string name, params string[] formatterNames) private static string GetString(string name, params string[] formatterNames)
{ {
var value = _resourceManager.GetString(name); var value = _resourceManager.GetString(name);

View File

@ -153,4 +153,7 @@
<data name="Error_UrlRewriteParseError" xml:space="preserve"> <data name="Error_UrlRewriteParseError" xml:space="preserve">
<value>Could not parse the UrlRewrite file. Message: '{0}'. Line number '{1}': '{2}'.</value> <value>Could not parse the UrlRewrite file. Message: '{0}'. Line number '{1}': '{2}'.</value>
</data> </data>
<data name="Error_UnsupportedServerVariable" xml:space="preserve">
<value>Rules using the '{0}' server variable are not supported</value>
</data>
</root> </root>