-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Add Custom Header - In AddHeaderPolicy and RequestIDPolicy #6602
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
Merged
hemanttanwar
merged 10 commits into
Azure:master
from
hemanttanwar:6217_RequestID_AddHeaderPolicy_customHeader
Dec 9, 2019
Merged
Changes from 4 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
eccfbf6
initial design
5e650a6
Adding OverrideHeaderPolicy as discussed.
bf58b5d
Adding more documentation and validations.
f7d4359
Renamed OverrideHeaderPolicy to AddHeadersFromContextPolicy and reso…
04c34a2
Adding unit test and incorporating review comments.
ecbc5dc
fix checkstyle issue in Java snippet
5c87630
Incorporating review comments
231a5da
Adding code anipper for new policy and incorporating review comments.
1bc9a6a
Adding code sample in new policy
5ac3436
Removed changes in ConfigurationClientTest .
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
44 changes: 44 additions & 0 deletions
44
...core/azure-core/src/main/java/com/azure/core/http/policy/AddHeadersFromContextPolicy.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| // Copyright (c) Microsoft Corporation. All rights reserved. | ||
| // Licensed under the MIT License. | ||
|
|
||
| package com.azure.core.http.policy; | ||
|
|
||
| import com.azure.core.http.HttpHeader; | ||
| import com.azure.core.http.HttpHeaders; | ||
| import com.azure.core.http.HttpPipelineCallContext; | ||
| import com.azure.core.http.HttpPipelineNextPolicy; | ||
| import com.azure.core.http.HttpResponse; | ||
| import com.azure.core.util.Context; | ||
| import com.azure.core.http.HttpRequest; | ||
| import static com.azure.core.util.Context.AZURE_REQUEST_HTTP_HEADERS_KEY; | ||
| import reactor.core.publisher.Mono; | ||
|
|
||
| import java.util.Objects; | ||
| import java.util.Optional; | ||
|
|
||
| /** | ||
| * The pipeline policy that override or add {@link HttpHeaders} in {@link HttpRequest} by reading values from | ||
| * {@link Context} with key 'azure-request-override-http-headers-key'. The value for this key should be of type | ||
hemanttanwar marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| * {@link HttpHeaders} for it to be added in {@link HttpRequest}. | ||
| */ | ||
hemanttanwar marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| public class AddHeadersFromContextPolicy implements HttpPipelinePolicy { | ||
hemanttanwar marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| @Override | ||
| public Mono<HttpResponse> process(HttpPipelineCallContext context, HttpPipelineNextPolicy next) { | ||
|
|
||
| Optional<Object> customHttpHeadersObject = context.getData(AZURE_REQUEST_HTTP_HEADERS_KEY); | ||
| if (customHttpHeadersObject.isPresent() | ||
| && customHttpHeadersObject.get() instanceof HttpHeaders) { | ||
|
|
||
| HttpHeaders customHttpHeaders = (HttpHeaders) customHttpHeadersObject.get(); | ||
hemanttanwar marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| // loop through customHttpHeaders and add headers in HttpRequest | ||
| for (HttpHeader httpHeader : customHttpHeaders) { | ||
| if (!Objects.isNull(httpHeader.getName()) && !Objects.isNull(httpHeader.getValue())) { | ||
| context.getHttpRequest().getHeaders().put(httpHeader.getName(), httpHeader.getValue()); | ||
| } | ||
| } | ||
| } | ||
| return next.process(); | ||
|
|
||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 20 additions & 0 deletions
20
...e-core/src/samples/java/com/azure/core/http/policy/RequestIdPolicyJavaDocCodeSnippet.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| // Copyright (c) Microsoft Corporation. All rights reserved. | ||
| // Licensed under the MIT License. | ||
|
|
||
| package com.azure.core.http.policy; | ||
|
|
||
| /** | ||
| * Code snippets for {@link RequestIdPolicy} | ||
| */ | ||
| public class RequestIdPolicyJavaDocCodeSnippet { | ||
|
|
||
| /** | ||
| * Code snippets for using {@link RequestIdPolicy#RequestIdPolicy(String)} } | ||
| */ | ||
| public void overrideRequestIdHeaderName() { | ||
|
|
||
| // BEGIN: com.azure.core.http.policy.RequestIdPolicy.constructor.overrideRequestIdHeaderName | ||
| RequestIdPolicy requestIdPolicy = new RequestIdPolicy("x-ms-my-custom-request-id"); | ||
| // END: com.azure.core.http.policy.RequestIdPolicy.constructor.overrideRequestIdHeaderName | ||
| } | ||
| } |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.