Skip to content

Commit 09293f2

Browse files
gunjansingh-msftibrandesbrowndav-msft
authored
[Storage] Add Expect: 100-continue support (#50094)
* [Storage] Add Expect: 100-continue support Applies the HTTP header Expect: 100-continue to requests that carry a body, so that a body is not uploaded just to be rejected while the service is under load. The service can reject the request before a single byte of body is sent, which cuts the bandwidth wasted retrying large uploads against a throttling service. - Adds Request100ContinueOptions and Request100ContinueMode (AUTO, ALWAYS, NEVER) to azure-storage-common. AUTO, the default, applies the header only for a window after the service responds 429, 500, or 503, so the extra round trip is only paid when it earns its keep. - The policies are added below the retry policy so a throttling response takes effect on the very next attempt rather than only on a later call, and above the credential policies since headers may affect the string to sign. - Wired into the blob, data lake, file share, and queue pipelines, and exposed on the blob client builders via request100ContinueOptions. - Can be turned off without a code change by setting the system property or environment variable AZURE_STORAGE_DISABLE_EXPECT_CONTINUE_HEADER. Ported from azure-sdk-for-net #40611 and #52438. * [Storage] Address PR feedback on Expect: 100-continue - Rename Request100ContinueOptions/Request100ContinueMode to ExpectContinueOptions/ExpectContinueMode, the mode values to APPLY_ON_THROTTLE/ON/OFF, autoInterval to throttleInterval, and the builder method to expectContinueBehavior, matching the .NET names. - Make ExpectContinueOnThrottlePolicy extend HttpPipelineSyncPolicy rather than ExpectContinuePolicy. Both policies are now final and share their logic through a package private helper, so neither advertises an extension point that callers outside the package cannot actually use. - Allow the Expect header in the blob default log options, so it is visible when debugging whether a request negotiated the handshake. - Replace the unrelated timeouts link in the options javadoc with RFC 9110. - Add ExpectContinueTransportTests, which drives each HTTP client against a real socket and asserts on what reached the wire and when. The transport tests show that setting the header does not by itself make a client wait. Only okhttp performs the handshake. netty and vertx send the header and stream the body immediately, and jdk-httpclient drops the header entirely since Expect is restricted by java.net.http.HttpClient. That is recorded in the test matrix and documented on ExpectContinueOptions and in the changelog rather than left implicit. * [Storage] Test the allowed Expect log header, trim changelog Cover the default log options change with an assertion, and keep the changelog to the feature itself. The transport caveat stays on ExpectContinueOptions, where the behavior it describes lives. * [Storage] Match .NET exactly on enum names and log the Expect header everywhere Use the .NET casing for the mode values, ApplyOnThrottle / On / Off, rather than Java's upper snake case. Checkstyle accepts it. Allow the Expect header in the default log options of the queue, file share and data lake builders too, not only blob, as the review comment was a general one. * [Storage] Mirror the .NET expect-continue tests and cover the async path Restructure ExpectContinueTests so the first section mirrors ExpectContinueTests.cs test for test, with the same names and the same case values, making the two suites directly comparable. Java specific coverage, including the per retry behaviour that .NET has no test for, moves to a clearly separated second section. ThrottlePolicyRevertsAfterBackoff is disabled in .NET (Azure/azure-sdk-for-net#41368); the Java mirror is enabled, since the window is a monotonic nanoTime deadline and oversleeping it can only close the window. Extend the transport test to transport x sync/async, as those are separate code paths in every client. All four transports behave the same on both paths, so the earlier finding is unchanged. * [Storage] Scope expect-continue to blob only and trim comments Revert the queue, file share and data lake packages entirely, so the header is applied only where a customer can configure it. Drop the explanatory comments that were not carrying their weight, including the cross references to the .NET implementation. * [Storage] Remove an unrelated file that was committed by mistake sdk/storage/TYPESPEC_MIGRATION_ESTIMATE.md is unrelated to this change and was picked up accidentally. * [Storage] Move the wire level tests into ExpectContinueTests Keep them in the class the review comment was on rather than a separate file. Each one opens and closes its own server, so the socket fixture does not run for the tests that do not need it. * [Storage] Address review feedback on Expect: 100-continue - Drop the azure-storage-common changelog entry; the changes there are implementation level and the customer facing option is on the blob builders. - Remove the okhttp, vertx and jdk test dependencies. They already come transitively from azure-core-test, so they were redundant. - Move ExpectContinuePolicy and ExpectContinueOnThrottlePolicy into com.azure.storage.common.policy alongside the other storage policies, and rename the shared helper to ExpectContinuePolicyHelper. - Use upper snake case for the mode constants. - Reject a negative content length threshold or throttle interval rather than silently changing behaviour, with boundary tests for both. * [Storage] Do not apply Expect: 100-continue unless it is configured The handshake needs the HTTP client to withhold the request body until the service responds, and the default transport does not do that, so a default client would pay for the header and save nothing. The policy is now added only when expectContinueBehavior is set. * adding support for expect continue 100 to azure core netty * Avoid the deprecated URL constructor in the netty observation test The core modules compile with -Werror, and URL(String) is deprecated as of Java 20, so the test failed to compile on the JDK 25 build agents and took the whole build down with it. * Expect the JDK and Vert.x clients to defer the request body Records the behaviour those transports have once the azure-core fixes in #50311 and #50312 ship. Until Storage picks up those versions the four cases fail, which is the intended signal rather than a silent mismatch. Netty stays as it is: the change there observes the interim response and does not defer the body. * Let the JDK and Vert.x expectations follow the azure-core version Those two clients honour the handshake from azure-core 1.2.0-beta.1 onwards, so the behaviour depends on whether the build resolves a released artifact or the repository source. Asserting either one fails half the pipeline, so assert what holds either way: the exchange completes, the body arrives in full, and a withheld body implies the header reached the wire. Once Storage consumes a release carrying the fix these become DEFERS_BODY. Netty and okhttp keep their exact expectations. * Revert "Let the JDK and Vert.x expectations follow the azure-core version" This reverts commit 644c196. * Revert "Storage - STG105 NFS List V2 Files and Directories (#50036)" This reverts commit 83dc6e2. * add recordings for prev features that were missing * addressing comments and fixing problems left by base merge * addressing comment * preventing expect continute jdk tests from running on java 11 or lower * moving to internal.policy * addressing comments * removing dupe import * fixing flaky test * assets tag update --------- Co-authored-by: Isabelle <ibrandes@microsoft.com> Co-authored-by: browndav <browndav@microsoft.com>
1 parent 48c3373 commit 09293f2

15 files changed

Lines changed: 1753 additions & 16 deletions

File tree

‎sdk/storage/azure-storage-blob/CHANGELOG.md‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
## 12.37.0-beta.1 (Unreleased)
44

55
### Features Added
6+
- Added `expectContinueBehavior` to the blob client builders, which configures when the HTTP header
7+
`Expect: 100-continue` is applied to requests that carry a body. The header is not applied unless configured, and
8+
requires an HTTP client that withholds the request body until the service responds.
69

710
- Added opt-in session-based authentication for eligible Blob GET requests when using a `TokenCredential`. Configure
811
it with `SessionContext.setSessionMode(SessionMode.ENABLED)`; the default `AUTO` mode currently resolves to `SessionMode.DISABLED`.

‎sdk/storage/azure-storage-blob/assets.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22
"AssetsRepo": "Azure/azure-sdk-assets",
33
"AssetsRepoPrefixPath": "java",
44
"TagPrefix": "java/storage/azure-storage-blob",
5-
"Tag": "java/storage/azure-storage-blob_5567e25d8f"
5+
"Tag": "java/storage/azure-storage-blob_4303d08d2f"
66
}

‎sdk/storage/azure-storage-blob/src/main/java/com/azure/storage/blob/BlobClientBuilder.java‎

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
import com.azure.storage.common.implementation.connectionstring.StorageAuthenticationSettings;
3636
import com.azure.storage.common.implementation.connectionstring.StorageConnectionString;
3737
import com.azure.storage.common.implementation.connectionstring.StorageEndpoint;
38+
import com.azure.storage.common.policy.ExpectContinueOptions;
3839
import com.azure.storage.common.policy.RequestRetryOptions;
3940

4041
import java.io.OutputStream;
@@ -92,6 +93,7 @@ public final class BlobClientBuilder
9293
private Configuration configuration;
9394
private BlobServiceVersion version;
9495
private BlobAudience audience;
96+
private ExpectContinueOptions expectContinueOptions;
9597
private SessionContext sessionContext = new SessionContext();
9698

9799
/**
@@ -219,7 +221,7 @@ private HttpPipeline constructPipeline(String containerName, BlobServiceVersion
219221

220222
return BuilderHelper.buildPipeline(storageSharedKeyCredential, tokenCredential, azureSasCredential, sasToken,
221223
endpoint, retryOptions, coreRetryOptions, logOptions, clientOptions, httpClient, perCallPolicies,
222-
perRetryPolicies, configuration, audience, LOGGER, sessionContext, serviceVersion);
224+
perRetryPolicies, configuration, audience, expectContinueOptions, LOGGER, sessionContext, serviceVersion);
223225
}
224226

225227
/**
@@ -670,4 +672,17 @@ public BlobClientBuilder audience(BlobAudience audience) {
670672
return this;
671673
}
672674

675+
/**
676+
* Sets the behavior for applying the HTTP header {@code Expect: 100-continue} to requests that carry a body.
677+
* <p>
678+
* The header is not applied unless this is set, and requires an HTTP client that withholds the request body
679+
* until the service responds.
680+
*
681+
* @param expectContinueOptions {@link ExpectContinueOptions} to be used when sending requests with a body.
682+
* @return the updated BlobClientBuilder object
683+
*/
684+
public BlobClientBuilder expectContinueBehavior(ExpectContinueOptions expectContinueOptions) {
685+
this.expectContinueOptions = expectContinueOptions;
686+
return this;
687+
}
673688
}

‎sdk/storage/azure-storage-blob/src/main/java/com/azure/storage/blob/BlobContainerClientBuilder.java‎

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
import com.azure.storage.common.implementation.connectionstring.StorageAuthenticationSettings;
3737
import com.azure.storage.common.implementation.connectionstring.StorageConnectionString;
3838
import com.azure.storage.common.implementation.connectionstring.StorageEndpoint;
39+
import com.azure.storage.common.policy.ExpectContinueOptions;
3940
import com.azure.storage.common.policy.RequestRetryOptions;
4041

4142
import java.net.MalformedURLException;
@@ -91,6 +92,7 @@ public final class BlobContainerClientBuilder implements TokenCredentialTrait<Bl
9192
private Configuration configuration;
9293
private BlobServiceVersion version;
9394
private BlobAudience audience;
95+
private ExpectContinueOptions expectContinueOptions;
9496
private SessionContext sessionContext = new SessionContext();
9597

9698
/**
@@ -204,7 +206,7 @@ private HttpPipeline constructPipeline(String containerName, BlobServiceVersion
204206
}
205207
return BuilderHelper.buildPipeline(storageSharedKeyCredential, tokenCredential, azureSasCredential, sasToken,
206208
endpoint, retryOptions, coreRetryOptions, logOptions, clientOptions, httpClient, perCallPolicies,
207-
perRetryPolicies, configuration, audience, LOGGER, sessionContext, serviceVersion);
209+
perRetryPolicies, configuration, audience, expectContinueOptions, LOGGER, sessionContext, serviceVersion);
208210
}
209211

210212
/**
@@ -626,4 +628,18 @@ public BlobContainerClientBuilder audience(BlobAudience audience) {
626628
return this;
627629
}
628630

631+
/**
632+
* Sets the behavior for applying the HTTP header {@code Expect: 100-continue} to requests that carry a body.
633+
* <p>
634+
* The header is not applied unless this is set, and requires an HTTP client that withholds the request body
635+
* until the service responds.
636+
*
637+
* @param expectContinueOptions {@link ExpectContinueOptions} to be used when sending requests with a body.
638+
* @return the updated BlobContainerClientBuilder object
639+
*/
640+
public BlobContainerClientBuilder expectContinueBehavior(ExpectContinueOptions expectContinueOptions) {
641+
this.expectContinueOptions = expectContinueOptions;
642+
return this;
643+
}
644+
629645
}

‎sdk/storage/azure-storage-blob/src/main/java/com/azure/storage/blob/BlobServiceClientBuilder.java‎

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
import com.azure.storage.common.implementation.connectionstring.StorageAuthenticationSettings;
3939
import com.azure.storage.common.implementation.connectionstring.StorageConnectionString;
4040
import com.azure.storage.common.implementation.connectionstring.StorageEndpoint;
41+
import com.azure.storage.common.policy.ExpectContinueOptions;
4142
import com.azure.storage.common.policy.RequestRetryOptions;
4243
import com.azure.storage.common.policy.StorageSharedKeyCredentialPolicy;
4344

@@ -92,6 +93,7 @@ public final class BlobServiceClientBuilder implements TokenCredentialTrait<Blob
9293
private Configuration configuration;
9394
private BlobServiceVersion version;
9495
private BlobAudience audience;
96+
private ExpectContinueOptions expectContinueOptions;
9597
private boolean anonymousAccess;
9698
private SessionContext sessionContext = new SessionContext();
9799

@@ -157,7 +159,7 @@ private HttpPipeline constructPipeline(BlobServiceVersion serviceVersion) {
157159
}
158160
return BuilderHelper.buildPipeline(storageSharedKeyCredential, tokenCredential, azureSasCredential, sasToken,
159161
endpoint, retryOptions, coreRetryOptions, logOptions, clientOptions, httpClient, perCallPolicies,
160-
perRetryPolicies, configuration, audience, LOGGER, sessionContext, serviceVersion);
162+
perRetryPolicies, configuration, audience, expectContinueOptions, LOGGER, sessionContext, serviceVersion);
161163
}
162164

163165
/**
@@ -598,6 +600,20 @@ public BlobServiceClientBuilder audience(BlobAudience audience) {
598600
return this;
599601
}
600602

603+
/**
604+
* Sets the behavior for applying the HTTP header {@code Expect: 100-continue} to requests that carry a body.
605+
* <p>
606+
* The header is not applied unless this is set, and requires an HTTP client that withholds the request body
607+
* until the service responds.
608+
*
609+
* @param expectContinueOptions {@link ExpectContinueOptions} to be used when sending requests with a body.
610+
* @return the updated BlobServiceClientBuilder object
611+
*/
612+
public BlobServiceClientBuilder expectContinueBehavior(ExpectContinueOptions expectContinueOptions) {
613+
this.expectContinueOptions = expectContinueOptions;
614+
return this;
615+
}
616+
601617
/**
602618
* Sets the {@link SessionContext} used for session-based authentication by container and blob clients derived from
603619
* this service client.

‎sdk/storage/azure-storage-blob/src/main/java/com/azure/storage/blob/implementation/util/BuilderHelper.java‎

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
import com.azure.storage.common.implementation.StorageImplUtils;
4343
import com.azure.storage.common.implementation.credentials.CredentialValidator;
4444
import com.azure.storage.common.policy.DataLocalityPolicy;
45+
import com.azure.storage.common.policy.ExpectContinueOptions;
4546
import com.azure.storage.common.policy.MetadataValidationPolicy;
4647
import com.azure.storage.common.policy.RequestRetryOptions;
4748
import com.azure.storage.common.policy.ResponseValidationPolicyBuilder;
@@ -93,6 +94,8 @@ public final class BuilderHelper {
9394
* @param configuration Configuration store contain environment settings.
9495
* @param logger {@link ClientLogger} used to log any exception.
9596
* @param audience {@link BlobAudience} used to determine the audience of the blob.
97+
* @param expectContinueOptions {@link ExpectContinueOptions} used to determine when the HTTP header
98+
* {@code Expect: 100-continue} is applied to requests.
9699
* @param sessionContext {@link SessionContext} containing the session mode and optional acquisition configuration.
97100
* @param serviceVersion The service version for session creation; defaults to the latest version when null.
98101
* @return A new {@link HttpPipeline} from the passed values.
@@ -102,7 +105,8 @@ public static HttpPipeline buildPipeline(StorageSharedKeyCredential storageShare
102105
RequestRetryOptions retryOptions, RetryOptions coreRetryOptions, HttpLogOptions logOptions,
103106
ClientOptions clientOptions, HttpClient httpClient, List<HttpPipelinePolicy> perCallPolicies,
104107
List<HttpPipelinePolicy> perRetryPolicies, Configuration configuration, BlobAudience audience,
105-
ClientLogger logger, SessionContext sessionContext, BlobServiceVersion serviceVersion) {
108+
ExpectContinueOptions expectContinueOptions, ClientLogger logger, SessionContext sessionContext,
109+
BlobServiceVersion serviceVersion) {
106110

107111
CredentialValidator.validateCredentialsNotAmbiguous(storageSharedKeyCredential, tokenCredential,
108112
azureSasCredential, sasToken, logger);
@@ -139,6 +143,10 @@ public static HttpPipeline buildPipeline(StorageSharedKeyCredential storageShare
139143
policies.add(new StorageContentValidationEncodingPolicy());
140144
policies.add(new StorageContentValidationDecodingPolicy());
141145

146+
// Must be after the retry policy so it is evaluated on every attempt, and after content validation so the
147+
// Content-Length it reads is the encoded length actually sent. Before the credential policies.
148+
BuilderUtils.addExpectContinuePolicy(policies, expectContinueOptions, configuration);
149+
142150
if (storageSharedKeyCredential != null) {
143151
policies.add(new StorageSharedKeyCredentialPolicy(storageSharedKeyCredential));
144152
}
@@ -309,6 +317,7 @@ public static HttpLogOptions getDefaultHttpLogOptions() {
309317
HttpLogOptions defaultOptions = new HttpLogOptions();
310318
BlobHeadersAndQueryParameters.getBlobHeaders().forEach(defaultOptions::addAllowedHeaderName);
311319
BlobHeadersAndQueryParameters.getBlobQueryParameters().forEach(defaultOptions::addAllowedQueryParamName);
320+
defaultOptions.addAllowedHttpHeaderName(HttpHeaderName.EXPECT);
312321
return defaultOptions;
313322
}
314323

‎sdk/storage/azure-storage-blob/src/main/java/com/azure/storage/blob/specialized/SpecializedBlobClientBuilder.java‎

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
import com.azure.storage.common.implementation.connectionstring.StorageAuthenticationSettings;
4242
import com.azure.storage.common.implementation.connectionstring.StorageConnectionString;
4343
import com.azure.storage.common.implementation.connectionstring.StorageEndpoint;
44+
import com.azure.storage.common.policy.ExpectContinueOptions;
4445
import com.azure.storage.common.policy.RequestRetryOptions;
4546
import reactor.core.publisher.Flux;
4647

@@ -104,6 +105,7 @@ public final class SpecializedBlobClientBuilder implements TokenCredentialTrait<
104105
private Configuration configuration;
105106
private BlobServiceVersion version;
106107
private BlobAudience audience;
108+
private ExpectContinueOptions expectContinueOptions;
107109
private SessionContext sessionContext = new SessionContext();
108110

109111
/**
@@ -260,7 +262,8 @@ private HttpPipeline getHttpPipeline() {
260262
? httpPipeline
261263
: BuilderHelper.buildPipeline(storageSharedKeyCredential, tokenCredential, azureSasCredential, sasToken,
262264
endpoint, retryOptions, coreRetryOptions, logOptions, clientOptions, httpClient, perCallPolicies,
263-
perRetryPolicies, configuration, audience, LOGGER, sessionContext, getServiceVersion());
265+
perRetryPolicies, configuration, audience, expectContinueOptions, LOGGER, sessionContext,
266+
getServiceVersion());
264267
}
265268

266269
private BlobServiceVersion getServiceVersion() {
@@ -798,4 +801,18 @@ public SpecializedBlobClientBuilder audience(BlobAudience audience) {
798801
this.audience = audience;
799802
return this;
800803
}
804+
805+
/**
806+
* Sets the behavior for applying the HTTP header {@code Expect: 100-continue} to requests that carry a body.
807+
* <p>
808+
* The header is not applied unless this is set, and requires an HTTP client that withholds the request body
809+
* until the service responds.
810+
*
811+
* @param expectContinueOptions {@link ExpectContinueOptions} to be used when sending requests with a body.
812+
* @return the updated SpecializedBlobClientBuilder object
813+
*/
814+
public SpecializedBlobClientBuilder expectContinueBehavior(ExpectContinueOptions expectContinueOptions) {
815+
this.expectContinueOptions = expectContinueOptions;
816+
return this;
817+
}
801818
}

0 commit comments

Comments
 (0)