diff --git a/NuGet.config b/NuGet.config index 1707938c61..03704957e8 100644 --- a/NuGet.config +++ b/NuGet.config @@ -1,4 +1,4 @@ - + diff --git a/src/Microsoft.AspNet.Html.Abstractions/project.json b/src/Microsoft.AspNet.Html.Abstractions/project.json index 6ecc82e292..eee0e0ab1b 100644 --- a/src/Microsoft.AspNet.Html.Abstractions/project.json +++ b/src/Microsoft.AspNet.Html.Abstractions/project.json @@ -5,6 +5,9 @@ "type": "git", "url": "git://github.com/aspnet/httpabstractions" }, + "compilationOptions": { + "warningsAsErrors": true + }, "dependencies": { "Microsoft.Framework.WebEncoders.Core": "1.0.0-*" }, diff --git a/src/Microsoft.AspNet.Http.Abstractions/Authentication/AuthenticationManager.cs b/src/Microsoft.AspNet.Http.Abstractions/Authentication/AuthenticationManager.cs index e10e081717..a18fe99c97 100644 --- a/src/Microsoft.AspNet.Http.Abstractions/Authentication/AuthenticationManager.cs +++ b/src/Microsoft.AspNet.Http.Abstractions/Authentication/AuthenticationManager.cs @@ -1,11 +1,11 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. +using System; using System.Collections.Generic; using System.Security.Claims; using System.Threading.Tasks; using Microsoft.AspNet.Http.Features.Authentication; -using Microsoft.Framework.Internal; namespace Microsoft.AspNet.Http.Authentication { @@ -13,10 +13,15 @@ namespace Microsoft.AspNet.Http.Authentication { public abstract IEnumerable GetAuthenticationSchemes(); - public abstract Task AuthenticateAsync([NotNull] AuthenticateContext context); + public abstract Task AuthenticateAsync(AuthenticateContext context); - public virtual async Task AuthenticateAsync([NotNull] string authenticationScheme) + public virtual async Task AuthenticateAsync(string authenticationScheme) { + if (authenticationScheme == null) + { + throw new ArgumentNullException(nameof(authenticationScheme)); + } + var context = new AuthenticateContext(authenticationScheme); await AuthenticateAsync(context); return context.Principal; @@ -32,42 +37,77 @@ namespace Microsoft.AspNet.Http.Authentication return ChallengeAsync(authenticationScheme: string.Empty, properties: properties); } - public virtual Task ChallengeAsync([NotNull] string authenticationScheme) + public virtual Task ChallengeAsync(string authenticationScheme) { + if (authenticationScheme == null) + { + throw new ArgumentNullException(nameof(authenticationScheme)); + } + return ChallengeAsync(authenticationScheme: authenticationScheme, properties: null); } // Leave it up to authentication handler to do the right thing for the challenge - public virtual Task ChallengeAsync([NotNull] string authenticationScheme, AuthenticationProperties properties) + public virtual Task ChallengeAsync(string authenticationScheme, AuthenticationProperties properties) { + if (authenticationScheme == null) + { + throw new ArgumentNullException(nameof(authenticationScheme)); + } + return ChallengeAsync(authenticationScheme, properties, ChallengeBehavior.Automatic); } - public virtual Task SignInAsync([NotNull] string authenticationScheme, [NotNull] ClaimsPrincipal principal) + public virtual Task SignInAsync(string authenticationScheme, ClaimsPrincipal principal) { + if (authenticationScheme == null) + { + throw new ArgumentNullException(nameof(authenticationScheme)); + } + + if (principal == null) + { + throw new ArgumentNullException(nameof(principal)); + } + return SignInAsync(authenticationScheme, principal, properties: null); } - public virtual Task ForbidAsync([NotNull] string authenticationScheme) + public virtual Task ForbidAsync(string authenticationScheme) { + if (authenticationScheme == null) + { + throw new ArgumentNullException(nameof(authenticationScheme)); + } + return ForbidAsync(authenticationScheme, properties: null); } // Deny access (typically a 403) - public virtual Task ForbidAsync([NotNull] string authenticationScheme, AuthenticationProperties properties) + public virtual Task ForbidAsync(string authenticationScheme, AuthenticationProperties properties) { + if (authenticationScheme == null) + { + throw new ArgumentNullException(nameof(authenticationScheme)); + } + return ChallengeAsync(authenticationScheme, properties, ChallengeBehavior.Forbidden); } - public abstract Task ChallengeAsync([NotNull] string authenticationScheme, AuthenticationProperties properties, ChallengeBehavior behavior); + public abstract Task ChallengeAsync(string authenticationScheme, AuthenticationProperties properties, ChallengeBehavior behavior); - public abstract Task SignInAsync([NotNull] string authenticationScheme, [NotNull] ClaimsPrincipal principal, AuthenticationProperties properties); + public abstract Task SignInAsync(string authenticationScheme, ClaimsPrincipal principal, AuthenticationProperties properties); - public virtual Task SignOutAsync([NotNull] string authenticationScheme) + public virtual Task SignOutAsync(string authenticationScheme) { + if (authenticationScheme == null) + { + throw new ArgumentNullException(nameof(authenticationScheme)); + } + return SignOutAsync(authenticationScheme, properties: null); } - public abstract Task SignOutAsync([NotNull] string authenticationScheme, AuthenticationProperties properties); + public abstract Task SignOutAsync(string authenticationScheme, AuthenticationProperties properties); } } diff --git a/src/Microsoft.AspNet.Http.Abstractions/Extensions/HttpResponseWritingExtensions.cs b/src/Microsoft.AspNet.Http.Abstractions/Extensions/HttpResponseWritingExtensions.cs index 896a6a11b4..953cd7ce6e 100644 --- a/src/Microsoft.AspNet.Http.Abstractions/Extensions/HttpResponseWritingExtensions.cs +++ b/src/Microsoft.AspNet.Http.Abstractions/Extensions/HttpResponseWritingExtensions.cs @@ -5,7 +5,6 @@ using System; using System.Text; using System.Threading; using System.Threading.Tasks; -using Microsoft.Framework.Internal; namespace Microsoft.AspNet.Http { @@ -21,8 +20,18 @@ namespace Microsoft.AspNet.Http /// /// /// - public static Task WriteAsync([NotNull] this HttpResponse response, [NotNull] string text, CancellationToken cancellationToken = default(CancellationToken)) + public static Task WriteAsync(this HttpResponse response, string text, CancellationToken cancellationToken = default(CancellationToken)) { + if (response == null) + { + throw new ArgumentNullException(nameof(response)); + } + + if (text == null) + { + throw new ArgumentNullException(nameof(text)); + } + return response.WriteAsync(text, Encoding.UTF8, cancellationToken); } @@ -34,8 +43,23 @@ namespace Microsoft.AspNet.Http /// /// /// - public static Task WriteAsync([NotNull] this HttpResponse response, [NotNull] string text, [NotNull] Encoding encoding, CancellationToken cancellationToken = default(CancellationToken)) + public static Task WriteAsync(this HttpResponse response, string text, Encoding encoding, CancellationToken cancellationToken = default(CancellationToken)) { + if (response == null) + { + throw new ArgumentNullException(nameof(response)); + } + + if (text == null) + { + throw new ArgumentNullException(nameof(text)); + } + + if (encoding == null) + { + throw new ArgumentNullException(nameof(encoding)); + } + byte[] data = encoding.GetBytes(text); return response.Body.WriteAsync(data, 0, data.Length, cancellationToken); } diff --git a/src/Microsoft.AspNet.Http.Abstractions/Extensions/MapExtensions.cs b/src/Microsoft.AspNet.Http.Abstractions/Extensions/MapExtensions.cs index 3af199d519..94985df589 100644 --- a/src/Microsoft.AspNet.Http.Abstractions/Extensions/MapExtensions.cs +++ b/src/Microsoft.AspNet.Http.Abstractions/Extensions/MapExtensions.cs @@ -4,7 +4,6 @@ using System; using Microsoft.AspNet.Http; using Microsoft.AspNet.Builder.Extensions; -using Microsoft.Framework.Internal; namespace Microsoft.AspNet.Builder { @@ -18,8 +17,18 @@ namespace Microsoft.AspNet.Builder /// The path to match /// The branch to take for positive path matches /// - public static IApplicationBuilder Map([NotNull] this IApplicationBuilder app, PathString pathMatch, [NotNull] Action configuration) + public static IApplicationBuilder Map(this IApplicationBuilder app, PathString pathMatch, Action configuration) { + if (app == null) + { + throw new ArgumentNullException(nameof(app)); + } + + if (configuration == null) + { + throw new ArgumentNullException(nameof(configuration)); + } + if (pathMatch.HasValue && pathMatch.Value.EndsWith("/", StringComparison.Ordinal)) { throw new ArgumentException("The path must not end with a '/'", nameof(pathMatch)); diff --git a/src/Microsoft.AspNet.Http.Abstractions/Extensions/MapMiddleware.cs b/src/Microsoft.AspNet.Http.Abstractions/Extensions/MapMiddleware.cs index 569938516d..f35e0a5480 100644 --- a/src/Microsoft.AspNet.Http.Abstractions/Extensions/MapMiddleware.cs +++ b/src/Microsoft.AspNet.Http.Abstractions/Extensions/MapMiddleware.cs @@ -1,9 +1,9 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. +using System; using System.Threading.Tasks; using Microsoft.AspNet.Http; -using Microsoft.Framework.Internal; namespace Microsoft.AspNet.Builder.Extensions { @@ -12,14 +12,29 @@ namespace Microsoft.AspNet.Builder.Extensions private readonly RequestDelegate _next; private readonly MapOptions _options; - public MapMiddleware([NotNull] RequestDelegate next, [NotNull] MapOptions options) + public MapMiddleware(RequestDelegate next, MapOptions options) { + if (next == null) + { + throw new ArgumentNullException(nameof(next)); + } + + if (options == null) + { + throw new ArgumentNullException(nameof(options)); + } + _next = next; _options = options; } - public async Task Invoke([NotNull] HttpContext context) + public async Task Invoke(HttpContext context) { + if (context == null) + { + throw new ArgumentNullException(nameof(context)); + } + PathString path = context.Request.Path; PathString remainingPath; if (path.StartsWithSegments(_options.PathMatch, out remainingPath)) diff --git a/src/Microsoft.AspNet.Http.Abstractions/Extensions/MapWhenExtensions.cs b/src/Microsoft.AspNet.Http.Abstractions/Extensions/MapWhenExtensions.cs index e3ac00274f..cabe45094d 100644 --- a/src/Microsoft.AspNet.Http.Abstractions/Extensions/MapWhenExtensions.cs +++ b/src/Microsoft.AspNet.Http.Abstractions/Extensions/MapWhenExtensions.cs @@ -2,10 +2,9 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; -using System.Threading.Tasks; using Microsoft.AspNet.Http; using Microsoft.AspNet.Builder.Extensions; -using Microsoft.Framework.Internal; + namespace Microsoft.AspNet.Builder { @@ -23,8 +22,23 @@ namespace Microsoft.AspNet.Builder /// Invoked with the request environment to determine if the branch should be taken /// Configures a branch to take /// - public static IApplicationBuilder MapWhen([NotNull] this IApplicationBuilder app, [NotNull] Predicate predicate, [NotNull] Action configuration) + public static IApplicationBuilder MapWhen(this IApplicationBuilder app, Predicate predicate, Action configuration) { + if (app == null) + { + throw new ArgumentNullException(nameof(app)); + } + + if (predicate == null) + { + throw new ArgumentNullException(nameof(predicate)); + } + + if (configuration == null) + { + throw new ArgumentNullException(nameof(configuration)); + } + // create branch var branchBuilder = app.New(); configuration(branchBuilder); diff --git a/src/Microsoft.AspNet.Http.Abstractions/Extensions/MapWhenMiddleware.cs b/src/Microsoft.AspNet.Http.Abstractions/Extensions/MapWhenMiddleware.cs index 09024a11db..b1ac27f800 100644 --- a/src/Microsoft.AspNet.Http.Abstractions/Extensions/MapWhenMiddleware.cs +++ b/src/Microsoft.AspNet.Http.Abstractions/Extensions/MapWhenMiddleware.cs @@ -1,9 +1,9 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. +using System; using System.Threading.Tasks; using Microsoft.AspNet.Http; -using Microsoft.Framework.Internal; namespace Microsoft.AspNet.Builder.Extensions { @@ -12,14 +12,29 @@ namespace Microsoft.AspNet.Builder.Extensions private readonly RequestDelegate _next; private readonly MapWhenOptions _options; - public MapWhenMiddleware([NotNull] RequestDelegate next, [NotNull] MapWhenOptions options) + public MapWhenMiddleware(RequestDelegate next, MapWhenOptions options) { + if (next == null) + { + throw new ArgumentNullException(nameof(next)); + } + + if (options == null) + { + throw new ArgumentNullException(nameof(options)); + } + _next = next; _options = options; } - public async Task Invoke([NotNull] HttpContext context) + public async Task Invoke(HttpContext context) { + if (context == null) + { + throw new ArgumentNullException(nameof(context)); + } + if (_options.Predicate(context)) { await _options.Branch(context); diff --git a/src/Microsoft.AspNet.Http.Abstractions/Extensions/MapWhenOptions.cs b/src/Microsoft.AspNet.Http.Abstractions/Extensions/MapWhenOptions.cs index dead7f4de8..aa6263366e 100644 --- a/src/Microsoft.AspNet.Http.Abstractions/Extensions/MapWhenOptions.cs +++ b/src/Microsoft.AspNet.Http.Abstractions/Extensions/MapWhenOptions.cs @@ -2,9 +2,7 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; -using System.Threading.Tasks; using Microsoft.AspNet.Http; -using Microsoft.Framework.Internal; namespace Microsoft.AspNet.Builder.Extensions { @@ -13,14 +11,26 @@ namespace Microsoft.AspNet.Builder.Extensions /// public class MapWhenOptions { + private Func _predicate; + /// /// The user callback that determines if the branch should be taken /// public Func Predicate { - get; - [param: NotNull] - set; + get + { + return _predicate; + } + set + { + if (value == null) + { + throw new ArgumentNullException(nameof(value)); + } + + _predicate = value; + } } /// diff --git a/src/Microsoft.AspNet.Http.Abstractions/Extensions/RunExtensions.cs b/src/Microsoft.AspNet.Http.Abstractions/Extensions/RunExtensions.cs index b87b2797e3..d79949c5c8 100644 --- a/src/Microsoft.AspNet.Http.Abstractions/Extensions/RunExtensions.cs +++ b/src/Microsoft.AspNet.Http.Abstractions/Extensions/RunExtensions.cs @@ -2,16 +2,23 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; -using Microsoft.AspNet.Http; -using System.Threading.Tasks; -using Microsoft.Framework.Internal; namespace Microsoft.AspNet.Builder { public static class RunExtensions { - public static void Run([NotNull] this IApplicationBuilder app, [NotNull] RequestDelegate handler) + public static void Run(this IApplicationBuilder app, RequestDelegate handler) { + if (app == null) + { + throw new ArgumentNullException(nameof(app)); + } + + if (handler == null) + { + throw new ArgumentNullException(nameof(handler)); + } + app.Use(_ => handler); } } diff --git a/src/Microsoft.AspNet.Http.Abstractions/FragmentString.cs b/src/Microsoft.AspNet.Http.Abstractions/FragmentString.cs index 794b800b63..87b22df243 100644 --- a/src/Microsoft.AspNet.Http.Abstractions/FragmentString.cs +++ b/src/Microsoft.AspNet.Http.Abstractions/FragmentString.cs @@ -2,7 +2,6 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; -using Microsoft.Framework.Internal; namespace Microsoft.AspNet.Http { @@ -91,8 +90,13 @@ namespace Microsoft.AspNet.Http /// /// The Uri object /// The resulting FragmentString - public static FragmentString FromUriComponent([NotNull] Uri uri) + public static FragmentString FromUriComponent(Uri uri) { + if (uri == null) + { + throw new ArgumentNullException(nameof(uri)); + } + string fragmentValue = uri.GetComponents(UriComponents.Fragment, UriFormat.UriEscaped); if (!string.IsNullOrEmpty(fragmentValue)) { diff --git a/src/Microsoft.AspNet.Http.Abstractions/HostString.cs b/src/Microsoft.AspNet.Http.Abstractions/HostString.cs index 15af914718..59fb4f233d 100644 --- a/src/Microsoft.AspNet.Http.Abstractions/HostString.cs +++ b/src/Microsoft.AspNet.Http.Abstractions/HostString.cs @@ -4,7 +4,6 @@ using System; using System.Diagnostics.CodeAnalysis; using System.Globalization; -using Microsoft.Framework.Internal; namespace Microsoft.AspNet.Http { @@ -135,8 +134,13 @@ namespace Microsoft.AspNet.Http /// /// /// - public static HostString FromUriComponent([NotNull] Uri uri) + public static HostString FromUriComponent(Uri uri) { + if (uri == null) + { + throw new ArgumentNullException(nameof(uri)); + } + return new HostString(uri.GetComponents( UriComponents.NormalizedHost | // Always convert punycode to Unicode. UriComponents.HostAndPort, UriFormat.Unescaped)); diff --git a/src/Microsoft.AspNet.Http.Abstractions/HttpResponse.cs b/src/Microsoft.AspNet.Http.Abstractions/HttpResponse.cs index 22c4daae06..195ef02330 100644 --- a/src/Microsoft.AspNet.Http.Abstractions/HttpResponse.cs +++ b/src/Microsoft.AspNet.Http.Abstractions/HttpResponse.cs @@ -4,7 +4,6 @@ using System; using System.IO; using System.Threading.Tasks; -using Microsoft.Framework.Internal; namespace Microsoft.AspNet.Http { @@ -33,15 +32,15 @@ namespace Microsoft.AspNet.Http public abstract bool HasStarted { get; } - public abstract void OnStarting([NotNull] Func callback, object state); + public abstract void OnStarting(Func callback, object state); - public virtual void OnStarting([NotNull] Func callback) => OnStarting(_callbackDelegate, callback); + public virtual void OnStarting(Func callback) => OnStarting(_callbackDelegate, callback); - public abstract void OnCompleted([NotNull] Func callback, object state); + public abstract void OnCompleted(Func callback, object state); - public virtual void RegisterForDispose([NotNull] IDisposable disposable) => OnCompleted(_disposeDelegate, disposable); + public virtual void RegisterForDispose(IDisposable disposable) => OnCompleted(_disposeDelegate, disposable); - public virtual void OnCompleted([NotNull] Func callback) => OnCompleted(_callbackDelegate, callback); + public virtual void OnCompleted(Func callback) => OnCompleted(_callbackDelegate, callback); public virtual void Redirect(string location) => Redirect(location, permanent: false); diff --git a/src/Microsoft.AspNet.Http.Abstractions/PathString.cs b/src/Microsoft.AspNet.Http.Abstractions/PathString.cs index 62cfd74bd6..be6422063f 100644 --- a/src/Microsoft.AspNet.Http.Abstractions/PathString.cs +++ b/src/Microsoft.AspNet.Http.Abstractions/PathString.cs @@ -3,7 +3,6 @@ using System; using System.Linq; -using Microsoft.Framework.Internal; using Microsoft.Framework.WebEncoders; namespace Microsoft.AspNet.Http @@ -88,8 +87,13 @@ namespace Microsoft.AspNet.Http /// /// The Uri object /// The resulting PathString - public static PathString FromUriComponent([NotNull] Uri uri) + public static PathString FromUriComponent(Uri uri) { + if (uri == null) + { + throw new ArgumentNullException(nameof(uri)); + } + // REVIEW: what is the exactly correct thing to do? return new PathString("/" + uri.GetComponents(UriComponents.Path, UriFormat.Unescaped)); } @@ -128,8 +132,8 @@ namespace Microsoft.AspNet.Http /// The combined PathString value public PathString Add(PathString other) { - if (HasValue && - other.HasValue && + if (HasValue && + other.HasValue && Value[Value.Length - 1] == '/') { // If the path string has a trailing slash and the other string has a leading slash, we need diff --git a/src/Microsoft.AspNet.Http.Abstractions/QueryString.cs b/src/Microsoft.AspNet.Http.Abstractions/QueryString.cs index 2844c90213..ed59879585 100644 --- a/src/Microsoft.AspNet.Http.Abstractions/QueryString.cs +++ b/src/Microsoft.AspNet.Http.Abstractions/QueryString.cs @@ -4,7 +4,6 @@ using System; using System.Collections.Generic; using System.Text; -using Microsoft.Framework.Internal; using Microsoft.Framework.Primitives; using Microsoft.Framework.WebEncoders; @@ -97,8 +96,13 @@ namespace Microsoft.AspNet.Http /// /// The Uri object /// The resulting QueryString - public static QueryString FromUriComponent([NotNull] Uri uri) + public static QueryString FromUriComponent(Uri uri) { + if (uri == null) + { + throw new ArgumentNullException(nameof(uri)); + } + string queryValue = uri.GetComponents(UriComponents.Query, UriFormat.UriEscaped); if (!string.IsNullOrEmpty(queryValue)) { diff --git a/src/Microsoft.AspNet.Http.Abstractions/project.json b/src/Microsoft.AspNet.Http.Abstractions/project.json index da09379110..3ae66b0aba 100644 --- a/src/Microsoft.AspNet.Http.Abstractions/project.json +++ b/src/Microsoft.AspNet.Http.Abstractions/project.json @@ -5,10 +5,12 @@ "type": "git", "url": "git://github.com/aspnet/httpabstractions" }, + "compilationOptions": { + "warningsAsErrors": true + }, "dependencies": { "Microsoft.AspNet.Http.Features": "1.0.0-*", "Microsoft.Framework.ActivatorUtilities.Sources": { "type": "build", "version": "1.0.0-*" }, - "Microsoft.Framework.NotNullAttribute.Sources": { "type": "build", "version": "1.0.0-*" }, "Microsoft.Framework.WebEncoders.Core": "1.0.0-*" }, "frameworks": { diff --git a/src/Microsoft.AspNet.Http.Extensions/FormFileExtensions.cs b/src/Microsoft.AspNet.Http.Extensions/FormFileExtensions.cs index e83402f101..7b13bc2ac3 100644 --- a/src/Microsoft.AspNet.Http.Extensions/FormFileExtensions.cs +++ b/src/Microsoft.AspNet.Http.Extensions/FormFileExtensions.cs @@ -1,10 +1,10 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. +using System; using System.IO; using System.Threading; using System.Threading.Tasks; -using Microsoft.Framework.Internal; namespace Microsoft.AspNet.Http { @@ -21,8 +21,13 @@ namespace Microsoft.AspNet.Http /// /// The . /// The name of the file to create. - public static void SaveAs([NotNull] this IFormFile formFile, string filename) + public static void SaveAs(this IFormFile formFile, string filename) { + if (formFile == null) + { + throw new ArgumentNullException(nameof(formFile)); + } + using (var fileStream = new FileStream(filename, FileMode.Create)) { var inputStream = formFile.OpenReadStream(); @@ -35,10 +40,15 @@ namespace Microsoft.AspNet.Http /// /// The . /// The name of the file to create. - public async static Task SaveAsAsync([NotNull] this IFormFile formFile, + public async static Task SaveAsAsync(this IFormFile formFile, string filename, CancellationToken cancellationToken = default(CancellationToken)) { + if (formFile == null) + { + throw new ArgumentNullException(nameof(formFile)); + } + using (var fileStream = new FileStream(filename, FileMode.Create)) { var inputStream = formFile.OpenReadStream(); diff --git a/src/Microsoft.AspNet.Http.Extensions/HeaderDictionaryTypeExtensions.cs b/src/Microsoft.AspNet.Http.Extensions/HeaderDictionaryTypeExtensions.cs index 803a0a5080..78bafd33bc 100644 --- a/src/Microsoft.AspNet.Http.Extensions/HeaderDictionaryTypeExtensions.cs +++ b/src/Microsoft.AspNet.Http.Extensions/HeaderDictionaryTypeExtensions.cs @@ -6,7 +6,6 @@ using System.Collections.Generic; using System.Linq; using System.Reflection; using Microsoft.AspNet.Http.Headers; -using Microsoft.Framework.Internal; using Microsoft.Framework.Primitives; using Microsoft.Net.Http.Headers; @@ -26,13 +25,33 @@ namespace Microsoft.AspNet.Http // These are all shared helpers used by both RequestHeaders and ResponseHeaders - internal static DateTimeOffset? GetDate([NotNull] this IHeaderDictionary headers, [NotNull] string name) + internal static DateTimeOffset? GetDate(this IHeaderDictionary headers, string name) { + if (headers == null) + { + throw new ArgumentNullException(nameof(headers)); + } + + if (name == null) + { + throw new ArgumentNullException(nameof(name)); + } + return headers.Get(name); } - internal static void Set([NotNull] this IHeaderDictionary headers, [NotNull] string name, object value) + internal static void Set(this IHeaderDictionary headers, string name, object value) { + if (headers == null) + { + throw new ArgumentNullException(nameof(headers)); + } + + if (name == null) + { + throw new ArgumentNullException(nameof(name)); + } + if (value == null) { headers.Remove(name); @@ -43,8 +62,18 @@ namespace Microsoft.AspNet.Http } } - internal static void SetList([NotNull] this IHeaderDictionary headers, [NotNull] string name, IList values) + internal static void SetList(this IHeaderDictionary headers, string name, IList values) { + if (headers == null) + { + throw new ArgumentNullException(nameof(headers)); + } + + if (name == null) + { + throw new ArgumentNullException(nameof(name)); + } + if (values == null || values.Count == 0) { headers.Remove(name); @@ -55,8 +84,18 @@ namespace Microsoft.AspNet.Http } } - internal static void SetDate([NotNull] this IHeaderDictionary headers, [NotNull] string name, DateTimeOffset? value) + internal static void SetDate(this IHeaderDictionary headers, string name, DateTimeOffset? value) { + if (headers == null) + { + throw new ArgumentNullException(nameof(headers)); + } + + if (name == null) + { + throw new ArgumentNullException(nameof(name)); + } + if (value.HasValue) { headers[name] = HeaderUtilities.FormatDate(value.Value); @@ -89,8 +128,13 @@ namespace Microsoft.AspNet.Http { typeof(SetCookieHeaderValue), new Func, IList>(value => { IList result; return SetCookieHeaderValue.TryParseList(value, out result) ? result : null; }) }, }; - internal static T Get([NotNull] this IHeaderDictionary headers, string name) + internal static T Get(this IHeaderDictionary headers, string name) { + if (headers == null) + { + throw new ArgumentNullException(nameof(headers)); + } + object temp; if (KnownParsers.TryGetValue(typeof(T), out temp)) { @@ -107,8 +151,13 @@ namespace Microsoft.AspNet.Http return GetViaReflection(value); } - internal static IList GetList([NotNull] this IHeaderDictionary headers, string name) + internal static IList GetList(this IHeaderDictionary headers, string name) { + if (headers == null) + { + throw new ArgumentNullException(nameof(headers)); + } + object temp; if (KnownListParsers.TryGetValue(typeof(T), out temp)) { @@ -169,11 +218,11 @@ namespace Microsoft.AspNet.Http if (string.Equals("TryParseList", methodInfo.Name, StringComparison.Ordinal) && methodInfo.ReturnParameter.ParameterType.Equals(typeof(Boolean))) { - var methodParams = methodInfo.GetParameters(); - return methodParams.Length == 2 - && methodParams[0].ParameterType.Equals(typeof(IList)) - && methodParams[1].IsOut - && methodParams[1].ParameterType.Equals(typeof(IList).MakeByRefType()); + var methodParams = methodInfo.GetParameters(); + return methodParams.Length == 2 + && methodParams[0].ParameterType.Equals(typeof(IList)) + && methodParams[1].IsOut + && methodParams[1].ParameterType.Equals(typeof(IList).MakeByRefType()); } return false; }).FirstOrDefault(); diff --git a/src/Microsoft.AspNet.Http.Extensions/Internal/HeaderSegmentCollection.cs b/src/Microsoft.AspNet.Http.Extensions/Internal/HeaderSegmentCollection.cs index 85e51f3782..d3bfe5f4cf 100644 --- a/src/Microsoft.AspNet.Http.Extensions/Internal/HeaderSegmentCollection.cs +++ b/src/Microsoft.AspNet.Http.Extensions/Internal/HeaderSegmentCollection.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Collections; using System.Collections.Generic; using Microsoft.Framework.Primitives; diff --git a/src/Microsoft.AspNet.Http.Extensions/Internal/ParsingHelpers.cs b/src/Microsoft.AspNet.Http.Extensions/Internal/ParsingHelpers.cs index 0959adbca0..93a5bfc631 100644 --- a/src/Microsoft.AspNet.Http.Extensions/Internal/ParsingHelpers.cs +++ b/src/Microsoft.AspNet.Http.Extensions/Internal/ParsingHelpers.cs @@ -2,10 +2,8 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; -using System.Collections; using System.Collections.Generic; using System.Linq; -using Microsoft.Framework.Internal; using Microsoft.Framework.Primitives; namespace Microsoft.AspNet.Http.Internal @@ -35,14 +33,24 @@ namespace Microsoft.AspNet.Http.Internal } } - public static StringValues GetHeaderUnmodified([NotNull] IDictionary headers, string key) + public static StringValues GetHeaderUnmodified(IDictionary headers, string key) { + if (headers == null) + { + throw new ArgumentNullException(nameof(headers)); + } + StringValues values; return headers.TryGetValue(key, out values) ? values : StringValues.Empty; } - public static void SetHeaderJoined([NotNull] IDictionary headers, [NotNull] string key, StringValues value) + public static void SetHeaderJoined(IDictionary headers, string key, StringValues value) { + if (headers == null) + { + throw new ArgumentNullException(nameof(headers)); + } + if (string.IsNullOrWhiteSpace(key)) { throw new ArgumentNullException(nameof(key)); @@ -89,8 +97,13 @@ namespace Microsoft.AspNet.Http.Internal return value; } - public static void SetHeaderUnmodified([NotNull] IDictionary headers, [NotNull] string key, StringValues? values) + public static void SetHeaderUnmodified(IDictionary headers, string key, StringValues? values) { + if (headers == null) + { + throw new ArgumentNullException(nameof(headers)); + } + if (string.IsNullOrWhiteSpace(key)) { throw new ArgumentNullException(nameof(key)); @@ -105,8 +118,18 @@ namespace Microsoft.AspNet.Http.Internal } } - public static void AppendHeaderJoined([NotNull] IDictionary headers, [NotNull] string key, params string[] values) + public static void AppendHeaderJoined(IDictionary headers, string key, params string[] values) { + if (headers == null) + { + throw new ArgumentNullException(nameof(headers)); + } + + if (key == null) + { + throw new ArgumentNullException(nameof(key)); + } + if (values == null || values.Length == 0) { return; @@ -123,8 +146,18 @@ namespace Microsoft.AspNet.Http.Internal } } - public static void AppendHeaderUnmodified([NotNull] IDictionary headers, [NotNull] string key, StringValues values) + public static void AppendHeaderUnmodified(IDictionary headers, string key, StringValues values) { + if (headers == null) + { + throw new ArgumentNullException(nameof(headers)); + } + + if (key == null) + { + throw new ArgumentNullException(nameof(key)); + } + if (values.Count == 0) { return; diff --git a/src/Microsoft.AspNet.Http.Extensions/Internal/StringSegment.cs b/src/Microsoft.AspNet.Http.Extensions/Internal/StringSegment.cs index 2b7fa93020..83c998421d 100644 --- a/src/Microsoft.AspNet.Http.Extensions/Internal/StringSegment.cs +++ b/src/Microsoft.AspNet.Http.Extensions/Internal/StringSegment.cs @@ -1,5 +1,4 @@ using System; -using Microsoft.Framework.Internal; namespace Microsoft.AspNet.Http.Internal { @@ -80,8 +79,13 @@ namespace Microsoft.AspNet.Http.Internal return !left.Equals(right); } - public bool StartsWith([NotNull] string text, StringComparison comparisonType) + public bool StartsWith(string text, StringComparison comparisonType) { + if (text == null) + { + throw new ArgumentNullException(nameof(text)); + } + int textLength = text.Length; if (!HasValue || _count < textLength) { @@ -91,8 +95,13 @@ namespace Microsoft.AspNet.Http.Internal return string.Compare(_buffer, _offset, text, 0, textLength, comparisonType) == 0; } - public bool EndsWith([NotNull] string text, StringComparison comparisonType) + public bool EndsWith(string text, StringComparison comparisonType) { + if (text == null) + { + throw new ArgumentNullException(nameof(text)); + } + int textLength = text.Length; if (!HasValue || _count < textLength) { @@ -102,8 +111,13 @@ namespace Microsoft.AspNet.Http.Internal return string.Compare(_buffer, _offset + _count - textLength, text, 0, textLength, comparisonType) == 0; } - public bool Equals([NotNull] string text, StringComparison comparisonType) + public bool Equals(string text, StringComparison comparisonType) { + if (text == null) + { + throw new ArgumentNullException(nameof(text)); + } + int textLength = text.Length; if (!HasValue || _count != textLength) { diff --git a/src/Microsoft.AspNet.Http.Extensions/RequestHeaders.cs b/src/Microsoft.AspNet.Http.Extensions/RequestHeaders.cs index c718ada981..efaa73fc14 100644 --- a/src/Microsoft.AspNet.Http.Extensions/RequestHeaders.cs +++ b/src/Microsoft.AspNet.Http.Extensions/RequestHeaders.cs @@ -4,15 +4,19 @@ using System; using System.Collections.Generic; using System.Linq; -using Microsoft.Framework.Internal; using Microsoft.Net.Http.Headers; namespace Microsoft.AspNet.Http.Headers { public class RequestHeaders { - public RequestHeaders([NotNull] IHeaderDictionary headers) + public RequestHeaders(IHeaderDictionary headers) { + if (headers == null) + { + throw new ArgumentNullException(nameof(headers)); + } + Headers = headers; } @@ -268,23 +272,53 @@ namespace Microsoft.AspNet.Http.Headers return Headers.GetList(name); } - public void Set([NotNull] string name, object value) + public void Set(string name, object value) { + if (name == null) + { + throw new ArgumentNullException(nameof(name)); + } + Headers.Set(name, value); } - public void SetList([NotNull] string name, IList values) + public void SetList(string name, IList values) { + if (name == null) + { + throw new ArgumentNullException(nameof(name)); + } + Headers.SetList(name, values); } - public void Append([NotNull] string name, [NotNull] object value) + public void Append(string name, object value) { + if (name == null) + { + throw new ArgumentNullException(nameof(name)); + } + + if (value == null) + { + throw new ArgumentNullException(nameof(value)); + } + Headers.Append(name, value.ToString()); } - public void AppendList([NotNull] string name, [NotNull] IList values) + public void AppendList(string name, IList values) { + if (name == null) + { + throw new ArgumentNullException(nameof(name)); + } + + if (values == null) + { + throw new ArgumentNullException(nameof(values)); + } + Headers.Append(name, values.Select(value => value.ToString()).ToArray()); } } diff --git a/src/Microsoft.AspNet.Http.Extensions/ResponseHeaders.cs b/src/Microsoft.AspNet.Http.Extensions/ResponseHeaders.cs index 7ee2bb79a5..de719d58ec 100644 --- a/src/Microsoft.AspNet.Http.Extensions/ResponseHeaders.cs +++ b/src/Microsoft.AspNet.Http.Extensions/ResponseHeaders.cs @@ -5,15 +5,19 @@ using System; using System.Collections.Generic; using System.Linq; using Microsoft.AspNet.Http.Extensions; -using Microsoft.Framework.Internal; using Microsoft.Net.Http.Headers; namespace Microsoft.AspNet.Http.Headers { public class ResponseHeaders { - public ResponseHeaders([NotNull] IHeaderDictionary headers) + public ResponseHeaders(IHeaderDictionary headers) { + if (headers == null) + { + throw new ArgumentNullException(nameof(headers)); + } + Headers = headers; } @@ -165,23 +169,53 @@ namespace Microsoft.AspNet.Http.Headers return Headers.GetList(name); } - public void Set([NotNull] string name, object value) + public void Set(string name, object value) { + if (name == null) + { + throw new ArgumentNullException(nameof(name)); + } + Headers.Set(name, value); } - public void SetList([NotNull] string name, IList values) + public void SetList(string name, IList values) { + if (name == null) + { + throw new ArgumentNullException(nameof(name)); + } + Headers.SetList(name, values); } - public void Append([NotNull] string name, [NotNull] object value) + public void Append(string name, object value) { + if (name == null) + { + throw new ArgumentNullException(nameof(name)); + } + + if (value == null) + { + throw new ArgumentNullException(nameof(value)); + } + Headers.Append(name, value.ToString()); } - public void AppendList([NotNull] string name, [NotNull] IList values) + public void AppendList(string name, IList values) { + if (name == null) + { + throw new ArgumentNullException(nameof(name)); + } + + if (values == null) + { + throw new ArgumentNullException(nameof(values)); + } + Headers.Append(name, values.Select(value => value.ToString()).ToArray()); } } diff --git a/src/Microsoft.AspNet.Http.Extensions/SendFileResponseExtensions.cs b/src/Microsoft.AspNet.Http.Extensions/SendFileResponseExtensions.cs index b60f1acad9..680c77e62c 100644 --- a/src/Microsoft.AspNet.Http.Extensions/SendFileResponseExtensions.cs +++ b/src/Microsoft.AspNet.Http.Extensions/SendFileResponseExtensions.cs @@ -6,7 +6,6 @@ using System.Threading; using System.Threading.Tasks; using Microsoft.AspNet.Http.Extensions; using Microsoft.AspNet.Http.Features; -using Microsoft.Framework.Internal; namespace Microsoft.AspNet.Http { @@ -20,8 +19,13 @@ namespace Microsoft.AspNet.Http /// /// /// True if sendfile feature exists in the response. - public static bool SupportsSendFile([NotNull] this HttpResponse response) + public static bool SupportsSendFile(this HttpResponse response) { + if (response == null) + { + throw new ArgumentNullException(nameof(response)); + } + return response.HttpContext.Features.Get() != null; } @@ -31,8 +35,18 @@ namespace Microsoft.AspNet.Http /// /// /// - public static Task SendFileAsync([NotNull] this HttpResponse response, [NotNull] string fileName) + public static Task SendFileAsync(this HttpResponse response, string fileName) { + if (response == null) + { + throw new ArgumentNullException(nameof(response)); + } + + if (fileName == null) + { + throw new ArgumentNullException(nameof(fileName)); + } + return response.SendFileAsync(fileName, 0, null, CancellationToken.None); } @@ -45,8 +59,18 @@ namespace Microsoft.AspNet.Http /// The number of types to send, or null to send the remainder of the file. /// /// - public static Task SendFileAsync([NotNull] this HttpResponse response, [NotNull] string fileName, long offset, long? count, CancellationToken cancellationToken) + public static Task SendFileAsync(this HttpResponse response, string fileName, long offset, long? count, CancellationToken cancellationToken) { + if (response == null) + { + throw new ArgumentNullException(nameof(response)); + } + + if (fileName == null) + { + throw new ArgumentNullException(nameof(fileName)); + } + var sendFile = response.HttpContext.Features.Get(); if (sendFile == null) { diff --git a/src/Microsoft.AspNet.Http.Extensions/project.json b/src/Microsoft.AspNet.Http.Extensions/project.json index 767da562d9..4ef0842096 100644 --- a/src/Microsoft.AspNet.Http.Extensions/project.json +++ b/src/Microsoft.AspNet.Http.Extensions/project.json @@ -5,9 +5,11 @@ "type": "git", "url": "git://github.com/aspnet/httpabstractions" }, - "dependencies": { + "compilationOptions": { + "warningsAsErrors": true + }, + "dependencies": { "Microsoft.AspNet.Http.Abstractions": "1.0.0-*", - "Microsoft.Framework.NotNullAttribute.Sources": { "type": "build", "version": "1.0.0-*" }, "Microsoft.Framework.WebEncoders.Core": "1.0.0-*", "Microsoft.Net.Http.Headers": "1.0.0-*" }, diff --git a/src/Microsoft.AspNet.Http.Features/Authentication/AuthenticateContext.cs b/src/Microsoft.AspNet.Http.Features/Authentication/AuthenticateContext.cs index a259ce8489..c3ef43c071 100644 --- a/src/Microsoft.AspNet.Http.Features/Authentication/AuthenticateContext.cs +++ b/src/Microsoft.AspNet.Http.Features/Authentication/AuthenticateContext.cs @@ -1,16 +1,21 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. +using System; using System.Collections.Generic; using System.Security.Claims; -using Microsoft.Framework.Internal; namespace Microsoft.AspNet.Http.Features.Authentication { public class AuthenticateContext { - public AuthenticateContext([NotNull] string authenticationScheme) + public AuthenticateContext(string authenticationScheme) { + if (authenticationScheme == null) + { + throw new ArgumentNullException(nameof(authenticationScheme)); + } + AuthenticationScheme = authenticationScheme; } diff --git a/src/Microsoft.AspNet.Http.Features/Authentication/ChallengeContext.cs b/src/Microsoft.AspNet.Http.Features/Authentication/ChallengeContext.cs index 5dfcd16914..d632a5722e 100644 --- a/src/Microsoft.AspNet.Http.Features/Authentication/ChallengeContext.cs +++ b/src/Microsoft.AspNet.Http.Features/Authentication/ChallengeContext.cs @@ -3,18 +3,23 @@ using System; using System.Collections.Generic; -using Microsoft.Framework.Internal; namespace Microsoft.AspNet.Http.Features.Authentication { public class ChallengeContext { - public ChallengeContext([NotNull] string authenticationScheme) : this(authenticationScheme, properties: null, behavior: ChallengeBehavior.Automatic) + public ChallengeContext(string authenticationScheme) + : this(authenticationScheme, properties: null, behavior: ChallengeBehavior.Automatic) { } - public ChallengeContext([NotNull] string authenticationScheme, IDictionary properties, ChallengeBehavior behavior) + public ChallengeContext(string authenticationScheme, IDictionary properties, ChallengeBehavior behavior) { + if (authenticationScheme == null) + { + throw new ArgumentNullException(nameof(authenticationScheme)); + } + AuthenticationScheme = authenticationScheme; Properties = properties ?? new Dictionary(StringComparer.Ordinal); Behavior = behavior; diff --git a/src/Microsoft.AspNet.Http.Features/Authentication/SignInContext.cs b/src/Microsoft.AspNet.Http.Features/Authentication/SignInContext.cs index 0eade92638..f4bdef8dcb 100644 --- a/src/Microsoft.AspNet.Http.Features/Authentication/SignInContext.cs +++ b/src/Microsoft.AspNet.Http.Features/Authentication/SignInContext.cs @@ -4,14 +4,23 @@ using System; using System.Collections.Generic; using System.Security.Claims; -using Microsoft.Framework.Internal; namespace Microsoft.AspNet.Http.Features.Authentication { public class SignInContext { - public SignInContext([NotNull] string authenticationScheme, [NotNull] ClaimsPrincipal principal, IDictionary properties) + public SignInContext(string authenticationScheme, ClaimsPrincipal principal, IDictionary properties) { + if (authenticationScheme == null) + { + throw new ArgumentNullException(nameof(authenticationScheme)); + } + + if (principal == null) + { + throw new ArgumentNullException(nameof(principal)); + } + AuthenticationScheme = authenticationScheme; Principal = principal; Properties = properties ?? new Dictionary(StringComparer.Ordinal); diff --git a/src/Microsoft.AspNet.Http.Features/Authentication/SignOutContext.cs b/src/Microsoft.AspNet.Http.Features/Authentication/SignOutContext.cs index d260afea84..ba27794c3e 100644 --- a/src/Microsoft.AspNet.Http.Features/Authentication/SignOutContext.cs +++ b/src/Microsoft.AspNet.Http.Features/Authentication/SignOutContext.cs @@ -3,14 +3,18 @@ using System; using System.Collections.Generic; -using Microsoft.Framework.Internal; namespace Microsoft.AspNet.Http.Features.Authentication { public class SignOutContext { - public SignOutContext([NotNull] string authenticationScheme, IDictionary properties) + public SignOutContext(string authenticationScheme, IDictionary properties) { + if (authenticationScheme == null) + { + throw new ArgumentNullException(nameof(authenticationScheme)); + } + AuthenticationScheme = authenticationScheme; Properties = properties ?? new Dictionary(StringComparer.Ordinal); } diff --git a/src/Microsoft.AspNet.Http.Features/FeatureCollection.cs b/src/Microsoft.AspNet.Http.Features/FeatureCollection.cs index 16b4d6fb44..25c86d06a9 100644 --- a/src/Microsoft.AspNet.Http.Features/FeatureCollection.cs +++ b/src/Microsoft.AspNet.Http.Features/FeatureCollection.cs @@ -5,13 +5,12 @@ using System; using System.Collections; using System.Collections.Generic; using System.Linq; -using Microsoft.Framework.Internal; namespace Microsoft.AspNet.Http.Features { public class FeatureCollection : IFeatureCollection { - private static KeyComparer FeatureKeyComparer = new FeatureCollection.KeyComparer(); + private static KeyComparer FeatureKeyComparer = new KeyComparer(); private readonly IFeatureCollection _defaults; private IDictionary _features; private volatile int _containerRevision; @@ -32,15 +31,25 @@ namespace Microsoft.AspNet.Http.Features public bool IsReadOnly { get { return false; } } - public object this[[NotNull] Type key] + public object this[Type key] { get { + if (key == null) + { + throw new ArgumentNullException(nameof(key)); + } + object result; return _features != null && _features.TryGetValue(key, out result) ? result : _defaults?[key]; } set { + if (key == null) + { + throw new ArgumentNullException(nameof(key)); + } + if (value == null) { if (_features != null && _features.Remove(key)) diff --git a/src/Microsoft.AspNet.Http.Features/IFeatureCollection.cs b/src/Microsoft.AspNet.Http.Features/IFeatureCollection.cs index ba612b10c6..59741d9394 100644 --- a/src/Microsoft.AspNet.Http.Features/IFeatureCollection.cs +++ b/src/Microsoft.AspNet.Http.Features/IFeatureCollection.cs @@ -3,7 +3,6 @@ using System; using System.Collections.Generic; -using Microsoft.Framework.Internal; namespace Microsoft.AspNet.Http.Features { @@ -24,6 +23,6 @@ namespace Microsoft.AspNet.Http.Features /// /// /// The requested feature, or null if it is not present. - object this[[NotNull] Type key] { get; set; } + object this[Type key] { get; set; } } } diff --git a/src/Microsoft.AspNet.Http.Features/project.json b/src/Microsoft.AspNet.Http.Features/project.json index b2b95c92a0..51e3cada2f 100644 --- a/src/Microsoft.AspNet.Http.Features/project.json +++ b/src/Microsoft.AspNet.Http.Features/project.json @@ -5,11 +5,10 @@ "type": "git", "url": "git://github.com/aspnet/httpabstractions" }, + "compilationOptions": { + "warningsAsErrors": true + }, "dependencies": { - "Microsoft.Framework.NotNullAttribute.Sources": { - "type": "build", - "version": "1.0.0-*" - }, "Microsoft.Framework.Primitives": "1.0.0-*" }, "frameworks": { diff --git a/src/Microsoft.AspNet.Http/Authentication/DefaultAuthenticationManager.cs b/src/Microsoft.AspNet.Http/Authentication/DefaultAuthenticationManager.cs index 821a67395a..4dcb81916c 100644 --- a/src/Microsoft.AspNet.Http/Authentication/DefaultAuthenticationManager.cs +++ b/src/Microsoft.AspNet.Http/Authentication/DefaultAuthenticationManager.cs @@ -9,7 +9,6 @@ using System.Threading.Tasks; using Microsoft.AspNet.Http.Features; using Microsoft.AspNet.Http.Features.Authentication; using Microsoft.AspNet.Http.Features.Authentication.Internal; -using Microsoft.Framework.Internal; namespace Microsoft.AspNet.Http.Authentication.Internal { @@ -47,8 +46,13 @@ namespace Microsoft.AspNet.Http.Authentication.Internal return describeContext.Results.Select(description => new AuthenticationDescription(description)); } - public override async Task AuthenticateAsync([NotNull] AuthenticateContext context) + public override async Task AuthenticateAsync(AuthenticateContext context) { + if (context == null) + { + throw new ArgumentNullException(nameof(context)); + } + var handler = HttpAuthenticationFeature.Handler; if (handler != null) @@ -62,8 +66,13 @@ namespace Microsoft.AspNet.Http.Authentication.Internal } } - public override async Task ChallengeAsync([NotNull] string authenticationScheme, AuthenticationProperties properties, ChallengeBehavior behavior) + public override async Task ChallengeAsync(string authenticationScheme, AuthenticationProperties properties, ChallengeBehavior behavior) { + if (authenticationScheme == null) + { + throw new ArgumentNullException(nameof(authenticationScheme)); + } + var handler = HttpAuthenticationFeature.Handler; var challengeContext = new ChallengeContext(authenticationScheme, properties?.Items, behavior); @@ -78,8 +87,18 @@ namespace Microsoft.AspNet.Http.Authentication.Internal } } - public override async Task SignInAsync([NotNull] string authenticationScheme, [NotNull] ClaimsPrincipal principal, AuthenticationProperties properties) + public override async Task SignInAsync(string authenticationScheme, ClaimsPrincipal principal, AuthenticationProperties properties) { + if (authenticationScheme == null) + { + throw new ArgumentNullException(nameof(authenticationScheme)); + } + + if (principal == null) + { + throw new ArgumentNullException(nameof(principal)); + } + var handler = HttpAuthenticationFeature.Handler; var signInContext = new SignInContext(authenticationScheme, principal, properties?.Items); @@ -94,8 +113,13 @@ namespace Microsoft.AspNet.Http.Authentication.Internal } } - public override async Task SignOutAsync([NotNull] string authenticationScheme, AuthenticationProperties properties) + public override async Task SignOutAsync(string authenticationScheme, AuthenticationProperties properties) { + if (authenticationScheme == null) + { + throw new ArgumentNullException(nameof(authenticationScheme)); + } + var handler = HttpAuthenticationFeature.Handler; var signOutContext = new SignOutContext(authenticationScheme, properties?.Items); diff --git a/src/Microsoft.AspNet.Http/BufferingHelper.cs b/src/Microsoft.AspNet.Http/BufferingHelper.cs index 47b08915c4..e56d73e5cf 100644 --- a/src/Microsoft.AspNet.Http/BufferingHelper.cs +++ b/src/Microsoft.AspNet.Http/BufferingHelper.cs @@ -4,7 +4,6 @@ using System; using System.IO; using Microsoft.AspNet.WebUtilities; -using Microsoft.Framework.Internal; namespace Microsoft.AspNet.Http.Internal { @@ -39,8 +38,13 @@ namespace Microsoft.AspNet.Http.Internal } } - public static HttpRequest EnableRewind([NotNull] this HttpRequest request, int bufferThreshold = DefaultBufferThreshold) + public static HttpRequest EnableRewind(this HttpRequest request, int bufferThreshold = DefaultBufferThreshold) { + if (request == null) + { + throw new ArgumentNullException(nameof(request)); + } + var body = request.Body; if (!body.CanSeek) { diff --git a/src/Microsoft.AspNet.Http/DefaultHttpResponse.cs b/src/Microsoft.AspNet.Http/DefaultHttpResponse.cs index b47279bfd8..e5f09f7ca2 100644 --- a/src/Microsoft.AspNet.Http/DefaultHttpResponse.cs +++ b/src/Microsoft.AspNet.Http/DefaultHttpResponse.cs @@ -95,11 +95,21 @@ namespace Microsoft.AspNet.Http.Internal public override void OnStarting(Func callback, object state) { + if (callback == null) + { + throw new ArgumentNullException(nameof(callback)); + } + HttpResponseFeature.OnStarting(callback, state); } public override void OnCompleted(Func callback, object state) { + if (callback == null) + { + throw new ArgumentNullException(nameof(callback)); + } + HttpResponseFeature.OnCompleted(callback, state); } diff --git a/src/Microsoft.AspNet.Http/Features/FormFeature.cs b/src/Microsoft.AspNet.Http/Features/FormFeature.cs index 48819224dd..6d6ff1d012 100644 --- a/src/Microsoft.AspNet.Http/Features/FormFeature.cs +++ b/src/Microsoft.AspNet.Http/Features/FormFeature.cs @@ -9,7 +9,6 @@ using System.Threading; using System.Threading.Tasks; using Microsoft.AspNet.Http.Internal; using Microsoft.AspNet.WebUtilities; -using Microsoft.Framework.Internal; using Microsoft.Framework.Primitives; using Microsoft.Net.Http.Headers; @@ -19,13 +18,23 @@ namespace Microsoft.AspNet.Http.Features.Internal { private readonly HttpRequest _request; - public FormFeature([NotNull] IFormCollection form) + public FormFeature(IFormCollection form) { + if (form == null) + { + throw new ArgumentNullException(nameof(form)); + } + Form = form; } - public FormFeature([NotNull] HttpRequest request) + public FormFeature(HttpRequest request) { + if (request == null) + { + throw new ArgumentNullException(nameof(request)); + } + _request = request; } diff --git a/src/Microsoft.AspNet.Http/Features/QueryFeature.cs b/src/Microsoft.AspNet.Http/Features/QueryFeature.cs index 39c842b83e..5dd7ca9163 100644 --- a/src/Microsoft.AspNet.Http/Features/QueryFeature.cs +++ b/src/Microsoft.AspNet.Http/Features/QueryFeature.cs @@ -5,7 +5,6 @@ using System; using System.Collections.Generic; using Microsoft.AspNet.Http.Internal; using Microsoft.AspNet.WebUtilities; -using Microsoft.Framework.Internal; using Microsoft.Framework.Primitives; namespace Microsoft.AspNet.Http.Features.Internal @@ -18,18 +17,32 @@ namespace Microsoft.AspNet.Http.Features.Internal private string _original; private IReadableStringCollection _parsedValues; - public QueryFeature([NotNull] IDictionary query) + public QueryFeature(IDictionary query) : this(new ReadableStringCollection(query)) { + if (query == null) + { + throw new ArgumentNullException(nameof(query)); + } } - public QueryFeature([NotNull] IReadableStringCollection query) + public QueryFeature(IReadableStringCollection query) { + if (query == null) + { + throw new ArgumentNullException(nameof(query)); + } + _parsedValues = query; } - public QueryFeature([NotNull] IFeatureCollection features) + public QueryFeature(IFeatureCollection features) { + if (features == null) + { + throw new ArgumentNullException(nameof(features)); + } + _features = features; } diff --git a/src/Microsoft.AspNet.Http/Features/RequestCookiesFeature.cs b/src/Microsoft.AspNet.Http/Features/RequestCookiesFeature.cs index cc0a9df3ed..0eb44ef102 100644 --- a/src/Microsoft.AspNet.Http/Features/RequestCookiesFeature.cs +++ b/src/Microsoft.AspNet.Http/Features/RequestCookiesFeature.cs @@ -5,7 +5,6 @@ using System; using System.Collections.Generic; using System.Linq; using Microsoft.AspNet.Http.Internal; -using Microsoft.Framework.Internal; using Microsoft.Framework.Primitives; using Microsoft.Net.Http.Headers; @@ -19,18 +18,28 @@ namespace Microsoft.AspNet.Http.Features.Internal private StringValues _original; private IReadableStringCollection _parsedValues; - public RequestCookiesFeature([NotNull] IDictionary cookies) + public RequestCookiesFeature(IDictionary cookies) : this(new ReadableStringCollection(cookies)) { } - public RequestCookiesFeature([NotNull] IReadableStringCollection cookies) + public RequestCookiesFeature(IReadableStringCollection cookies) { + if (cookies == null) + { + throw new ArgumentNullException(nameof(cookies)); + } + _parsedValues = cookies; } - public RequestCookiesFeature([NotNull] IFeatureCollection features) + public RequestCookiesFeature(IFeatureCollection features) { + if (features == null) + { + throw new ArgumentNullException(nameof(features)); + } + _features = features; } diff --git a/src/Microsoft.AspNet.Http/FormCollection.cs b/src/Microsoft.AspNet.Http/FormCollection.cs index 15de4dee62..550ad933eb 100644 --- a/src/Microsoft.AspNet.Http/FormCollection.cs +++ b/src/Microsoft.AspNet.Http/FormCollection.cs @@ -1,8 +1,8 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. +using System; using System.Collections.Generic; -using Microsoft.Framework.Internal; using Microsoft.Framework.Primitives; namespace Microsoft.AspNet.Http.Internal @@ -12,17 +12,27 @@ namespace Microsoft.AspNet.Http.Internal /// public class FormCollection : ReadableStringCollection, IFormCollection { - public FormCollection([NotNull] IDictionary store) + public FormCollection(IDictionary store) : this(store, new FormFileCollection()) { } - public FormCollection([NotNull] IDictionary store, [NotNull] IFormFileCollection files) + public FormCollection(IDictionary store, IFormFileCollection files) : base(store) { + if (store == null) + { + throw new ArgumentNullException(nameof(store)); + } + + if (files == null) + { + throw new ArgumentNullException(nameof(files)); + } + Files = files; } - public IFormFileCollection Files { get; private set; } + public IFormFileCollection Files { get; } } } diff --git a/src/Microsoft.AspNet.Http/HeaderDictionary.cs b/src/Microsoft.AspNet.Http/HeaderDictionary.cs index 05d5d7fdf4..20b520b783 100644 --- a/src/Microsoft.AspNet.Http/HeaderDictionary.cs +++ b/src/Microsoft.AspNet.Http/HeaderDictionary.cs @@ -4,7 +4,6 @@ using System; using System.Collections; using System.Collections.Generic; -using Microsoft.Framework.Internal; using Microsoft.Framework.Primitives; namespace Microsoft.AspNet.Http.Internal @@ -22,8 +21,13 @@ namespace Microsoft.AspNet.Http.Internal /// Initializes a new instance of the class. /// /// The underlying data store. - public HeaderDictionary([NotNull] IDictionary store) + public HeaderDictionary(IDictionary store) { + if (store == null) + { + throw new ArgumentNullException(nameof(store)); + } + Store = store; } diff --git a/src/Microsoft.AspNet.Http/ParsingHelpers.cs b/src/Microsoft.AspNet.Http/ParsingHelpers.cs index 54455b90b3..6bf5a57ae6 100644 --- a/src/Microsoft.AspNet.Http/ParsingHelpers.cs +++ b/src/Microsoft.AspNet.Http/ParsingHelpers.cs @@ -6,7 +6,6 @@ using System.Collections; using System.Collections.Generic; using System.Globalization; using System.Linq; -using Microsoft.Framework.Internal; using Microsoft.Framework.Primitives; using Microsoft.Net.Http.Headers; @@ -444,8 +443,13 @@ namespace Microsoft.AspNet.Http.Internal #endregion - public bool StartsWith([NotNull] string text, StringComparison comparisonType) + public bool StartsWith(string text, StringComparison comparisonType) { + if (text == null) + { + throw new ArgumentNullException(nameof(text)); + } + int textLength = text.Length; if (!HasValue || _count < textLength) { @@ -455,8 +459,13 @@ namespace Microsoft.AspNet.Http.Internal return string.Compare(_buffer, _offset, text, 0, textLength, comparisonType) == 0; } - public bool EndsWith([NotNull] string text, StringComparison comparisonType) + public bool EndsWith(string text, StringComparison comparisonType) { + if (text == null) + { + throw new ArgumentNullException(nameof(text)); + } + int textLength = text.Length; if (!HasValue || _count < textLength) { @@ -466,8 +475,13 @@ namespace Microsoft.AspNet.Http.Internal return string.Compare(_buffer, _offset + _count - textLength, text, 0, textLength, comparisonType) == 0; } - public bool Equals([NotNull] string text, StringComparison comparisonType) + public bool Equals(string text, StringComparison comparisonType) { + if (text == null) + { + throw new ArgumentNullException(nameof(text)); + } + int textLength = text.Length; if (!HasValue || _count != textLength) { @@ -518,14 +532,29 @@ namespace Microsoft.AspNet.Http.Internal } } - public static StringValues GetHeaderUnmodified([NotNull] IDictionary headers, string key) + public static StringValues GetHeaderUnmodified(IDictionary headers, string key) { + if (headers == null) + { + throw new ArgumentNullException(nameof(headers)); + } + StringValues values; return headers.TryGetValue(key, out values) ? values : StringValues.Empty; } - public static void SetHeader([NotNull] IDictionary headers, [NotNull] string key, StringValues value) + public static void SetHeader(IDictionary headers, string key, StringValues value) { + if (headers == null) + { + throw new ArgumentNullException(nameof(headers)); + } + + if (key == null) + { + throw new ArgumentNullException(nameof(key)); + } + if (string.IsNullOrWhiteSpace(key)) { throw new ArgumentNullException(nameof(key)); @@ -554,8 +583,13 @@ namespace Microsoft.AspNet.Http.Internal return value; } - public static long? GetContentLength([NotNull] IHeaderDictionary headers) + public static long? GetContentLength(IHeaderDictionary headers) { + if (headers == null) + { + throw new ArgumentNullException(nameof(headers)); + } + const NumberStyles styles = NumberStyles.AllowLeadingWhite | NumberStyles.AllowTrailingWhite; long value; var rawValue = headers[HeaderNames.ContentLength]; @@ -569,8 +603,13 @@ namespace Microsoft.AspNet.Http.Internal return null; } - public static void SetContentLength([NotNull] IHeaderDictionary headers, long? value) + public static void SetContentLength(IHeaderDictionary headers, long? value) { + if (headers == null) + { + throw new ArgumentNullException(nameof(headers)); + } + if (value.HasValue) { headers[HeaderNames.ContentLength] = value.Value.ToString(CultureInfo.InvariantCulture); diff --git a/src/Microsoft.AspNet.Http/ReadableStringCollection.cs b/src/Microsoft.AspNet.Http/ReadableStringCollection.cs index 962804b723..c1ed5d910e 100644 --- a/src/Microsoft.AspNet.Http/ReadableStringCollection.cs +++ b/src/Microsoft.AspNet.Http/ReadableStringCollection.cs @@ -1,9 +1,9 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. +using System; using System.Collections; using System.Collections.Generic; -using Microsoft.Framework.Internal; using Microsoft.Framework.Primitives; namespace Microsoft.AspNet.Http.Internal @@ -19,8 +19,13 @@ namespace Microsoft.AspNet.Http.Internal /// Create a new wrapper /// /// - public ReadableStringCollection([NotNull] IDictionary store) + public ReadableStringCollection(IDictionary store) { + if (store == null) + { + throw new ArgumentNullException(nameof(store)); + } + Store = store; } diff --git a/src/Microsoft.AspNet.Http/ReferenceReadStream.cs b/src/Microsoft.AspNet.Http/ReferenceReadStream.cs index 87f2959eef..509a6e44cd 100644 --- a/src/Microsoft.AspNet.Http/ReferenceReadStream.cs +++ b/src/Microsoft.AspNet.Http/ReferenceReadStream.cs @@ -5,7 +5,6 @@ using System; using System.IO; using System.Threading; using System.Threading.Tasks; -using Microsoft.Framework.Internal; namespace Microsoft.AspNet.Http.Internal { @@ -21,8 +20,13 @@ namespace Microsoft.AspNet.Http.Internal private bool _disposed; - public ReferenceReadStream([NotNull] Stream inner, long offset, long length) + public ReferenceReadStream(Stream inner, long offset, long length) { + if (inner == null) + { + throw new ArgumentNullException(nameof(inner)); + } + _inner = inner; _innerOffset = offset; _length = length; diff --git a/src/Microsoft.AspNet.Http/ResponseCookies.cs b/src/Microsoft.AspNet.Http/ResponseCookies.cs index 7ead5dcc91..c4db554c47 100644 --- a/src/Microsoft.AspNet.Http/ResponseCookies.cs +++ b/src/Microsoft.AspNet.Http/ResponseCookies.cs @@ -3,7 +3,6 @@ using System; using System.Linq; -using Microsoft.Framework.Internal; using Microsoft.Framework.Primitives; using Microsoft.Framework.WebEncoders; using Microsoft.Net.Http.Headers; @@ -19,8 +18,13 @@ namespace Microsoft.AspNet.Http.Internal /// Create a new wrapper /// /// - public ResponseCookies([NotNull] IHeaderDictionary headers) + public ResponseCookies(IHeaderDictionary headers) { + if (headers == null) + { + throw new ArgumentNullException(nameof(headers)); + } + Headers = headers; } @@ -49,8 +53,13 @@ namespace Microsoft.AspNet.Http.Internal /// /// /// - public void Append(string key, string value, [NotNull] CookieOptions options) + public void Append(string key, string value, CookieOptions options) { + if (options == null) + { + throw new ArgumentNullException(nameof(options)); + } + var setCookieHeaderValue = new SetCookieHeaderValue( UrlEncoder.Default.UrlEncode(key), UrlEncoder.Default.UrlEncode(value)) @@ -91,8 +100,13 @@ namespace Microsoft.AspNet.Http.Internal /// /// /// - public void Delete(string key, [NotNull] CookieOptions options) + public void Delete(string key, CookieOptions options) { + if (options == null) + { + throw new ArgumentNullException(nameof(options)); + } + var encodedKeyPlusEquals = UrlEncoder.Default.UrlEncode(key) + "="; bool domainHasValue = !string.IsNullOrEmpty(options.Domain); bool pathHasValue = !string.IsNullOrEmpty(options.Path); diff --git a/src/Microsoft.AspNet.Http/project.json b/src/Microsoft.AspNet.Http/project.json index 53e3ece572..27cb110745 100644 --- a/src/Microsoft.AspNet.Http/project.json +++ b/src/Microsoft.AspNet.Http/project.json @@ -5,10 +5,12 @@ "type": "git", "url": "git://github.com/aspnet/httpabstractions" }, + "compilationOptions": { + "warningsAsErrors": true + }, "dependencies": { "Microsoft.AspNet.Http.Abstractions": "1.0.0-*", "Microsoft.AspNet.WebUtilities": "1.0.0-*", - "Microsoft.Framework.NotNullAttribute.Sources": { "type": "build", "version": "1.0.0-*" }, "Microsoft.Net.Http.Headers": "1.0.0-*" }, "frameworks": { diff --git a/src/Microsoft.AspNet.Owin/project.json b/src/Microsoft.AspNet.Owin/project.json index 7a496619ae..a20dd5ccff 100644 --- a/src/Microsoft.AspNet.Owin/project.json +++ b/src/Microsoft.AspNet.Owin/project.json @@ -5,9 +5,11 @@ "type": "git", "url": "git://github.com/aspnet/httpabstractions" }, + "compilationOptions": { + "warningsAsErrors": true + }, "dependencies": { - "Microsoft.AspNet.Http": "1.0.0-*", - "Microsoft.Framework.NotNullAttribute.Sources": { "type": "build", "version": "1.0.0-*" } + "Microsoft.AspNet.Http": "1.0.0-*" }, "frameworks": { "dnx451": { }, diff --git a/src/Microsoft.AspNet.WebUtilities/BufferedReadStream.cs b/src/Microsoft.AspNet.WebUtilities/BufferedReadStream.cs index 94bb03efce..88e2782938 100644 --- a/src/Microsoft.AspNet.WebUtilities/BufferedReadStream.cs +++ b/src/Microsoft.AspNet.WebUtilities/BufferedReadStream.cs @@ -6,7 +6,6 @@ using System.IO; using System.Text; using System.Threading; using System.Threading.Tasks; -using Microsoft.Framework.Internal; namespace Microsoft.AspNet.WebUtilities { @@ -21,8 +20,13 @@ namespace Microsoft.AspNet.WebUtilities private int _bufferCount = 0; private bool _disposed; - public BufferedReadStream([NotNull] Stream inner, int bufferSize) + public BufferedReadStream(Stream inner, int bufferSize) { + if (inner == null) + { + throw new ArgumentNullException(nameof(inner)); + } + _inner = inner; _buffer = new byte[bufferSize]; } diff --git a/src/Microsoft.AspNet.WebUtilities/FileBufferingReadStream.cs b/src/Microsoft.AspNet.WebUtilities/FileBufferingReadStream.cs index 9bed427578..3341b65857 100644 --- a/src/Microsoft.AspNet.WebUtilities/FileBufferingReadStream.cs +++ b/src/Microsoft.AspNet.WebUtilities/FileBufferingReadStream.cs @@ -6,7 +6,6 @@ using System.Diagnostics; using System.IO; using System.Threading; using System.Threading.Tasks; -using Microsoft.Framework.Internal; namespace Microsoft.AspNet.WebUtilities { @@ -30,18 +29,38 @@ namespace Microsoft.AspNet.WebUtilities // TODO: allow for an optional buffer size limit to prevent filling hard disks. 1gb? public FileBufferingReadStream( - [NotNull] Stream inner, + Stream inner, int memoryThreshold, - [NotNull] Func tempFileDirectoryAccessor) + Func tempFileDirectoryAccessor) { + if (inner == null) + { + throw new ArgumentNullException(nameof(inner)); + } + + if (tempFileDirectoryAccessor == null) + { + throw new ArgumentNullException(nameof(tempFileDirectoryAccessor)); + } + _inner = inner; _memoryThreshold = memoryThreshold; _tempFileDirectoryAccessor = tempFileDirectoryAccessor; } // TODO: allow for an optional buffer size limit to prevent filling hard disks. 1gb? - public FileBufferingReadStream([NotNull] Stream inner, int memoryThreshold, [NotNull] string tempFileDirectory) + public FileBufferingReadStream(Stream inner, int memoryThreshold, string tempFileDirectory) { + if (inner == null) + { + throw new ArgumentNullException(nameof(inner)); + } + + if (tempFileDirectory == null) + { + throw new ArgumentNullException(nameof(tempFileDirectory)); + } + _inner = inner; _memoryThreshold = memoryThreshold; _tempFileDirectory = tempFileDirectory; diff --git a/src/Microsoft.AspNet.WebUtilities/FormReader.cs b/src/Microsoft.AspNet.WebUtilities/FormReader.cs index e475522646..d4e36264de 100644 --- a/src/Microsoft.AspNet.WebUtilities/FormReader.cs +++ b/src/Microsoft.AspNet.WebUtilities/FormReader.cs @@ -7,7 +7,6 @@ using System.IO; using System.Text; using System.Threading; using System.Threading.Tasks; -using Microsoft.Framework.Internal; using Microsoft.Framework.Primitives; namespace Microsoft.AspNet.WebUtilities @@ -23,13 +22,28 @@ namespace Microsoft.AspNet.WebUtilities private int _bufferOffset; private int _bufferCount; - public FormReader([NotNull] string data) + public FormReader(string data) { + if (data == null) + { + throw new ArgumentNullException(nameof(data)); + } + _reader = new StringReader(data); } - public FormReader([NotNull] Stream stream, [NotNull] Encoding encoding) + public FormReader(Stream stream, Encoding encoding) { + if (stream == null) + { + throw new ArgumentNullException(nameof(stream)); + } + + if (encoding == null) + { + throw new ArgumentNullException(nameof(encoding)); + } + _reader = new StreamReader(stream, encoding, detectEncodingFromByteOrderMarks: true, bufferSize: 1024 * 2, leaveOpen: true); } @@ -160,7 +174,7 @@ namespace Microsoft.AspNet.WebUtilities while (pair.HasValue) { accumulator.Append(pair.Value.Key, pair.Value.Value); - pair = reader.ReadNextPair(); + pair = reader.ReadNextPair(); } return accumulator.GetResults(); diff --git a/src/Microsoft.AspNet.WebUtilities/MultipartReader.cs b/src/Microsoft.AspNet.WebUtilities/MultipartReader.cs index 631908173b..8c87e5db52 100644 --- a/src/Microsoft.AspNet.WebUtilities/MultipartReader.cs +++ b/src/Microsoft.AspNet.WebUtilities/MultipartReader.cs @@ -7,7 +7,6 @@ using System.Diagnostics; using System.IO; using System.Threading; using System.Threading.Tasks; -using Microsoft.Framework.Internal; using Microsoft.Framework.Primitives; namespace Microsoft.AspNet.WebUtilities @@ -21,13 +20,23 @@ namespace Microsoft.AspNet.WebUtilities private readonly string _boundary; private MultipartReaderStream _currentStream; - public MultipartReader([NotNull] string boundary, [NotNull] Stream stream) + public MultipartReader(string boundary, Stream stream) : this(boundary, stream, DefaultBufferSize) { } - public MultipartReader([NotNull] string boundary, [NotNull] Stream stream, int bufferSize) + public MultipartReader(string boundary, Stream stream, int bufferSize) { + if (boundary == null) + { + throw new ArgumentNullException(nameof(boundary)); + } + + if (stream == null) + { + throw new ArgumentNullException(nameof(stream)); + } + if (bufferSize < boundary.Length + 8) // Size of the boundary + leading and trailing CRLF + leading and trailing '--' markers. { throw new ArgumentOutOfRangeException(nameof(bufferSize), bufferSize, "Insufficient buffer space, the buffer must be larger than the boundary: " + boundary); diff --git a/src/Microsoft.AspNet.WebUtilities/MultipartReaderStream.cs b/src/Microsoft.AspNet.WebUtilities/MultipartReaderStream.cs index 5e3059280d..9350233c83 100644 --- a/src/Microsoft.AspNet.WebUtilities/MultipartReaderStream.cs +++ b/src/Microsoft.AspNet.WebUtilities/MultipartReaderStream.cs @@ -7,7 +7,6 @@ using System.IO; using System.Text; using System.Threading; using System.Threading.Tasks; -using Microsoft.Framework.Internal; namespace Microsoft.AspNet.WebUtilities { @@ -26,8 +25,18 @@ namespace Microsoft.AspNet.WebUtilities /// /// /// - public MultipartReaderStream([NotNull] BufferedReadStream stream, [NotNull] string boundary, bool expectLeadingCrlf = true) + public MultipartReaderStream(BufferedReadStream stream, string boundary, bool expectLeadingCrlf = true) { + if (stream == null) + { + throw new ArgumentNullException(nameof(stream)); + } + + if (boundary == null) + { + throw new ArgumentNullException(nameof(boundary)); + } + _innerStream = stream; _innerOffset = _innerStream.CanSeek ? _innerStream.Position : 0; if (expectLeadingCrlf) diff --git a/src/Microsoft.AspNet.WebUtilities/QueryHelpers.cs b/src/Microsoft.AspNet.WebUtilities/QueryHelpers.cs index 13cd1f4051..17022d0b2d 100644 --- a/src/Microsoft.AspNet.WebUtilities/QueryHelpers.cs +++ b/src/Microsoft.AspNet.WebUtilities/QueryHelpers.cs @@ -4,7 +4,6 @@ using System; using System.Collections.Generic; using System.Text; -using Microsoft.Framework.Internal; using Microsoft.Framework.Primitives; using Microsoft.Framework.WebEncoders; @@ -19,10 +18,25 @@ namespace Microsoft.AspNet.WebUtilities /// The name of the query key. /// The query value. /// The combined result. - public static string AddQueryString([NotNull] string uri, [NotNull] string name, [NotNull] string value) + public static string AddQueryString(string uri, string name, string value) { + if (uri == null) + { + throw new ArgumentNullException(nameof(uri)); + } + + if (name == null) + { + throw new ArgumentNullException(nameof(name)); + } + + if (value == null) + { + throw new ArgumentNullException(nameof(value)); + } + return AddQueryString( - uri, new [] { new KeyValuePair(name, value) }); + uri, new[] { new KeyValuePair(name, value) }); } /// @@ -31,15 +45,35 @@ namespace Microsoft.AspNet.WebUtilities /// The base uri. /// A collection of name value query pairs to append. /// The combined result. - public static string AddQueryString([NotNull] string uri, [NotNull] IDictionary queryString) + public static string AddQueryString(string uri, IDictionary queryString) { + if (uri == null) + { + throw new ArgumentNullException(nameof(uri)); + } + + if (queryString == null) + { + throw new ArgumentNullException(nameof(queryString)); + } + return AddQueryString(uri, (IEnumerable>)queryString); } private static string AddQueryString( - [NotNull] string uri, - [NotNull] IEnumerable> queryString) + string uri, + IEnumerable> queryString) { + if (uri == null) + { + throw new ArgumentNullException(nameof(uri)); + } + + if (queryString == null) + { + throw new ArgumentNullException(nameof(queryString)); + } + var anchorIndex = uri.IndexOf('#'); var uriToBeAppended = uri; var anchorText = ""; diff --git a/src/Microsoft.AspNet.WebUtilities/WebEncoders.cs b/src/Microsoft.AspNet.WebUtilities/WebEncoders.cs index 132f106e07..751ad43c21 100644 --- a/src/Microsoft.AspNet.WebUtilities/WebEncoders.cs +++ b/src/Microsoft.AspNet.WebUtilities/WebEncoders.cs @@ -3,7 +3,6 @@ using System; using System.Diagnostics; -using Microsoft.Framework.Internal; namespace Microsoft.AspNet.WebUtilities { @@ -21,8 +20,13 @@ namespace Microsoft.AspNet.WebUtilities /// The input must not contain any whitespace or padding characters. /// Throws FormatException if the input is malformed. /// - public static byte[] Base64UrlDecode([NotNull] string input) + public static byte[] Base64UrlDecode(string input) { + if (input == null) + { + throw new ArgumentNullException(nameof(input)); + } + return Base64UrlDecode(input, 0, input.Length); } @@ -37,8 +41,13 @@ namespace Microsoft.AspNet.WebUtilities /// The input must not contain any whitespace or padding characters. /// Throws FormatException if the input is malformed. /// - public static byte[] Base64UrlDecode([NotNull] string input, int offset, int count) + public static byte[] Base64UrlDecode(string input, int offset, int count) { + if (input == null) + { + throw new ArgumentNullException(nameof(input)); + } + ValidateParameters(input.Length, offset, count); // Special-case empty input @@ -83,8 +92,13 @@ namespace Microsoft.AspNet.WebUtilities /// /// The binary input to encode. /// The base64url-encoded form of the input. - public static string Base64UrlEncode([NotNull] byte[] input) + public static string Base64UrlEncode(byte[] input) { + if (input == null) + { + throw new ArgumentNullException(nameof(input)); + } + return Base64UrlEncode(input, 0, input.Length); } @@ -95,8 +109,13 @@ namespace Microsoft.AspNet.WebUtilities /// The offset into at which to begin encoding. /// The number of bytes of to encode. /// The base64url-encoded form of the input. - public static string Base64UrlEncode([NotNull] byte[] input, int offset, int count) + public static string Base64UrlEncode(byte[] input, int offset, int count) { + if (input == null) + { + throw new ArgumentNullException(nameof(input)); + } + ValidateParameters(input.Length, offset, count); // Special-case empty input diff --git a/src/Microsoft.AspNet.WebUtilities/project.json b/src/Microsoft.AspNet.WebUtilities/project.json index 4aa7a07c04..621e8c5954 100644 --- a/src/Microsoft.AspNet.WebUtilities/project.json +++ b/src/Microsoft.AspNet.WebUtilities/project.json @@ -5,8 +5,10 @@ "type": "git", "url": "git://github.com/aspnet/httpabstractions" }, + "compilationOptions": { + "warningsAsErrors": true + }, "dependencies": { - "Microsoft.Framework.NotNullAttribute.Sources": { "type": "build", "version": "1.0.0-*" }, "Microsoft.Framework.Primitives": "1.0.0-*", "Microsoft.Framework.WebEncoders.Core": "1.0.0-*" }, diff --git a/src/Microsoft.Framework.Primitives/project.json b/src/Microsoft.Framework.Primitives/project.json index c504f822d2..4957eeb224 100644 --- a/src/Microsoft.Framework.Primitives/project.json +++ b/src/Microsoft.Framework.Primitives/project.json @@ -5,11 +5,8 @@ "type": "git", "url": "git://github.com/aspnet/httpabstractions" }, - "dependencies": { - "Microsoft.Framework.NotNullAttribute.Sources": { - "type": "build", - "version": "1.0.0-*" - } + "compilationOptions": { + "warningsAsErrors": true }, "frameworks": { "net451": { }, diff --git a/src/Microsoft.Framework.WebEncoders.Core/CodePointFilter.cs b/src/Microsoft.Framework.WebEncoders.Core/CodePointFilter.cs index a5d5b21c3a..8858c2df17 100644 --- a/src/Microsoft.Framework.WebEncoders.Core/CodePointFilter.cs +++ b/src/Microsoft.Framework.WebEncoders.Core/CodePointFilter.cs @@ -3,7 +3,6 @@ using System; using System.Collections.Generic; -using Microsoft.Framework.Internal; namespace Microsoft.Framework.WebEncoders { @@ -25,8 +24,13 @@ namespace Microsoft.Framework.WebEncoders /// /// Instantiates the filter by cloning the allow list of another . /// - public CodePointFilter([NotNull] ICodePointFilter other) + public CodePointFilter(ICodePointFilter other) { + if (other == null) + { + throw new ArgumentNullException(nameof(other)); + } + CodePointFilter otherAsCodePointFilter = other as CodePointFilter; if (otherAsCodePointFilter != null) { @@ -85,8 +89,13 @@ namespace Microsoft.Framework.WebEncoders /// /// The 'this' instance. /// - public CodePointFilter AllowChars([NotNull] string chars) + public CodePointFilter AllowChars(string chars) { + if (chars == null) + { + throw new ArgumentNullException(nameof(chars)); + } + for (int i = 0; i < chars.Length; i++) { _allowedCharsBitmap.AllowCharacter(chars[i]); @@ -100,8 +109,13 @@ namespace Microsoft.Framework.WebEncoders /// /// The 'this' instance. /// - public CodePointFilter AllowFilter([NotNull] ICodePointFilter filter) + public CodePointFilter AllowFilter(ICodePointFilter filter) { + if (filter == null) + { + throw new ArgumentNullException(nameof(filter)); + } + foreach (var allowedCodePoint in filter.GetAllowedCodePoints()) { // If the code point can't be represented as a BMP character, skip it. @@ -120,8 +134,13 @@ namespace Microsoft.Framework.WebEncoders /// /// The 'this' instance. /// - public CodePointFilter AllowRange([NotNull] UnicodeRange range) + public CodePointFilter AllowRange(UnicodeRange range) { + if (range == null) + { + throw new ArgumentNullException(nameof(range)); + } + int firstCodePoint = range.FirstCodePoint; int rangeSize = range.RangeSize; for (int i = 0; i < rangeSize; i++) @@ -197,8 +216,13 @@ namespace Microsoft.Framework.WebEncoders /// /// The 'this' instance. /// - public CodePointFilter ForbidChars([NotNull] string chars) + public CodePointFilter ForbidChars(string chars) { + if (chars == null) + { + throw new ArgumentNullException(nameof(chars)); + } + for (int i = 0; i < chars.Length; i++) { _allowedCharsBitmap.ForbidCharacter(chars[i]); @@ -212,8 +236,13 @@ namespace Microsoft.Framework.WebEncoders /// /// The 'this' instance. /// - public CodePointFilter ForbidRange([NotNull] UnicodeRange range) + public CodePointFilter ForbidRange(UnicodeRange range) { + if (range == null) + { + throw new ArgumentNullException(nameof(range)); + } + int firstCodePoint = range.FirstCodePoint; int rangeSize = range.RangeSize; for (int i = 0; i < rangeSize; i++) diff --git a/src/Microsoft.Framework.WebEncoders.Core/HtmlEncoder.cs b/src/Microsoft.Framework.WebEncoders.Core/HtmlEncoder.cs index 68b492f55a..5a0553e782 100644 --- a/src/Microsoft.Framework.WebEncoders.Core/HtmlEncoder.cs +++ b/src/Microsoft.Framework.WebEncoders.Core/HtmlEncoder.cs @@ -6,7 +6,6 @@ using System.Diagnostics; using System.IO; using System.Runtime.CompilerServices; using System.Threading; -using Microsoft.Framework.Internal; namespace Microsoft.Framework.WebEncoders { @@ -51,9 +50,13 @@ namespace Microsoft.Framework.WebEncoders /// set returned by 's /// method will be escaped. /// - public HtmlEncoder([NotNull] ICodePointFilter filter) + public HtmlEncoder(ICodePointFilter filter) : this(new HtmlUnicodeEncoder(CodePointFilter.Wrap(filter))) { + if (filter == null) + { + throw new ArgumentNullException(nameof(filter)); + } } private HtmlEncoder(HtmlUnicodeEncoder innerEncoder) @@ -97,6 +100,16 @@ namespace Microsoft.Framework.WebEncoders /// public void HtmlEncode(char[] value, int startIndex, int charCount, TextWriter output) { + if (value == null) + { + throw new ArgumentNullException(nameof(value)); + } + + if (output == null) + { + throw new ArgumentNullException(nameof(output)); + } + _innerUnicodeEncoder.Encode(value, startIndex, charCount, output); } @@ -113,6 +126,16 @@ namespace Microsoft.Framework.WebEncoders /// public void HtmlEncode(string value, int startIndex, int charCount, TextWriter output) { + if (value == null) + { + throw new ArgumentNullException(nameof(value)); + } + + if (output == null) + { + throw new ArgumentNullException(nameof(output)); + } + _innerUnicodeEncoder.Encode(value, startIndex, charCount, output); } diff --git a/src/Microsoft.Framework.WebEncoders.Core/IHtmlEncoder.cs b/src/Microsoft.Framework.WebEncoders.Core/IHtmlEncoder.cs index 16e4ff5f05..f7c6adb064 100644 --- a/src/Microsoft.Framework.WebEncoders.Core/IHtmlEncoder.cs +++ b/src/Microsoft.Framework.WebEncoders.Core/IHtmlEncoder.cs @@ -1,9 +1,7 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -using System; using System.IO; -using Microsoft.Framework.Internal; namespace Microsoft.Framework.WebEncoders { @@ -20,7 +18,7 @@ namespace Microsoft.Framework.WebEncoders /// The encoded value is also appropriately encoded for inclusion inside an HTML attribute /// as long as the attribute value is surrounded by single or double quotes. /// - void HtmlEncode([NotNull] char[] value, int startIndex, int charCount, [NotNull] TextWriter output); + void HtmlEncode(char[] value, int startIndex, int charCount, TextWriter output); /// /// HTML-encodes a given input string. @@ -42,6 +40,6 @@ namespace Microsoft.Framework.WebEncoders /// The encoded value is also appropriately encoded for inclusion inside an HTML attribute /// as long as the attribute value is surrounded by single or double quotes. /// - void HtmlEncode([NotNull] string value, int startIndex, int charCount, [NotNull] TextWriter output); + void HtmlEncode(string value, int startIndex, int charCount, TextWriter output); } } diff --git a/src/Microsoft.Framework.WebEncoders.Core/IJavaScriptStringEncoder.cs b/src/Microsoft.Framework.WebEncoders.Core/IJavaScriptStringEncoder.cs index e88aafce79..19b7d843e2 100644 --- a/src/Microsoft.Framework.WebEncoders.Core/IJavaScriptStringEncoder.cs +++ b/src/Microsoft.Framework.WebEncoders.Core/IJavaScriptStringEncoder.cs @@ -1,9 +1,7 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -using System; using System.IO; -using Microsoft.Framework.Internal; namespace Microsoft.Framework.WebEncoders { @@ -19,7 +17,7 @@ namespace Microsoft.Framework.WebEncoders /// /// The encoded value is appropriately encoded for inclusion inside a quoted JSON string. /// - void JavaScriptStringEncode([NotNull] char[] value, int startIndex, int charCount, [NotNull] TextWriter output); + void JavaScriptStringEncode(char[] value, int startIndex, int charCount, TextWriter output); /// /// JavaScript-escapes a given input string. @@ -37,6 +35,6 @@ namespace Microsoft.Framework.WebEncoders /// /// The encoded value is appropriately encoded for inclusion inside a quoted JSON string. /// - void JavaScriptStringEncode([NotNull] string value, int startIndex, int charCount, [NotNull] TextWriter output); + void JavaScriptStringEncode(string value, int startIndex, int charCount, TextWriter output); } } diff --git a/src/Microsoft.Framework.WebEncoders.Core/IUrlEncoder.cs b/src/Microsoft.Framework.WebEncoders.Core/IUrlEncoder.cs index 9b38b6a65e..edcaaffea8 100644 --- a/src/Microsoft.Framework.WebEncoders.Core/IUrlEncoder.cs +++ b/src/Microsoft.Framework.WebEncoders.Core/IUrlEncoder.cs @@ -1,9 +1,7 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -using System; using System.IO; -using Microsoft.Framework.Internal; namespace Microsoft.Framework.WebEncoders { @@ -20,7 +18,7 @@ namespace Microsoft.Framework.WebEncoders /// The encoded value is appropriately encoded for inclusion in the segment, query, or /// fragment portion of a URI. /// - void UrlEncode([NotNull] char[] value, int startIndex, int charCount, [NotNull] TextWriter output); + void UrlEncode(char[] value, int startIndex, int charCount, TextWriter output); /// /// URL-escapes a given input string. @@ -41,6 +39,6 @@ namespace Microsoft.Framework.WebEncoders /// The encoded value is appropriately encoded for inclusion in the segment, query, or /// fragment portion of a URI. /// - void UrlEncode([NotNull] string value, int startIndex, int charCount, [NotNull] TextWriter output); + void UrlEncode(string value, int startIndex, int charCount, TextWriter output); } } diff --git a/src/Microsoft.Framework.WebEncoders.Core/JavaScriptStringEncoder.cs b/src/Microsoft.Framework.WebEncoders.Core/JavaScriptStringEncoder.cs index 71e8a68246..6328bdebc1 100644 --- a/src/Microsoft.Framework.WebEncoders.Core/JavaScriptStringEncoder.cs +++ b/src/Microsoft.Framework.WebEncoders.Core/JavaScriptStringEncoder.cs @@ -6,7 +6,6 @@ using System.Diagnostics; using System.IO; using System.Runtime.CompilerServices; using System.Threading; -using Microsoft.Framework.Internal; namespace Microsoft.Framework.WebEncoders { @@ -51,9 +50,13 @@ namespace Microsoft.Framework.WebEncoders /// set returned by 's /// method will be escaped. /// - public JavaScriptStringEncoder([NotNull] ICodePointFilter filter) + public JavaScriptStringEncoder(ICodePointFilter filter) : this(new JavaScriptStringUnicodeEncoder(CodePointFilter.Wrap(filter))) { + if (filter == null) + { + throw new ArgumentNullException(nameof(filter)); + } } private JavaScriptStringEncoder(JavaScriptStringUnicodeEncoder innerEncoder) @@ -97,6 +100,16 @@ namespace Microsoft.Framework.WebEncoders /// public void JavaScriptStringEncode(char[] value, int startIndex, int charCount, TextWriter output) { + if (value == null) + { + throw new ArgumentNullException(nameof(value)); + } + + if (output == null) + { + throw new ArgumentNullException(nameof(output)); + } + _innerUnicodeEncoder.Encode(value, startIndex, charCount, output); } @@ -113,6 +126,16 @@ namespace Microsoft.Framework.WebEncoders /// public void JavaScriptStringEncode(string value, int startIndex, int charCount, TextWriter output) { + if (value == null) + { + throw new ArgumentNullException(nameof(value)); + } + + if (output == null) + { + throw new ArgumentNullException(nameof(output)); + } + _innerUnicodeEncoder.Encode(value, startIndex, charCount, output); } diff --git a/src/Microsoft.Framework.WebEncoders.Core/UrlEncoder.cs b/src/Microsoft.Framework.WebEncoders.Core/UrlEncoder.cs index 0e0de56c7a..e15096659f 100644 --- a/src/Microsoft.Framework.WebEncoders.Core/UrlEncoder.cs +++ b/src/Microsoft.Framework.WebEncoders.Core/UrlEncoder.cs @@ -6,7 +6,6 @@ using System.Diagnostics; using System.IO; using System.Runtime.CompilerServices; using System.Threading; -using Microsoft.Framework.Internal; namespace Microsoft.Framework.WebEncoders { @@ -51,9 +50,13 @@ namespace Microsoft.Framework.WebEncoders /// set returned by 's /// method will be escaped. /// - public UrlEncoder([NotNull] ICodePointFilter filter) + public UrlEncoder(ICodePointFilter filter) : this(new UrlUnicodeEncoder(CodePointFilter.Wrap(filter))) { + if (filter == null) + { + throw new ArgumentNullException(nameof(filter)); + } } private UrlEncoder(UrlUnicodeEncoder innerEncoder) @@ -97,6 +100,16 @@ namespace Microsoft.Framework.WebEncoders /// public void UrlEncode(char[] value, int startIndex, int charCount, TextWriter output) { + if (value == null) + { + throw new ArgumentNullException(nameof(value)); + } + + if (output == null) + { + throw new ArgumentNullException(nameof(output)); + } + _innerUnicodeEncoder.Encode(value, startIndex, charCount, output); } @@ -113,6 +126,16 @@ namespace Microsoft.Framework.WebEncoders /// public void UrlEncode(string value, int startIndex, int charCount, TextWriter output) { + if (value == null) + { + throw new ArgumentNullException(nameof(value)); + } + + if (output == null) + { + throw new ArgumentNullException(nameof(output)); + } + _innerUnicodeEncoder.Encode(value, startIndex, charCount, output); } diff --git a/src/Microsoft.Framework.WebEncoders.Core/project.json b/src/Microsoft.Framework.WebEncoders.Core/project.json index b2ad614378..54dbd1c28e 100644 --- a/src/Microsoft.Framework.WebEncoders.Core/project.json +++ b/src/Microsoft.Framework.WebEncoders.Core/project.json @@ -6,10 +6,8 @@ "url": "git://github.com/aspnet/httpabstractions" }, "compilationOptions": { - "allowUnsafe": true - }, - "dependencies": { - "Microsoft.Framework.NotNullAttribute.Sources": { "type": "build", "version": "1.0.0-*" } + "allowUnsafe": true, + "warningsAsErrors": true }, "frameworks": { "net45": { }, diff --git a/src/Microsoft.Framework.WebEncoders/EncoderServiceCollectionExtensions.cs b/src/Microsoft.Framework.WebEncoders/EncoderServiceCollectionExtensions.cs index 48e0e94c98..13505165d8 100644 --- a/src/Microsoft.Framework.WebEncoders/EncoderServiceCollectionExtensions.cs +++ b/src/Microsoft.Framework.WebEncoders/EncoderServiceCollectionExtensions.cs @@ -3,7 +3,6 @@ using System; using Microsoft.Framework.DependencyInjection.Extensions; -using Microsoft.Framework.Internal; using Microsoft.Framework.OptionsModel; using Microsoft.Framework.WebEncoders; @@ -11,13 +10,23 @@ namespace Microsoft.Framework.DependencyInjection { public static class EncoderServiceCollectionExtensions { - public static IServiceCollection AddWebEncoders([NotNull] this IServiceCollection services) + public static IServiceCollection AddWebEncoders(this IServiceCollection services) { + if (services == null) + { + throw new ArgumentNullException(nameof(services)); + } + return AddWebEncoders(services, configureOptions: null); } - public static IServiceCollection AddWebEncoders([NotNull] this IServiceCollection services, Action configureOptions) + public static IServiceCollection AddWebEncoders(this IServiceCollection services, Action configureOptions) { + if (services == null) + { + throw new ArgumentNullException(nameof(services)); + } + services.AddOptions(); // Register the default encoders diff --git a/src/Microsoft.Framework.WebEncoders/project.json b/src/Microsoft.Framework.WebEncoders/project.json index d39cd992f4..d2a1c401fb 100644 --- a/src/Microsoft.Framework.WebEncoders/project.json +++ b/src/Microsoft.Framework.WebEncoders/project.json @@ -5,10 +5,12 @@ "type": "git", "url": "git://github.com/aspnet/httpabstractions" }, + "compilationOptions": { + "warningsAsErrors": true + }, "dependencies": { "Microsoft.Framework.DependencyInjection.Abstractions": "1.0.0-*", "Microsoft.Framework.OptionsModel": "1.0.0-*", - "Microsoft.Framework.NotNullAttribute.Sources": { "type": "build", "version": "1.0.0-*" }, "Microsoft.Framework.WebEncoders.Core": "1.0.0-*" }, "frameworks": { diff --git a/src/Microsoft.Net.Http.Headers/CookieHeaderValue.cs b/src/Microsoft.Net.Http.Headers/CookieHeaderValue.cs index 5006792814..e7e72d3ce5 100644 --- a/src/Microsoft.Net.Http.Headers/CookieHeaderValue.cs +++ b/src/Microsoft.Net.Http.Headers/CookieHeaderValue.cs @@ -5,7 +5,6 @@ using System; using System.Collections.Generic; using System.Diagnostics.Contracts; using System.Text; -using Microsoft.Framework.Internal; namespace Microsoft.Net.Http.Headers { @@ -23,13 +22,27 @@ namespace Microsoft.Net.Http.Headers // Used by the parser to create a new instance of this type. } - public CookieHeaderValue([NotNull] string name) + public CookieHeaderValue(string name) : this(name, string.Empty) { + if (name == null) + { + throw new ArgumentNullException(nameof(name)); + } } - public CookieHeaderValue([NotNull] string name, [NotNull] string value) + public CookieHeaderValue(string name, string value) { + if (name == null) + { + throw new ArgumentNullException(nameof(name)); + } + + if (value == null) + { + throw new ArgumentNullException(nameof(value)); + } + Name = name; Value = value; } @@ -219,16 +232,26 @@ namespace Microsoft.Net.Http.Headers return !(c == '"' || c == ',' || c == ';' || c == '\\'); } - internal static void CheckNameFormat([NotNull] string name, string parameterName) + internal static void CheckNameFormat(string name, string parameterName) { + if (name == null) + { + throw new ArgumentNullException(nameof(name)); + } + if (HttpRuleParser.GetTokenLength(name, 0) != name.Length) { throw new ArgumentException("Invalid cookie name: " + name, parameterName); } } - internal static void CheckValueFormat([NotNull] string value, string parameterName) + internal static void CheckValueFormat(string value, string parameterName) { + if (value == null) + { + throw new ArgumentNullException(nameof(value)); + } + string temp; if (GetCookieValueLength(value, 0, out temp) != value.Length) { diff --git a/src/Microsoft.Net.Http.Headers/GenericHeaderParser.cs b/src/Microsoft.Net.Http.Headers/GenericHeaderParser.cs index 669ec464de..63f9b8aed0 100644 --- a/src/Microsoft.Net.Http.Headers/GenericHeaderParser.cs +++ b/src/Microsoft.Net.Http.Headers/GenericHeaderParser.cs @@ -1,7 +1,7 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -using Microsoft.Framework.Internal; +using System; namespace Microsoft.Net.Http.Headers { @@ -11,9 +11,14 @@ namespace Microsoft.Net.Http.Headers private GetParsedValueLengthDelegate _getParsedValueLength; - internal GenericHeaderParser(bool supportsMultipleValues, [NotNull] GetParsedValueLengthDelegate getParsedValueLength) + internal GenericHeaderParser(bool supportsMultipleValues, GetParsedValueLengthDelegate getParsedValueLength) : base(supportsMultipleValues) { + if (getParsedValueLength == null) + { + throw new ArgumentNullException(nameof(getParsedValueLength)); + } + _getParsedValueLength = getParsedValueLength; } diff --git a/src/Microsoft.Net.Http.Headers/SetCookieHeaderValue.cs b/src/Microsoft.Net.Http.Headers/SetCookieHeaderValue.cs index 52fdd46a36..92cf35a41f 100644 --- a/src/Microsoft.Net.Http.Headers/SetCookieHeaderValue.cs +++ b/src/Microsoft.Net.Http.Headers/SetCookieHeaderValue.cs @@ -5,7 +5,6 @@ using System; using System.Collections.Generic; using System.Diagnostics.Contracts; using System.Text; -using Microsoft.Framework.Internal; namespace Microsoft.Net.Http.Headers { @@ -33,13 +32,23 @@ namespace Microsoft.Net.Http.Headers // Used by the parser to create a new instance of this type. } - public SetCookieHeaderValue([NotNull] string name) + public SetCookieHeaderValue(string name) : this(name, string.Empty) { } - public SetCookieHeaderValue([NotNull] string name, [NotNull] string value) + public SetCookieHeaderValue(string name, string value) { + if (name == null) + { + throw new ArgumentNullException(nameof(name)); + } + + if (value == null) + { + throw new ArgumentNullException(nameof(value)); + } + Name = name; Value = value; } diff --git a/src/Microsoft.Net.Http.Headers/StringWithQualityHeaderValueComparer.cs b/src/Microsoft.Net.Http.Headers/StringWithQualityHeaderValueComparer.cs index 37873c476c..2dfa0509ad 100644 --- a/src/Microsoft.Net.Http.Headers/StringWithQualityHeaderValueComparer.cs +++ b/src/Microsoft.Net.Http.Headers/StringWithQualityHeaderValueComparer.cs @@ -3,7 +3,6 @@ using System; using System.Collections.Generic; -using Microsoft.Framework.Internal; namespace Microsoft.Net.Http.Headers { @@ -39,9 +38,19 @@ namespace Microsoft.Net.Http.Headers /// The first value to compare. /// The second value to compare /// The result of the comparison. - public int Compare([NotNull] StringWithQualityHeaderValue stringWithQuality1, - [NotNull] StringWithQualityHeaderValue stringWithQuality2) + public int Compare(StringWithQualityHeaderValue stringWithQuality1, + StringWithQualityHeaderValue stringWithQuality2) { + if (stringWithQuality1 == null) + { + throw new ArgumentNullException(nameof(stringWithQuality1)); + } + + if (stringWithQuality2 == null) + { + throw new ArgumentNullException(nameof(stringWithQuality2)); + } + var quality1 = stringWithQuality1.Quality ?? HeaderQuality.Match; var quality2 = stringWithQuality2.Quality ?? HeaderQuality.Match; var qualityDifference = quality1 - quality2; diff --git a/src/Microsoft.Net.Http.Headers/project.json b/src/Microsoft.Net.Http.Headers/project.json index ae39f93621..8bcba3ca6d 100644 --- a/src/Microsoft.Net.Http.Headers/project.json +++ b/src/Microsoft.Net.Http.Headers/project.json @@ -1,12 +1,12 @@ { "version": "1.0.0-*", - "dependencies": { - "Microsoft.Framework.NotNullAttribute.Sources": { "type": "build", "version": "1.0.0-*" } - }, "repository": { "type": "git", "url": "git://github.com/aspnet/httpabstractions" }, + "compilationOptions": { + "warningsAsErrors": true + }, "frameworks" : { "net45" : { }, "dnx451" : { }, diff --git a/test/Microsoft.AspNet.Http.Abstractions.Tests/MapPathMiddlewareTests.cs b/test/Microsoft.AspNet.Http.Abstractions.Tests/MapPathMiddlewareTests.cs index aaa4467fe9..03d885f7bc 100644 --- a/test/Microsoft.AspNet.Http.Abstractions.Tests/MapPathMiddlewareTests.cs +++ b/test/Microsoft.AspNet.Http.Abstractions.Tests/MapPathMiddlewareTests.cs @@ -43,10 +43,8 @@ namespace Microsoft.AspNet.Builder.Extensions var builder = new ApplicationBuilder(serviceProvider: null); var noMiddleware = new ApplicationBuilder(serviceProvider: null).Build(); var noOptions = new MapOptions(); - // TODO: [NotNull] Assert.Throws(() => builder.Map(null, ActionNotImplemented)); - // TODO: [NotNull] Assert.Throws(() => builder.Map("/foo", (Action)null)); - // TODO: [NotNull] Assert.Throws(() => new MapMiddleware(null, noOptions)); - // TODO: [NotNull] Assert.Throws(() => new MapMiddleware(noMiddleware, null)); + Assert.Throws(() => builder.Map("/foo", configuration: null)); + Assert.Throws(() => new MapMiddleware(noMiddleware, null)); } [Theory] diff --git a/test/Microsoft.AspNet.Http.Abstractions.Tests/MapPredicateMiddlewareTests.cs b/test/Microsoft.AspNet.Http.Abstractions.Tests/MapPredicateMiddlewareTests.cs index 0fcc04c997..4ddf45220d 100644 --- a/test/Microsoft.AspNet.Http.Abstractions.Tests/MapPredicateMiddlewareTests.cs +++ b/test/Microsoft.AspNet.Http.Abstractions.Tests/MapPredicateMiddlewareTests.cs @@ -11,9 +11,7 @@ using Xunit; namespace Microsoft.AspNet.Builder.Extensions { - using AppFunc = Func, Task>; using Predicate = Func; - using PredicateAsync = Func>; public class MapPredicateMiddlewareTests { @@ -56,15 +54,12 @@ namespace Microsoft.AspNet.Builder.Extensions var builder = new ApplicationBuilder(serviceProvider: null); var noMiddleware = new ApplicationBuilder(serviceProvider: null).Build(); var noOptions = new MapWhenOptions(); - // TODO: [NotNull] Assert.Throws(() => builder.MapWhen(null, UseNotImplemented)); - // TODO: [NotNull] Assert.Throws(() => builder.MapWhen(NotImplementedPredicate, (Action)null)); - // TODO: [NotNull] Assert.Throws(() => new MapWhenMiddleware(null, noOptions)); - // TODO: [NotNull] Assert.Throws(() => new MapWhenMiddleware(noMiddleware, null)); - - // TODO: [NotNull] Assert.Throws(() => builder.MapWhenAsync(null, UseNotImplemented)); - // TODO: [NotNull] Assert.Throws(() => builder.MapWhenAsync(NotImplementedPredicateAsync, (Action)null)); - // TODO: [NotNull] Assert.Throws(() => new MapWhenMiddleware(null, noOptions)); - // TODO: [NotNull] Assert.Throws(() => new MapWhenMiddleware(noMiddleware, null)); + Assert.Throws(() => builder.MapWhen(null, UseNotImplemented)); + Assert.Throws(() => builder.MapWhen(NotImplementedPredicate, configuration: null)); + Assert.Throws(() => new MapWhenMiddleware(null, noOptions)); + Assert.Throws(() => new MapWhenMiddleware(noMiddleware, null)); + Assert.Throws(() => new MapWhenMiddleware(null, noOptions)); + Assert.Throws(() => new MapWhenMiddleware(noMiddleware, null)); } [Fact] diff --git a/test/Microsoft.AspNet.Http.Tests/Authentication/DefaultAuthenticationManagerTests.cs b/test/Microsoft.AspNet.Http.Tests/Authentication/DefaultAuthenticationManagerTests.cs index db7e1f7f36..a48e80ea03 100644 --- a/test/Microsoft.AspNet.Http.Tests/Authentication/DefaultAuthenticationManagerTests.cs +++ b/test/Microsoft.AspNet.Http.Tests/Authentication/DefaultAuthenticationManagerTests.cs @@ -24,7 +24,6 @@ namespace Microsoft.AspNet.Http.Authentication.Internal [Theory] [InlineData("")] - [InlineData(null)] [InlineData("Foo")] public async Task ChallengeWithNoAuthMiddlewareMayThrow(string scheme) {