Skip to content

Commit

Permalink
Use tryAdd when setting the Content-Type
Browse files Browse the repository at this point in the history
  • Loading branch information
andreaTP committed Oct 6, 2023
1 parent dc8f241 commit a3a5d3f
Showing 1 changed file with 5 additions and 5 deletions.
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

0 comments on commit a3a5d3f

Please sign in to comment.