Exceptions more descriptive and more NSE

This commit is contained in:
Justin Kotalik 2016-08-31 10:10:20 -07:00
parent 65e7f7f44b
commit 51cd14efba
8 changed files with 43 additions and 39 deletions

View File

@ -44,6 +44,8 @@ namespace Microsoft.AspNetCore.Rewrite.Internal.ModRewrite
switch (tokens[0]) switch (tokens[0])
{ {
case "RewriteBase": case "RewriteBase":
// the notion of the path base spans across all rules, not just mod_rewrite
// So not implemented for now
throw new NotImplementedException("RewriteBase is not implemented"); throw new NotImplementedException("RewriteBase is not implemented");
case "RewriteCond": case "RewriteCond":
try try
@ -91,7 +93,8 @@ namespace Microsoft.AspNetCore.Rewrite.Internal.ModRewrite
} }
break; break;
case "RewriteMap": case "RewriteMap":
throw new NotImplementedException("RewriteMap to be added soon."); // Lack of use
throw new NotImplementedException("RewriteMap are not implemented");
case "RewriteEngine": case "RewriteEngine":
// Explicitly do nothing here, no notion of turning on regex engine. // Explicitly do nothing here, no notion of turning on regex engine.
break; break;

View File

@ -132,16 +132,19 @@ namespace Microsoft.AspNetCore.Rewrite.Internal.ModRewrite
condition.Match = new IsFileMatch(input.Invert); condition.Match = new IsFileMatch(input.Invert);
break; break;
case OperationType.SymbolicLink: case OperationType.SymbolicLink:
throw new NotImplementedException("Symbolic links are not implemented"); // TODO see if FileAttributes.ReparsePoint works for this?
throw new NotImplementedException("Symbolic links are not supported because " +
"of cross platform implementation");
case OperationType.Size: case OperationType.Size:
condition.Match = new FileSizeMatch(input.Invert); condition.Match = new FileSizeMatch(input.Invert);
break; break;
case OperationType.ExistingUrl: case OperationType.ExistingUrl:
throw new NotImplementedException("Existing Url lookups not implemented"); throw new NotSupportedException("Existing Url lookups not supported because it requires a subrequest");
case OperationType.Executable: case OperationType.Executable:
throw new NotImplementedException("Executable Property search is not implemented"); throw new NotSupportedException("Executable Property is not supported because Windows " +
"requires a pinvoke to get this property");
default: default:
throw new ArgumentException("Invalid operation for property comparison."); throw new ArgumentException("Invalid operation for property comparison");
} }
break; break;
} }
@ -166,7 +169,6 @@ namespace Microsoft.AspNetCore.Rewrite.Internal.ModRewrite
Pattern pattern, Pattern pattern,
Flags flags) Flags flags)
{ {
// first create pre conditions
string flag; string flag;
if (flags.GetValue(FlagType.Cookie, out flag)) if (flags.GetValue(FlagType.Cookie, out flag))
{ {

View File

@ -38,51 +38,51 @@ namespace Microsoft.AspNetCore.Rewrite.Internal.ModRewrite
case "HTTP_FORWARDED": case "HTTP_FORWARDED":
return new HeaderSegment("Forwarded"); return new HeaderSegment("Forwarded");
case "AUTH_TYPE": case "AUTH_TYPE":
throw new NotImplementedException("Auth-Type server variable is not supported"); throw new NotSupportedException("Rules using the AUTH_TYPE server variable are not supported");
case "CONN_REMOTE_ADDR": case "CONN_REMOTE_ADDR":
return new RemoteAddressSegment(); return new RemoteAddressSegment();
case "CONTEXT_PREFIX": case "CONTEXT_PREFIX":
throw new NotImplementedException("Context-prefix server variable is not supported"); throw new NotSupportedException("Rules using the CONTEXT_PREFIX server variable are not supported");
case "CONTEXT_DOCUMENT_ROOT": case "CONTEXT_DOCUMENT_ROOT":
throw new NotImplementedException("Context-Document-Root server variable is not supported"); throw new NotSupportedException("Rules using the CONTEXT_DOCUMENT_ROOT server variable are not supported");
case "IPV6": case "IPV6":
return new IsIPV6Segment(); return new IsIPV6Segment();
case "PATH_INFO": case "PATH_INFO":
throw new NotImplementedException("Path-Info server variable is not supported"); throw new NotImplementedException("Rules using the PATH_INFO server variable are not implemented");
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 NotImplementedException("Remote-Host server variable is not supported"); throw new NotSupportedException("Rules using the REMOTE_HOST server variable are not supported");
case "REMOTE_IDENT": case "REMOTE_IDENT":
throw new NotImplementedException("Remote-Identity server variable is not supported"); throw new NotSupportedException("Rules using the REMOTE_IDENT server variable are not supported");
case "REMOTE_PORT": case "REMOTE_PORT":
return new RemotePortSegment(); return new RemotePortSegment();
case "REMOTE_USER": case "REMOTE_USER":
throw new NotImplementedException("Remote-User server variable is not supported"); throw new NotSupportedException("Rules using the REMOTE_USER server variable are not supported");
case "REQUEST_METHOD": case "REQUEST_METHOD":
return new RequestMethodSegment(); return new RequestMethodSegment();
case "SCRIPT_FILENAME": case "SCRIPT_FILENAME":
throw new NotImplementedException("Script-Filename server variable is not supported"); return new RequestFileNameSegment();
case "DOCUMENT_ROOT": case "DOCUMENT_ROOT":
throw new NotImplementedException("Document-Root server variable is not supported"); throw new NotSupportedException("Rules using the DOCUMENT_ROOT server variable are not supported");
case "SCRIPT_GROUP": case "SCRIPT_GROUP":
throw new NotImplementedException("Script-Group server variable is not supported"); throw new NotSupportedException("Rules using the SCRIPT_GROUP server variable are not supported");
case "SCRIPT_USER": case "SCRIPT_USER":
throw new NotImplementedException("Script-User server variable is not supported"); throw new NotSupportedException("Rules using the SCRIPT_USER server variable are not supported");
case "SERVER_ADDR": case "SERVER_ADDR":
return new LocalAddressSegment(); return new LocalAddressSegment();
case "SERVER_ADMIN": case "SERVER_ADMIN":
throw new NotImplementedException("Server-Admin server variable is not supported"); throw new NotSupportedException("Rules using the SERVER_ADMIN server variable are not supported");
case "SERVER_NAME": case "SERVER_NAME":
throw new NotImplementedException("Server-Name server variable is not supported"); throw new NotSupportedException("Rules using the SERVER_NAME server variable are not supported");
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 NotImplementedException("Server-Software server variable is not supported"); throw new NotSupportedException("Rules using the SERVER_SOFTWARE server variable are not supported");
case "TIME_YEAR": case "TIME_YEAR":
return new DateTimeSegment(variable); return new DateTimeSegment(variable);
case "TIME_MON": case "TIME_MON":
@ -100,13 +100,13 @@ namespace Microsoft.AspNetCore.Rewrite.Internal.ModRewrite
case "TIME": case "TIME":
return new DateTimeSegment(variable); return new DateTimeSegment(variable);
case "API_VERSION": case "API_VERSION":
throw new NotImplementedException(); throw new NotSupportedException();
case "HTTPS": case "HTTPS":
return new IsHttpsModSegment(); return new IsHttpsModSegment();
case "HTTP2": case "HTTP2":
throw new NotImplementedException("Http2 server variable is not supported"); throw new NotSupportedException("Rules using the HTTP2 server variable are not supported");
case "IS_SUBREQ": case "IS_SUBREQ":
throw new NotImplementedException("Is-Subrequest server variable is not supported"); throw new NotSupportedException("Rules using the IS_SUBREQ server variable are not supported");
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.ModRewrite
case "REQUEST_URI": case "REQUEST_URI":
return new UrlSegment(); return new UrlSegment();
case "THE_REQUEST": case "THE_REQUEST":
throw new NotImplementedException("The-Request server variable is not supported"); throw new NotSupportedException("Rules using the THE_REQUEST server variable are not supported");
default: default:
throw new FormatException(Resources.FormatError_InputParserUnrecognizedParameter(variable, context.Index)); throw new FormatException(Resources.FormatError_InputParserUnrecognizedParameter(variable, context.Index));
} }

View File

@ -11,13 +11,13 @@ namespace Microsoft.AspNetCore.Rewrite.Internal.UrlActions
public ChangeCookieAction(string cookie) public ChangeCookieAction(string cookie)
{ {
// TODO // TODO
throw new NotImplementedException(cookie); throw new NotImplementedException("Changing the cookie is not implemented");
} }
public override void ApplyAction(RewriteContext context, MatchResults ruleMatch, MatchResults condMatch) public override void ApplyAction(RewriteContext context, MatchResults ruleMatch, MatchResults condMatch)
{ {
// modify the cookies // modify the cookies
throw new NotImplementedException("Changing the cookie is not implemented");
} }
} }
} }

View File

@ -11,13 +11,13 @@ namespace Microsoft.AspNetCore.Rewrite.Internal.UrlActions
public ChangeEnvironmentAction(string env) public ChangeEnvironmentAction(string env)
{ {
// TODO // TODO
throw new NotImplementedException(); throw new NotImplementedException("Changing the environment is not implemented");
} }
public override void ApplyAction(RewriteContext context, MatchResults ruleMatch, MatchResults condMatch) public override void ApplyAction(RewriteContext context, MatchResults ruleMatch, MatchResults condMatch)
{ {
// Do stuff to modify the env // Do stuff to modify the env
throw new NotImplementedException(); throw new NotImplementedException("Changing the environment is not implemented");
} }
} }
} }

View File

@ -101,7 +101,7 @@ namespace Microsoft.AspNetCore.Rewrite.Internal.UrlRewrite
} }
case "UrlDecode": case "UrlDecode":
{ {
throw new NotImplementedException("UrlDecode is not supported."); throw new NotImplementedException("UrlDecode is not implemented because of no great library available");
} }
case "UrlEncode": case "UrlEncode":
{ {

View File

@ -15,9 +15,9 @@ namespace Microsoft.AspNetCore.Rewrite.Internal.UrlRewrite
{ {
// TODO Add all server variables here. // TODO Add all server variables here.
case "ALL_RAW": case "ALL_RAW":
throw new NotImplementedException("All-Raw server variable not implemented"); throw new NotSupportedException("Rules using the AUTH_TYPE server variable are not supported");
case "APP_POOL_ID": case "APP_POOL_ID":
throw new NotImplementedException("All-Pool-Id server variable not implemented"); throw new NotSupportedException("Rules using the AUTH_TYPE server variable are not supported");
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.UrlRewrite
case "LOCAL_ADDR": case "LOCAL_ADDR":
return new LocalAddressSegment(); return new LocalAddressSegment();
case "HTTP_PROXY_CONNECTION": case "HTTP_PROXY_CONNECTION":
throw new NotSupportedException("Proxy Connections not supported"); throw new NotSupportedException("Rules using the AUTH_TYPE server variable are not supported");
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 NotImplementedException("Remote-Host server variable not implemented"); throw new NotSupportedException("Rules using the REMOTE_HOST server variable are not supported");
case "REMOTE_PORT": case "REMOTE_PORT":
return new RemotePortSegment(); return new RemotePortSegment();
case "REQUEST_FILENAME": case "REQUEST_FILENAME":
@ -55,7 +55,7 @@ namespace Microsoft.AspNetCore.Rewrite.Internal.UrlRewrite
case "REQUEST_URI": case "REQUEST_URI":
return new UrlSegment(); return new UrlSegment();
default: default:
throw new FormatException("Unrecognized server variable."); throw new FormatException("Unrecognized server variable");
} }
} }
} }

View File

@ -53,10 +53,9 @@ namespace Microsoft.AspNetCore.Rewrite.Internal.UrlRewrite
_action = new RedirectAction(statusCode, url, appendQueryString); _action = new RedirectAction(statusCode, url, appendQueryString);
break; break;
case ActionType.AbortRequest: case ActionType.AbortRequest:
throw new NotImplementedException("Abort Requests are not supported"); throw new NotImplementedException("Abort Requests are not implemented");
case ActionType.CustomResponse: case ActionType.CustomResponse:
// TODO throw new NotImplementedException("Custom Responses are not implemented");
throw new NotImplementedException("Custom Responses are not supported");
} }
} }
@ -79,7 +78,7 @@ namespace Microsoft.AspNetCore.Rewrite.Internal.UrlRewrite
break; break;
} }
case PatternSyntax.WildCard: case PatternSyntax.WildCard:
throw new NotImplementedException("Wildcard syntax is not supported"); throw new NotSupportedException("Wildcard syntax is not supported");
case PatternSyntax.ExactMatch: case PatternSyntax.ExactMatch:
_initialMatch = new ExactMatch(ignoreCase, input, negate); _initialMatch = new ExactMatch(ignoreCase, input, negate);
break; break;
@ -132,7 +131,7 @@ namespace Microsoft.AspNetCore.Rewrite.Internal.UrlRewrite
break; break;
} }
case PatternSyntax.WildCard: case PatternSyntax.WildCard:
throw new NotImplementedException("Wildcard syntax is not supported"); throw new NotSupportedException("Wildcard syntax is not supported");
case PatternSyntax.ExactMatch: case PatternSyntax.ExactMatch:
if (pattern == null) if (pattern == null)
{ {