Skip to content

Commit

Permalink
accept url encoded form data #414
Browse files Browse the repository at this point in the history
  • Loading branch information
dj-nitehawk committed Mar 23, 2023
1 parent 93985ee commit afde256
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 9 deletions.
2 changes: 1 addition & 1 deletion Src/Directory.Build.props
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project>
<PropertyGroup>

<Version>5.8.0.7-beta</Version>
<Version>5.8.0.8-beta</Version>

<TargetFrameworks>net6.0;net7.0</TargetFrameworks>
<LangVersion>latest</LangVersion>
Expand Down
9 changes: 5 additions & 4 deletions Src/Library/Endpoint/Auxiliary/EndpointDefinition.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public sealed class EndpointDefinition
public bool DoNotCatchExceptions { get; private set; }
public EndpointSummary? EndpointSummary { get; private set; }
public List<string>? EndpointTags { get; private set; }
public bool FormDataAllowed { get; private set; }
public string? FormDataContentType { get; private set; }
public string? OverriddenRoutePrefix { get; private set; }
public List<string>? PreBuiltUserPolicies { get; private set; }
public Action<AuthorizationPolicyBuilder>? PolicyBuilder { get; private set; }
Expand Down Expand Up @@ -135,14 +135,15 @@ public void AllowAnonymous(string[] verbs)
/// </param>
public void AllowFileUploads(bool dontAutoBindFormData = false)
{
FormDataAllowed = true;
FormDataContentType = "multipart/form-data";
DontBindFormData = dontAutoBindFormData;
}

/// <summary>
/// enable multipart/form-data submissions
/// enable form-data submissions
/// </summary>
public void AllowFormData() => FormDataAllowed = true;
/// <param name="urlEncoded">set to true to accept `application/x-www-form-urlencoded` content instead of `multipart/form-data` content.</param>
public void AllowFormData(bool urlEncoded = false) => FormDataContentType = urlEncoded ? "application/x-www-form-urlencoded" : "multipart/form-data";

/// <summary>
/// specify which authentication schemes to use for authenticating requests to this endpoint
Expand Down
5 changes: 3 additions & 2 deletions Src/Library/Endpoint/Endpoint.Setup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,10 @@ public abstract partial class Endpoint<TRequest, TResponse> : BaseEndpoint where
protected void AllowFileUploads(bool dontAutoBindFormData = false) => Definition.AllowFileUploads(dontAutoBindFormData);

/// <summary>
/// enable multipart/form-data submissions
/// enable form-data submissions
/// </summary>
protected void AllowFormData() => Definition.AllowFormData();
/// <param name="urlEncoded">set to true to accept `application/x-www-form-urlencoded` content instead of `multipart/form-data` content.</param>
protected void AllowFormData(bool urlEncoded = false) => Definition.AllowFormData(urlEncoded);

/// <summary>
/// specify which authentication schemes to use for authenticating requests to this endpoint
Expand Down
4 changes: 2 additions & 2 deletions Src/Library/Main/MainExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,8 @@ public static IEndpointRouteBuilder MapFastEndpoints(this IEndpointRouteBuilder
if (def.ResponseCacheSettings is not null)
hb.WithMetadata(def.ResponseCacheSettings);

if (def.FormDataAllowed)
hb.Accepts(def.ReqDtoType, "multipart/form-data");
if (def.FormDataContentType is not null)
hb.Accepts(def.ReqDtoType, def.FormDataContentType);

if (def.EndpointSummary?.ProducesMetas.Count > 0)
{
Expand Down
1 change: 1 addition & 0 deletions Src/Library/changelog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
### NEW
- ability to submit a request DTO as multipart form data when integration testing endpoints that accept form data. #409
- optional boolean argument `urlEncoded` for `AllowFormData()` method to accept `application/x-www-form-urlencoded` instead of `multipart/form-data` #414

### IMPROVEMENTS
- ability to execute a non-concrete `ICommand` types #411
Expand Down

0 comments on commit afde256

Please sign in to comment.