Skip to content

Commit

Permalink
Merge pull request #683 from andreaTP/use-tryadd
Browse files Browse the repository at this point in the history
Use tryAdd when setting the Content-Type
  • Loading branch information
baywet authored Oct 6, 2023
2 parents dc8f241 + 0f73f38 commit b51afcc
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 6 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Added

## [0.7.6] - 2023-10-09

### Changed

- Use `tryAdd` instead of `add` in all of the `setContentFrom...` methods

## [0.7.5] - 2023-10-04

### Added
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ public void setResponseHandler(@Nonnull ResponseHandler responseHandler) {
public void setStreamContent(@Nonnull final InputStream value) {
Objects.requireNonNull(value);
this.content = value;
headers.add(CONTENT_TYPE_HEADER, BINARY_CONTENT_TYPE);
headers.tryAdd(CONTENT_TYPE_HEADER, BINARY_CONTENT_TYPE);
}
private static final String SERIALIZE_ERROR = "could not serialize payload";
private static final String SPAN_NAME = "setContentFromParsable";
Expand All @@ -217,7 +217,7 @@ public <T extends Parsable> void setContentFromParsable(@Nonnull final RequestAd
final Span span = GlobalOpenTelemetry.getTracer(OBSERVABILITY_TRACER_NAME).spanBuilder(SPAN_NAME).startSpan();
try (final Scope scope = span.makeCurrent()) {
try(final SerializationWriter writer = getSerializationWriter(requestAdapter, contentType, values)) {
headers.add(CONTENT_TYPE_HEADER, contentType);
headers.tryAdd(CONTENT_TYPE_HEADER, contentType);
if (values.length > 0) {
setRequestType(values[0], span);
}
Expand Down Expand Up @@ -249,7 +249,7 @@ public <T extends Parsable> void setContentFromParsable(@Nonnull final RequestAd
effectiveContentType += "; boundary=" + multipartBody.getBoundary();
multipartBody.requestAdapter = requestAdapter;
}
headers.add(CONTENT_TYPE_HEADER, effectiveContentType);
headers.tryAdd(CONTENT_TYPE_HEADER, effectiveContentType);
setRequestType(value, span);
writer.writeObjectValue(null, value);
this.content = writer.getSerializedContent();
Expand Down Expand Up @@ -286,7 +286,7 @@ public <T> void setContentFromScalar(@Nonnull final RequestAdapter requestAdapte
final Span span = GlobalOpenTelemetry.getTracer(OBSERVABILITY_TRACER_NAME).spanBuilder(SPAN_NAME).startSpan();
try (final Scope scope = span.makeCurrent()) {
try(final SerializationWriter writer = getSerializationWriter(requestAdapter, contentType, value)) {
headers.add(CONTENT_TYPE_HEADER, contentType);
headers.tryAdd(CONTENT_TYPE_HEADER, contentType);
setRequestType(value, span);
final Class<?> valueClass = value.getClass();
if(valueClass.equals(String.class))
Expand Down Expand Up @@ -341,7 +341,7 @@ public <T> void setContentFromScalarCollection(@Nonnull final RequestAdapter req
final Span span = GlobalOpenTelemetry.getTracer(OBSERVABILITY_TRACER_NAME).spanBuilder(SPAN_NAME).startSpan();
try (final Scope scope = span.makeCurrent()) {
try(final SerializationWriter writer = getSerializationWriter(requestAdapter, contentType, values)) {
headers.add(CONTENT_TYPE_HEADER, contentType);
headers.tryAdd(CONTENT_TYPE_HEADER, contentType);
if (values.length > 0)
setRequestType(values[0], span);
writer.writeCollectionOfPrimitiveValues(null, Arrays.asList(values));
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ org.gradle.caching=true
mavenGroupId = com.microsoft.kiota
mavenMajorVersion = 0
mavenMinorVersion = 7
mavenPatchVersion = 5
mavenPatchVersion = 6
mavenArtifactSuffix =

#These values are used to run functional tests
Expand Down

0 comments on commit b51afcc

Please sign in to comment.