Skip to content

Commit d44e42d

Browse files
committed
GH-5723: fix use of headers in mutable HttpRequest object
The HttpRequest is now mutable for headers, use the provided APIs to avoid creating new HttpRequest clone objects.
1 parent d7d2870 commit d44e42d

1 file changed

Lines changed: 6 additions & 24 deletions

File tree

core/http/client/src/main/java/org/eclipse/rdf4j/http/client/SPARQLProtocolSession.java

Lines changed: 6 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -752,11 +752,10 @@ private HttpResponse sendTupleQueryViaHttp(HttpRequest method, Set<QueryResultFo
752752
}
753753
}
754754

755-
HttpRequest methodWithAccept = withHeader(method, ACCEPT_PARAM_NAME,
756-
String.join(", ", acceptValues));
755+
method.addHeader(ACCEPT_PARAM_NAME, String.join(", ", acceptValues));
757756

758757
try {
759-
return executeOK(methodWithAccept);
758+
return executeOK(method);
760759
} catch (RepositoryException | MalformedQueryException | QueryInterruptedException e) {
761760
throw e;
762761
} catch (RDF4JException e) {
@@ -901,11 +900,10 @@ private HttpResponse sendGraphQueryViaHttp(HttpRequest method, boolean requireCo
901900

902901
List<String> acceptParams = RDFFormat.getAcceptParams(rdfFormats, requireContext, getPreferredRDFFormat());
903902

904-
HttpRequest methodWithAccept = withHeader(method, ACCEPT_PARAM_NAME,
905-
String.join(", ", acceptParams));
903+
method.addHeader(ACCEPT_PARAM_NAME, String.join(", ", acceptParams));
906904

907905
try {
908-
return executeOK(methodWithAccept);
906+
return executeOK(method);
909907
} catch (RepositoryException | MalformedQueryException | QueryInterruptedException e) {
910908
throw e;
911909
} catch (RDF4JException e) {
@@ -972,10 +970,9 @@ private HttpResponse sendBooleanQueryViaHttp(HttpRequest method, Set<QueryResult
972970
}
973971
}
974972

975-
HttpRequest methodWithAccept = withHeader(method, ACCEPT_PARAM_NAME,
976-
String.join(", ", acceptValues));
973+
method.addHeader(ACCEPT_PARAM_NAME, String.join(", ", acceptValues));
977974

978-
return executeOK(methodWithAccept);
975+
return executeOK(method);
979976
}
980977

981978
/**
@@ -1250,19 +1247,4 @@ public void setPassThroughEnabled(boolean passThroughEnabled) {
12501247
this.passThroughEnabled = passThroughEnabled;
12511248
}
12521249

1253-
/**
1254-
* Creates a new {@link HttpRequest} with an additional header added to the existing request.
1255-
*
1256-
* @param request the original request
1257-
* @param name the header name
1258-
* @param value the header value
1259-
* @return a new request with the additional header
1260-
*/
1261-
private static HttpRequest withHeader(HttpRequest request, String name, String value) {
1262-
HttpRequest.Builder builder = HttpRequest.newBuilder(request.getMethod(), request.getUri())
1263-
.headers(request.getHeaders())
1264-
.header(name, value);
1265-
request.getBody().ifPresent(builder::body);
1266-
return builder.build();
1267-
}
12681250
}

0 commit comments

Comments
 (0)