Skip to content

Commit 4478658

Browse files
authored
fix(clojure): don't crash if there's no postData content (readmeio#171)
1 parent 9e044b4 commit 4478658

3 files changed

Lines changed: 41 additions & 1 deletion

File tree

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import type { Request } from '../../..';
2+
3+
import { runCustomFixtures } from '../../../fixtures/runCustomFixtures';
4+
5+
runCustomFixtures({
6+
targetId: 'clojure',
7+
clientId: 'clj_http',
8+
tests: [
9+
{
10+
it: 'should not crash if there is no `postData.text`',
11+
input: {
12+
headers: [
13+
{
14+
name: 'accept',
15+
value: 'application/json',
16+
},
17+
{
18+
name: 'content-type',
19+
value: 'application/json',
20+
},
21+
],
22+
postData: {
23+
mimeType: 'application/json',
24+
},
25+
bodySize: 0,
26+
method: 'POST',
27+
url: 'https://httpbin.org/anything',
28+
httpVersion: 'HTTP/1.1',
29+
} as Request,
30+
options: {},
31+
expected: 'should-not-crash.clj',
32+
},
33+
],
34+
});

src/targets/clojure/clj_http/client.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,9 @@ const jsType = (input?: any) => {
4545
};
4646

4747
const objEmpty = (input?: any) => {
48-
if (jsType(input) === 'object') {
48+
if (input === undefined) {
49+
return true;
50+
} else if (jsType(input) === 'object') {
4951
return Object.keys(input).length === 0;
5052
}
5153
return false;
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
(require '[clj-http.client :as client])
2+
3+
(client/post "https://httpbin.org/anything" {:content-type :json
4+
:accept :json})

0 commit comments

Comments
 (0)