Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Response Content-Type does not allow for optional parameters #526

Closed
HealthOneNZ opened this issue Nov 2, 2021 · 4 comments
Closed

Response Content-Type does not allow for optional parameters #526

HealthOneNZ opened this issue Nov 2, 2021 · 4 comments
Assignees
Labels
accepted Issue has been accepted and inserted in a future milestone enhancement

Comments

@HealthOneNZ
Copy link

HealthOneNZ commented Nov 2, 2021

The http specification allows for optional parameters to be added to the Content-Type response header
https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/MIME_types

The form of the header is
type/subtype;parameter=value

I wish to add a header to a response of "application/fhir+xml; fhirVersion=4.0"

The procedure SplitContentMediaTypeAndCharset which is called by the Render method discards all parameters except for "charset"

A fix would be to split the passed in value by ";", find the charset if any and recombine all other parameters

@HealthOneNZ
Copy link
Author

HealthOneNZ commented Nov 2, 2021

Suggested code fix which correctly extracts the charset and them recombines all of the other parameters
procedure SplitContentMediaTypeAndCharset(const aContentType: string; var aContentMediaType: string;
var aContentCharSet: string);
var
lContentTypeValues: TArray<string>;
begin
if not aContentType.IsEmpty then
begin
lContentTypeValues := aContentType.Split([';']);
aContentCharSet := '';
for var I := Low(lContentTypeValues) to High(lContentTypeValues) do
begin
if lContentTypeValues[I].Trim.StartsWith('charset', True) then
begin
aContentCharSet := lContentTypeValues[I].Trim.Split(['='])[1].Trim;
for var J := I + 1 to High(lContentTypeValues) do
lContentTypeValues[J-1] := lContentTypeValues[J];
SetLength(lContentTypeValues, Length(lContentTypeValues) - 1);
Break;
end;
end;
aContentMediaType := string.Join(';', lContentTypeValues);
end
else
begin
aContentMediaType := '';
aContentCharSet := '';
end;
end;

@danieleteti
Copy link
Owner

Thank you for your contribute.
Is this the behavior you need?

having this controller

procedure TTestServerController.TestIssue526;
begin
  ContentType := 'application/fhir+xml; fhirVersion=4.0';
  ResponseStream.Append('OK');
  RenderResponseStream;
end;

you get this response

image

@danieleteti danieleteti self-assigned this Nov 2, 2021
@danieleteti danieleteti added accepted Issue has been accepted and inserted in a future milestone enhancement labels Nov 2, 2021
@danieleteti danieleteti added this to the 3.2.2-nitrogen milestone Nov 2, 2021
@fastbike
Copy link
Contributor

fastbike commented Nov 2, 2021

Thanks Danielle, all looks good apart from dropping the casing in the header value.

BTW, I posted the issue with my work github account. Apologies if this causes any confusion.

@danieleteti
Copy link
Owner

Good, the fix will be merged ASAP.
Thank you for your feedback

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
accepted Issue has been accepted and inserted in a future milestone enhancement
Projects
None yet
Development

No branches or pull requests

3 participants