Skip to content

Commit 523c916

Browse files
committed
Fix relocated source files
1 parent e7a95d3 commit 523c916

File tree

34 files changed

+414
-68
lines changed

34 files changed

+414
-68
lines changed

src/Http/Http.Extensions/gen/StaticRouteHandler/Emitters/EndpointEmitter.cs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -85,10 +85,6 @@ public static void EmitRequestHandler(this Endpoint endpoint, CodeWriter codeWri
8585
{
8686
return;
8787
}
88-
if (!endpoint.Response.HasNoResponse && endpoint.Response is { ContentType: { } contentType })
89-
{
90-
codeWriter.WriteLine($@"httpContext.Response.ContentType ??= ""{contentType}"";");
91-
}
9288
if (!endpoint.Response.HasNoResponse)
9389
{
9490
codeWriter.Write("var result = ");
@@ -98,6 +94,9 @@ public static void EmitRequestHandler(this Endpoint endpoint, CodeWriter codeWri
9894
codeWriter.Write("await ");
9995
}
10096
codeWriter.WriteLine($"handler({endpoint.EmitArgumentList()});");
97+
98+
endpoint.Response.EmitHttpResponseContentType(codeWriter);
99+
101100
if (!endpoint.Response.HasNoResponse)
102101
{
103102
codeWriter.WriteLine(endpoint.Response.EmitResponseWritingCall(endpoint.IsAwaitable));

src/Http/Http.Extensions/gen/StaticRouteHandler/Emitters/EndpointResponseEmitter.cs

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ internal static void EmitJsonPreparation(this EndpointResponse endpointResponse,
1111
{
1212
if (endpointResponse.IsSerializableJsonResponse(out var responseType))
1313
{
14-
var typeName = responseType.ToDisplayString(EmitterConstants.DisplayFormat);
14+
var typeName = responseType.ToDisplayString(EmitterConstants.DisplayFormatWithoutNullability);
1515

1616
codeWriter.WriteLine("var serializerOptions = serviceProvider?.GetService<IOptions<JsonOptions>>()?.Value.SerializerOptions ?? new JsonOptions().SerializerOptions;");
1717
codeWriter.WriteLine($"var jsonTypeInfo = (JsonTypeInfo<{typeName}>)serializerOptions.GetTypeInfo(typeof({typeName}));");
@@ -73,7 +73,7 @@ internal static void EmitBuiltinResponseTypeMetadata(this Endpoint endpoint, Cod
7373
}
7474
else
7575
{
76-
codeWriter.WriteLine($"options.EndpointBuilder.Metadata.Add(new GeneratedProducesResponseTypeMetadata(type: typeof({responseType.ToDisplayString(EmitterConstants.DisplayFormat)}), statusCode: StatusCodes.Status200OK, contentTypes: GeneratedMetadataConstants.JsonContentType));");
76+
codeWriter.WriteLine($"options.EndpointBuilder.Metadata.Add(new GeneratedProducesResponseTypeMetadata(type: typeof({responseType.ToDisplayString(EmitterConstants.DisplayFormatWithoutNullability)}), statusCode: StatusCodes.Status200OK, contentTypes: GeneratedMetadataConstants.JsonContentType));");
7777
}
7878
}
7979

@@ -89,4 +89,21 @@ internal static void EmitCallToMetadataProviderForResponse(this Endpoint endpoin
8989
codeWriter.WriteLine($"PopulateMetadataForEndpoint<{responseType.ToDisplayString(EmitterConstants.DisplayFormat)}>(methodInfo, options.EndpointBuilder);");
9090
}
9191
}
92+
93+
internal static void EmitHttpResponseContentType(this EndpointResponse endpointResponse, CodeWriter codeWriter)
94+
{
95+
if (!endpointResponse.HasNoResponse
96+
&& endpointResponse.ResponseType is { } responseType
97+
&& (responseType.SpecialType == SpecialType.System_Object || responseType.SpecialType == SpecialType.System_String))
98+
{
99+
codeWriter.WriteLine("if (result is string)");
100+
codeWriter.StartBlock();
101+
codeWriter.WriteLine($@"httpContext.Response.ContentType ??= ""text/plain; charset=utf-8"";");
102+
codeWriter.EndBlock();
103+
codeWriter.WriteLine("else");
104+
codeWriter.StartBlock();
105+
codeWriter.WriteLine($@"httpContext.Response.ContentType ??= ""application/json; charset=utf-8"";");
106+
codeWriter.EndBlock();
107+
}
108+
}
92109
}

0 commit comments

Comments
 (0)