Skip to content

Commit ab16ffe

Browse files
lydonchandralydonch
authored andcommitted
passed in graphQL path into middleware (JannikLassahn#9)
* passed in graphQL path into middleware * used Path.StartsWithSegments to check /graphql Co-authored-by: Lydon Chandra <lydonch@gmail.com>
1 parent 6039f5c commit ab16ffe

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

src/GraphQL.Upload.AspNetCore/ApplicationBuilderExtensions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public static IApplicationBuilder UseGraphQLUpload<TSchema>(this IApplicationBui
4040
if (options is null)
4141
throw new ArgumentNullException(nameof(options));
4242

43-
return builder.UseMiddleware<GraphQLUploadMiddleware<TSchema>>(options);
43+
return builder.UseMiddleware<GraphQLUploadMiddleware<TSchema>>(options, path);
4444
}
4545
}
4646
}

src/GraphQL.Upload.AspNetCore/GraphQLUploadMiddleware.cs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,20 +19,23 @@ public class GraphQLUploadMiddleware<TSchema>
1919
private readonly RequestDelegate _next;
2020
private readonly GraphQLUploadOptions _options;
2121
private readonly GraphQLUploadRequestDeserializer _requestDeserializer;
22-
22+
private readonly string _graphQLPath;
2323
public GraphQLUploadMiddleware(ILogger<GraphQLUploadMiddleware<TSchema>> logger, RequestDelegate next,
24-
GraphQLUploadOptions options, GraphQLUploadRequestDeserializer requestDeserializer)
24+
GraphQLUploadOptions options, PathString path, GraphQLUploadRequestDeserializer requestDeserializer)
2525
{
2626
_logger = logger;
2727
_next = next ?? throw new ArgumentNullException(nameof(next));
2828
_options = options;
2929
_requestDeserializer = requestDeserializer;
30+
_graphQLPath = path;
3031
}
3132

3233
public async Task InvokeAsync(HttpContext context)
3334
{
34-
if (!context.Request.HasFormContentType)
35+
if (!context.Request.HasFormContentType
36+
|| !context.Request.Path.StartsWithSegments( _graphQLPath ))
3537
{
38+
// not graphql path, eg. Form Authentication, skip this middleware
3639
await _next(context);
3740
return;
3841
}

0 commit comments

Comments
 (0)