Skip to content

Commit d717011

Browse files
Merge pull request #26 from maxxedev/string-comparison
use .equals to compare strings
2 parents d312a29 + c5bc55b commit d717011

File tree

2 files changed

+14
-13
lines changed

2 files changed

+14
-13
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ repo/
2222
/.settings/
2323
/.classpath
2424
/.project
25+
/bin
2526

2627
# Environment files
27-
.env/*.*
28+
.env/*.*

src/main/java/com/sendgrid/Client.java

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import java.util.Map;
1111

1212
import org.apache.http.Header;
13+
import org.apache.http.HttpMessage;
1314
import org.apache.http.annotation.NotThreadSafe;
1415
import org.apache.http.client.ClientProtocolException;
1516
import org.apache.http.client.ResponseHandler;
@@ -201,9 +202,7 @@ public Response post(Request request) throws URISyntaxException, IOException {
201202
}
202203

203204
httpPost.setEntity(new StringEntity(request.getBody(), Charset.forName("UTF-8")));
204-
if (request.getBody() != "") {
205-
httpPost.setHeader("Content-Type", "application/json");
206-
}
205+
writeContentTypeIfNeeded(request, httpPost);
207206

208207
return executeApiCall(httpPost);
209208
}
@@ -230,9 +229,8 @@ public Response patch(Request request) throws URISyntaxException, IOException {
230229
}
231230

232231
httpPatch.setEntity(new StringEntity(request.getBody(), Charset.forName("UTF-8")));
233-
if (request.getBody() != "") {
234-
httpPatch.setHeader("Content-Type", "application/json");
235-
}
232+
writeContentTypeIfNeeded(request, httpPatch);
233+
236234
return executeApiCall(httpPatch);
237235
}
238236

@@ -258,9 +256,7 @@ public Response put(Request request) throws URISyntaxException, IOException {
258256
}
259257

260258
httpPut.setEntity(new StringEntity(request.getBody(), Charset.forName("UTF-8")));
261-
if (request.getBody() != "") {
262-
httpPut.setHeader("Content-Type", "application/json");
263-
}
259+
writeContentTypeIfNeeded(request, httpPut);
264260

265261
return executeApiCall(httpPut);
266262
}
@@ -286,13 +282,17 @@ public Response delete(Request request) throws URISyntaxException, IOException {
286282
}
287283

288284
httpDelete.setEntity(new StringEntity(request.getBody(), Charset.forName("UTF-8")));
289-
if (request.getBody() != "") {
290-
httpDelete.setHeader("Content-Type", "application/json");
291-
}
285+
writeContentTypeIfNeeded(request, httpDelete);
292286

293287
return executeApiCall(httpDelete);
294288
}
295289

290+
private void writeContentTypeIfNeeded(Request request, HttpMessage httpMessage) {
291+
if (!"".equals(request.getBody())) {
292+
httpMessage.setHeader("Content-Type", "application/json");
293+
}
294+
}
295+
296296
private Response executeApiCall(HttpRequestBase httpPost) throws IOException {
297297
try {
298298
CloseableHttpResponse serverResponse = httpClient.execute(httpPost);

0 commit comments

Comments
 (0)