Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions coap-core/src/main/java/com/mbed/coap/packet/Code.java
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ public boolean isSuccess() {
return coapCode >>> 5 == 2;
}

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

switch (httpStatus) {
Expand All @@ -127,11 +128,15 @@ public static Code fromHttp(int httpStatus, Method method) {
case 201:
return C201_CREATED;
case 204:
if (method == Method.DELETE) {
return C202_DELETED;
switch (method) {
case GET:
case FETCH:
return C205_CONTENT;
case DELETE:
return C202_DELETED;
default:
return C204_CHANGED;
}
return C204_CHANGED;


// REDIRECT (3.xx)
case 304:
Expand Down
1 change: 1 addition & 0 deletions coap-core/src/test/java/com/mbed/coap/packet/CodeTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ public void shouldConvertHttpToCoapCode() {
assertEquals(Code.C201_CREATED, fromHttp(202, POST));
assertEquals(Code.C202_DELETED, fromHttp(202, DELETE));
assertEquals(Code.C202_DELETED, fromHttp(204, DELETE));
assertEquals(Code.C205_CONTENT, fromHttp(204, GET));

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

Expand Down
Loading