twilio-aspnet icon indicating copy to clipboard operation
twilio-aspnet copied to clipboard

Use `XDocument.Save` or `XDocument.SaveAsync` to write to response body when possible

Open Swimburger opened this issue 1 year ago • 1 comments

With the new TwiML.ToXDocument() method (PR) from the Twilio C# helper library, we can now avoid serializing the XML to a big string before writing it to the response body.

ASP.NET Core does require writes to the response to be async, and in older .NET Core versions XDocument.SaveAsync is not available. In that case, the XML is serialized to a string and written to the response.

For ASP.NET, there's only XDocument.Save available but there's no need for asynchronous writes.


Additionally, I replaced null checks with string.IsNullOrEmpty for BaseUrlOverride because sometimes the setting is an empty string.

Contributing to Twilio

All third-party contributors acknowledge that any contributions they provide will be made under the same open-source license that the open-source project is provided under.

  • [x] I acknowledge that all my contributions will be made under the project's license.

Swimburger avatar Dec 07 '22 18:12 Swimburger

Assuming PR twilio-csharp#669 is merged into Twilio helper library for .NET, the new ToString, Save, and SaveAsync would be more performant. Putting this on hold.

Swimburger avatar Feb 08 '23 17:02 Swimburger