Updated to latest Protocol Version
This commit is contained in:
@@ -11,7 +11,7 @@ import org.openautonomousconnection.protocol.urlhandler.v1_0_1.beta.web.WebReque
|
||||
import org.openautonomousconnection.protocol.versions.v1_0_1.beta.WebPacketHeader;
|
||||
import org.openautonomousconnection.webclient.ui.BrowserTab;
|
||||
|
||||
import java.awt.Component;
|
||||
import java.awt.*;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.net.URL;
|
||||
import java.util.Map;
|
||||
@@ -85,6 +85,70 @@ public final class ClientImpl extends ProtocolClient {
|
||||
}
|
||||
}
|
||||
|
||||
private record StreamKey(long requestId, long tabId, long pageId, long frameId) {
|
||||
|
||||
StreamKey(WebPacketHeader h) {
|
||||
this(h.getRequestId(), h.getTabId(), h.getPageId(), h.getFrameId());
|
||||
}
|
||||
}
|
||||
|
||||
private static final class StreamState {
|
||||
|
||||
private final int statusCode;
|
||||
private final String contentType;
|
||||
private final Map<String, String> headers;
|
||||
private final long declaredLength;
|
||||
|
||||
private final ByteArrayOutputStream buffer = new ByteArrayOutputStream();
|
||||
private int expectedSeq = 0;
|
||||
private long written = 0;
|
||||
private boolean ended = false;
|
||||
private boolean ok = true;
|
||||
|
||||
StreamState(int statusCode,
|
||||
String contentType,
|
||||
Map<String, String> headers,
|
||||
long declaredLength) {
|
||||
|
||||
this.statusCode = statusCode;
|
||||
this.contentType = contentType == null ? "application/octet-stream" : contentType;
|
||||
this.headers = headers == null ? Map.of() : Map.copyOf(headers);
|
||||
this.declaredLength = declaredLength;
|
||||
}
|
||||
|
||||
void append(int seq, byte[] data) {
|
||||
|
||||
if (ended) throw new IllegalStateException("Chunk after end");
|
||||
if (seq != expectedSeq) throw new IllegalStateException("Out-of-order chunk");
|
||||
|
||||
expectedSeq++;
|
||||
|
||||
if (data == null || data.length == 0) return;
|
||||
|
||||
written += data.length;
|
||||
if (written > MAX_STREAM_BYTES)
|
||||
throw new IllegalStateException("Stream exceeds limit");
|
||||
|
||||
buffer.writeBytes(data);
|
||||
}
|
||||
|
||||
void markEnd(boolean ok, String error) {
|
||||
this.ended = true;
|
||||
this.ok = ok;
|
||||
}
|
||||
|
||||
byte[] finish() {
|
||||
if (!ok) return new byte[0];
|
||||
byte[] data = buffer.toByteArray();
|
||||
|
||||
if (declaredLength > 0 && data.length != declaredLength) {
|
||||
// tolerated but can log if needed
|
||||
}
|
||||
|
||||
return data;
|
||||
}
|
||||
}
|
||||
|
||||
public final class LibImpl extends LibClientImpl_v1_0_1_B {
|
||||
|
||||
private final WebRequestContextProvider provider = new WebRequestContextProvider.Default();
|
||||
@@ -176,68 +240,4 @@ public final class ClientImpl extends ProtocolClient {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private record StreamKey(long requestId, long tabId, long pageId, long frameId) {
|
||||
|
||||
StreamKey(WebPacketHeader h) {
|
||||
this(h.getRequestId(), h.getTabId(), h.getPageId(), h.getFrameId());
|
||||
}
|
||||
}
|
||||
|
||||
private static final class StreamState {
|
||||
|
||||
private final int statusCode;
|
||||
private final String contentType;
|
||||
private final Map<String, String> headers;
|
||||
private final long declaredLength;
|
||||
|
||||
private final ByteArrayOutputStream buffer = new ByteArrayOutputStream();
|
||||
private int expectedSeq = 0;
|
||||
private long written = 0;
|
||||
private boolean ended = false;
|
||||
private boolean ok = true;
|
||||
|
||||
StreamState(int statusCode,
|
||||
String contentType,
|
||||
Map<String, String> headers,
|
||||
long declaredLength) {
|
||||
|
||||
this.statusCode = statusCode;
|
||||
this.contentType = contentType == null ? "application/octet-stream" : contentType;
|
||||
this.headers = headers == null ? Map.of() : Map.copyOf(headers);
|
||||
this.declaredLength = declaredLength;
|
||||
}
|
||||
|
||||
void append(int seq, byte[] data) {
|
||||
|
||||
if (ended) throw new IllegalStateException("Chunk after end");
|
||||
if (seq != expectedSeq) throw new IllegalStateException("Out-of-order chunk");
|
||||
|
||||
expectedSeq++;
|
||||
|
||||
if (data == null || data.length == 0) return;
|
||||
|
||||
written += data.length;
|
||||
if (written > MAX_STREAM_BYTES)
|
||||
throw new IllegalStateException("Stream exceeds limit");
|
||||
|
||||
buffer.writeBytes(data);
|
||||
}
|
||||
|
||||
void markEnd(boolean ok, String error) {
|
||||
this.ended = true;
|
||||
this.ok = ok;
|
||||
}
|
||||
|
||||
byte[] finish() {
|
||||
if (!ok) return new byte[0];
|
||||
byte[] data = buffer.toByteArray();
|
||||
|
||||
if (declaredLength > 0 && data.length != declaredLength) {
|
||||
// tolerated but can log if needed
|
||||
}
|
||||
|
||||
return data;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user