Исправлена обработка chunk transfer encoding для случаев, когда конец сообщения в отдельном пакете
This commit is contained in:
@@ -12,16 +12,15 @@ import org.springframework.web.socket.sockjs.SockJsTransportFailureException;
|
|||||||
import ru.serega6531.packmate.model.pojo.SubscriptionMessage;
|
import ru.serega6531.packmate.model.pojo.SubscriptionMessage;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
import java.util.concurrent.CopyOnWriteArrayList;
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
@Slf4j
|
@Slf4j
|
||||||
public class SubscriptionService {
|
public class SubscriptionService {
|
||||||
|
|
||||||
private final List<WebSocketSession> subscribers = Collections.synchronizedList(new ArrayList<>());
|
private final List<WebSocketSession> subscribers = new CopyOnWriteArrayList<>();
|
||||||
|
|
||||||
private final ObjectMapper mapper;
|
private final ObjectMapper mapper;
|
||||||
|
|
||||||
|
|||||||
@@ -58,7 +58,8 @@ public class HttpChunksProcessor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void checkCompleteChunk(List<Packet> packets, int start) {
|
private void checkCompleteChunk(List<Packet> packets, int start) {
|
||||||
boolean end = BytesUtils.endsWith(packets.get(packets.size() - 1).getContent(), "\r\n0\r\n\r\n".getBytes());
|
boolean end = Arrays.equals(packets.get(packets.size() - 1).getContent(), "0\r\n\r\n".getBytes()) ||
|
||||||
|
BytesUtils.endsWith(packets.get(packets.size() - 1).getContent(), "\r\n0\r\n\r\n".getBytes());
|
||||||
|
|
||||||
if (end) {
|
if (end) {
|
||||||
processChunk(packets, start);
|
processChunk(packets, start);
|
||||||
@@ -122,7 +123,7 @@ public class HttpChunksProcessor {
|
|||||||
int c1 = buf.get();
|
int c1 = buf.get();
|
||||||
int c2 = buf.get();
|
int c2 = buf.get();
|
||||||
|
|
||||||
if(c1 != '\r' || c2 != '\n') {
|
if (c1 != '\r' || c2 != '\n') {
|
||||||
log.warn("Failed to merge chunks, chunk trailer is not equal to \\r\\n");
|
log.warn("Failed to merge chunks, chunk trailer is not equal to \\r\\n");
|
||||||
resetChunk();
|
resetChunk();
|
||||||
return false;
|
return false;
|
||||||
@@ -162,7 +163,7 @@ public class HttpChunksProcessor {
|
|||||||
if ((b >= '0' && b <= '9') || (b >= 'a' && b <= 'f')) {
|
if ((b >= '0' && b <= '9') || (b >= 'a' && b <= 'f')) {
|
||||||
sb.append((char) b);
|
sb.append((char) b);
|
||||||
} else if (b == '\r') {
|
} else if (b == '\r') {
|
||||||
if(buf.get() == '\n') {
|
if (buf.get() == '\n') {
|
||||||
return Integer.parseInt(sb.toString(), 16);
|
return Integer.parseInt(sb.toString(), 16);
|
||||||
} else {
|
} else {
|
||||||
return -1; // после \r не идет \n
|
return -1; // после \r не идет \n
|
||||||
|
|||||||
Reference in New Issue
Block a user