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

Should the Prefer header be configurable to either "return-no-content" or "return-content", based on options, rather than hard-coded? #6226

Open
ahsonkhan opened this issue Nov 15, 2024 · 2 comments
Assignees
Labels
bug This issue requires a change to an existing behavior in the product in order to be resolved. Tables

Comments

@ahsonkhan
Copy link
Member

It looks like we hard-code (and always set) the Prefer: header to "return-no-content" everywhere in C++, rather than it be configured based on options:

std::string TableClient::PrepInsertEntity(
std::string const& changesetId,
Models::TableEntity entity)
{
std::string payload = Serializers::UpdateEntity(entity);
std::string returnValue = "--" + changesetId + "\n";
returnValue += "Content-Type: application/http\n";
returnValue += "Content-Transfer-Encoding: binary\n\n";
auto url = m_url;
url.AppendPath(
m_tableName + PartitionKeyFragment + entity.GetPartitionKey().Value + RowKeyFragment
+ entity.GetRowKey().Value + ClosingFragment);
returnValue += "PATCH " + url.GetAbsoluteUrl() + " HTTP/1.1\n";
returnValue += "Content-Type: application/json\n";
returnValue += "Content-Length: " + std::to_string(payload.length());
returnValue += "Accept: application/json;odata=minimalmetadata\n";
returnValue += "Prefer: return-no-content\n";

In .NET, that header is configurable to a ResponseFormat, which is documented to be one of two values:

<param name="responsePreference"> Specifies whether the response should include the inserted entity in the payload.
Possible values are return-no-content and return-content. </param>

https://github.com/Azure/azure-sdk-for-net/blob/f566cffd72d20403eb934e03e0e6fe4015a878e5/sdk/tables/Azure.Data.Tables/src/Generated/TableRestClient.cs#L1149-L1157

And only if a value is provided, does that header get set:
https://github.com/Azure/azure-sdk-for-net/blob/f566cffd72d20403eb934e03e0e6fe4015a878e5/sdk/tables/Azure.Data.Tables/src/Generated/TableRestClient.cs#L1123-L1126

GoLang also has these ResponseFormat constants:
https://github.com/Azure/azure-sdk-for-go/blob/e8ec092d8456cd6d0cb836f29a9759d3aac2687d/sdk/data/aztables/internal/zz_constants.go#L46-L59
And they get used to optionally set the request header:
https://github.com/Azure/azure-sdk-for-go/blob/e8ec092d8456cd6d0cb836f29a9759d3aac2687d/sdk/data/aztables/internal/zz_table_client.go#L385-L389

As an aside, PrepDeleteEntity has this line commented out, which we should either remove or fix if intended:

returnValue += "DELETE " + url.GetAbsoluteUrl() + " HTTP/1.1\n";
returnValue += "Accept: application/json;odata=minimalmetadata\n";
// returnValue += "Prefer: return-no-content\n";
returnValue += "DataServiceVersion: 3.0;\n";

@ahsonkhan ahsonkhan added bug This issue requires a change to an existing behavior in the product in order to be resolved. Tables labels Nov 15, 2024
@gearama
Copy link
Member

gearama commented Nov 15, 2024

No custumer asked for it, the returned data contains the etag and all other useful info.

@gearama gearama closed this as completed Nov 15, 2024
@ahsonkhan
Copy link
Member Author

Looks like the option only exists in the generated "protocol" layer. It is hardcoded in .NET, within the public layer (and the option isn't exposed to the end user):
https://github.com/Azure/azure-sdk-for-net/blob/4e1173308d32f0413788359a87376e673f2ab15b/sdk/tables/Azure.Data.Tables/src/TableClient.cs#L495
https://github.com/Azure/azure-sdk-for-net/blob/4e1173308d32f0413788359a87376e673f2ab15b/sdk/tables/Azure.Data.Tables/src/TableClient.cs#L615

That said, the header is only optionally set in some cases.
For example, in SubmitTransaction, this header isn't set (since ResponseFormat is set to null):
https://github.com/Azure/azure-sdk-for-net/blob/4e1173308d32f0413788359a87376e673f2ab15b/sdk/tables/Azure.Data.Tables/src/TableClient.cs#L1625

Should we do the same? Is there any unintended consequence of us setting this header when it doesn't need to be set?

If we are fine with always setting this header in the request (even in the cases where other language SDKs don't), then the only actionable part of this issue is:

As an aside, PrepDeleteEntity has this line commented out, which we should either remove or fix if intended

@gearama gearama reopened this Nov 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug This issue requires a change to an existing behavior in the product in order to be resolved. Tables
Projects
None yet
Development

No branches or pull requests

2 participants