Skip to content

Commit cb11b24

Browse files
authored
Merge pull request #27 from tinify/post-bug
Small fix on requests
2 parents 6d361c2 + 6ae3e57 commit cb11b24

File tree

4 files changed

+46
-3
lines changed

4 files changed

+46
-3
lines changed

CHANGES.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
## 1.8.3
2+
* Fix for requests with empty body
3+
14
## 1.8.2
25
* Fixed Import-Package manifest for OSGI deployments
36

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<modelVersion>4.0.0</modelVersion>
44
<groupId>com.tinify</groupId>
55
<artifactId>tinify</artifactId>
6-
<version>1.8.2</version>
6+
<version>1.8.3</version>
77
<name>Tinify</name>
88
<description>Java client for the Tinify API. Tinify compresses your images intelligently. Read more at https://tinify.com.</description>
99
<url>https://tinify.com</url>

src/main/java/com/tinify/Source.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ public final ResultMeta store(final Options options) {
5252

5353
public final Result result() throws IOException {
5454
Client.Response response;
55-
if (commands == null) {
55+
if (commands == null || commands.isEmpty()) {
5656
response = Tinify.client().request(Client.Method.GET, url);
5757
} else {
5858
response = Tinify.client().request(Client.Method.POST, url, commands);

src/test/java/com/tinify/SourceTest.java

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -516,4 +516,44 @@ public void withValidApiKeyToFileShouldStoreImageData() throws Exception, IOExce
516516
assertThat(Files.readAllBytes(tempFile),
517517
is(equalTo("compressed file".getBytes())));
518518
}
519-
}
519+
520+
521+
/*
522+
* The following tests should probably be done with parametrized tests
523+
*/
524+
@Test
525+
public void withOptionsNotEmptyResultDoesAPOST() throws Exception, IOException, InterruptedException {
526+
Tinify.setKey("valid");
527+
528+
server.enqueue(new MockResponse()
529+
.setResponseCode(200)
530+
.setBody("compressed file"));
531+
Result result = new Source("https://api.tinify.com/some/location", new Options().with("I am not", "empty")).result();
532+
RecordedRequest outputRequest = server.takeRequest(1, TimeUnit.SECONDS);
533+
assertEquals("POST", outputRequest.getMethod());
534+
}
535+
536+
@Test
537+
public void withOptionsNULLResultDoesAGET() throws Exception, IOException, InterruptedException {
538+
Tinify.setKey("valid");
539+
540+
server.enqueue(new MockResponse()
541+
.setResponseCode(200)
542+
.setBody("compressed file"));
543+
Result result = new Source("https://api.tinify.com/some/location", null).result();
544+
RecordedRequest outputRequest = server.takeRequest(1, TimeUnit.SECONDS);
545+
assertEquals("GET", outputRequest.getMethod());
546+
}
547+
548+
@Test
549+
public void withOptionsEmptyResultDoesAGET() throws Exception, IOException, InterruptedException {
550+
Tinify.setKey("valid");
551+
552+
server.enqueue(new MockResponse()
553+
.setResponseCode(200)
554+
.setBody("compressed file"));
555+
Result result = new Source("https://api.tinify.com/some/location", new Options()).result();
556+
RecordedRequest outputRequest = server.takeRequest(1, TimeUnit.SECONDS);
557+
assertEquals("GET", outputRequest.getMethod());
558+
}
559+
}

0 commit comments

Comments
 (0)