Skip to content

Commit 0004ab2

Browse files
authored
fix(coap-core): add mapping for 204 http status to C205_CONTENT code (#129)
1 parent 9cafc41 commit 0004ab2

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

coap-core/src/main/java/com/mbed/coap/packet/Code.java

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ public boolean isSuccess() {
106106
return coapCode >>> 5 == 2;
107107
}
108108

109+
@SuppressWarnings("PMD.NcssCount")
109110
public static Code fromHttp(int httpStatus, Method method) {
110111

111112
switch (httpStatus) {
@@ -127,11 +128,15 @@ public static Code fromHttp(int httpStatus, Method method) {
127128
case 201:
128129
return C201_CREATED;
129130
case 204:
130-
if (method == Method.DELETE) {
131-
return C202_DELETED;
131+
switch (method) {
132+
case GET:
133+
case FETCH:
134+
return C205_CONTENT;
135+
case DELETE:
136+
return C202_DELETED;
137+
default:
138+
return C204_CHANGED;
132139
}
133-
return C204_CHANGED;
134-
135140

136141
// REDIRECT (3.xx)
137142
case 304:

coap-core/src/test/java/com/mbed/coap/packet/CodeTest.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ public void shouldConvertHttpToCoapCode() {
112112
assertEquals(Code.C201_CREATED, fromHttp(202, POST));
113113
assertEquals(Code.C202_DELETED, fromHttp(202, DELETE));
114114
assertEquals(Code.C202_DELETED, fromHttp(204, DELETE));
115+
assertEquals(Code.C205_CONTENT, fromHttp(204, GET));
115116

116117
assertEquals(Code.C203_VALID, fromHttp(304, GET));
117118

0 commit comments

Comments
 (0)