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

@ -1,17 +1,17 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<root> <root>
<!-- <!--
Microsoft ResX Schema Microsoft ResX Schema
Version 2.0 Version 2.0
The primary goals of this format is to allow a simple XML format The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes various data types are done through the TypeConverter classes
associated with the data types. associated with the data types.
Example: Example:
... ado.net/XML headers & schema ... ... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader> <resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader> <resheader name="version">2.0</resheader>
@ -26,36 +26,36 @@
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value> <value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment> <comment>This is a comment</comment>
</data> </data>
There are any number of "resheader" rows that contain simple There are any number of "resheader" rows that contain simple
name/value pairs. name/value pairs.
Each data row contains a name, and value. The row also contains a Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture. text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the Classes that don't support this are serialized and stored with the
mimetype set. mimetype set.
The mimetype is used for serialized objects, and tells the The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly: extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below. read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64 mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter : System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding. : and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64 mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter : System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding. : and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64 mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter : using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding. : and then encoded with base64 encoding.
--> -->
@ -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>