diff --git a/californium-proxy2/src/main/java/org/eclipse/californium/proxy2/http/CrossProtocolTranslator.java b/californium-proxy2/src/main/java/org/eclipse/californium/proxy2/http/CrossProtocolTranslator.java index fb0360dd2b..2130b73efd 100644 --- a/californium-proxy2/src/main/java/org/eclipse/californium/proxy2/http/CrossProtocolTranslator.java +++ b/californium-proxy2/src/main/java/org/eclipse/californium/proxy2/http/CrossProtocolTranslator.java @@ -50,6 +50,7 @@ import org.eclipse.californium.core.coap.OptionNumberRegistry; import org.eclipse.californium.core.coap.OptionNumberRegistry.OptionFormat; import org.eclipse.californium.core.coap.OptionSet; +import org.eclipse.californium.core.coap.Response; import org.eclipse.californium.elements.util.Bytes; import org.eclipse.californium.elements.util.StringUtil; import org.eclipse.californium.proxy2.InvalidMethodException; @@ -407,7 +408,8 @@ public void setCoapPayload(ContentTypedEntity httpBody, Message coapMessage) thr byte[] payload = httpBody.getContent(); if (payload != null) { ContentType contentType = httpBody.getContentType(); - int coapContentType = getCoapMediaType(contentType.getMimeType()); + String mimeType = contentType.getMimeType(); + int coapContentType = getCoapMediaType(mimeType); coapMessage.getOptions().setContentFormat(coapContentType); if (MediaTypeRegistry.isCharsetConvertible(coapContentType)) { try { @@ -426,6 +428,26 @@ public void setCoapPayload(ContentTypedEntity httpBody, Message coapMessage) thr throw new TranslationException("Cannot get the content of the http entity", e); } } + if (payload.length > 256) { + if (coapMessage instanceof Response) { + if (!((Response) coapMessage).isSuccess()) { + if (ContentType.TEXT_HTML.getMimeType().equals(mimeType)) { + // blockwise is not supported for error responses + // https://github.com/core-wg/corrclar/issues/25 + // reduce payload size + String page = new String(payload, UTF_8); + int start = page.indexOf("
"); + if (start >= 0) { + int end = page.indexOf("", start); + if (end >= 0) { + page = page.substring(start + 6, end); + payload = page.getBytes(UTF_8); + } + } + } + } + } + } coapMessage.setPayload(payload); } } diff --git a/californium-proxy2/src/main/java/org/eclipse/californium/proxy2/resources/ProxyHttpClientResource.java b/californium-proxy2/src/main/java/org/eclipse/californium/proxy2/resources/ProxyHttpClientResource.java index d9db765698..a1b4d48bf4 100644 --- a/californium-proxy2/src/main/java/org/eclipse/californium/proxy2/resources/ProxyHttpClientResource.java +++ b/californium-proxy2/src/main/java/org/eclipse/californium/proxy2/resources/ProxyHttpClientResource.java @@ -156,13 +156,7 @@ public void completed(Message