Azure / azure-storage-php

Microsoft Azure Storage Library for PHP
MIT License
217 stars 199 forks source link

Missing x-ms-client-request-id Header Option #222

Open meinemitternacht opened 4 years ago

meinemitternacht commented 4 years ago

Which service(blob, file, queue, table) does this issue concern?

blob

Which version of the SDK was used?

1.5.0

What's the PHP/OS version?

7.3.10

What problem was encountered?

When storing a page blob page via PUT request, there is no option to set a "client request ID".

Steps to reproduce the issue?

Make a "createBlobPages" or "createBlobPagesAsync" request.

Have you found a mitigation/solution?

I have patched my local installation of the SDK to copy the request headers from the Guzzle request to the response (and ServiceException objects).

Is there a failing request ID related to this problem returned by server? What is it?

No failing requests.

What is the storage account name and time frame of your last reproduce? (UTC YYYY/MM/DD hh:mm:ss)

N/A

Additional information:

The Official API Documentation specifies the x-ms-client-request-id header as optional. It also states that it will be returned in the response if provided.

My first attempt at a solution was to add support for adding the x-ms-client-request-id header to the SDK. This worked as intended, but led me to another problem: the Azure REST API does not return the header in the response, even though the documentation stated it would be there.

So, until I can file a bug report with Azure, I have added a nasty workaround which involves copying the request headers to the response. This also applies to possible RequestException and ServiceException objects which may be generated. All of these changes allow me to retry failed blob page PUT requests using a straightforward process, since I am uploading pages in parallel and PHP does not make it easy to process things in parallel.

XiaoningLiu commented 4 years ago

Hi, PHP SDK doesn't expose x-ms-client-request-id in options and will auto generate client id by design.

For your another question, why response doesn't include the x-ms-request-id you set. It because PHP SDK uses service API version 2017-11-09. https://github.com/Azure/azure-storage-php/blob/5c4839e8d0bc5b0e8216fda745b0ac52130fd2bc/azure-storage-blob/src/Blob/Internal/BlobResources.php#L45

While Azure Storage needs 2019-02-02 for returning x-ms-client-request-id header in response. https://docs.microsoft.com/en-us/rest/api/storageservices/version-2019-02-02

You can try to customize this x-ms-version header or override STORAGE_API_LATEST_VERSION in BlobResources.php

meinemitternacht commented 4 years ago

Thank you for the assistance, that makes sense. I think it would be nice to have the ability to manually specify this header, so I suppose this issue could be re-scoped to that only.