Scoop API

scoop:scoop.http.client:0.1.0

src/resume/api.scoop

Selected production source · src/resume/api.scoop

1package scoop.http.client
3import scoop.http.HttpResponseHead
4import scoop.platform.fs.Path
6/**
7 * The response to incompatible or unusable partial-download metadata.
8 */
9public enum HttpResumeMismatch {
10 /**
11 * Restarts from a fresh representation when safe continuation cannot be established.
12 */
13 Restart,
14 /**
15 * Reports the mismatch instead of restarting.
16 */
17 Fail
20/**
21 * The condition preventing safe byte-range continuation.
22 */
23public enum HttpResumeFailureReason {
24 /**
25 * The partial file has no usable companion metadata.
26 */
27 MissingMetadata,
28 /**
29 * Saved resume metadata is malformed or exceeds its limits.
30 */
31 InvalidMetadata,
32 /**
33 * The saved response has no reliable validator for continuation.
34 */
35 UnreliableValidator,
36 /**
37 * The current request no longer matches the saved download identity.
38 */
39 RequestChanged,
40 /**
41 * The server representation or validator differs from the saved one.
42 */
43 RepresentationChanged,
44 /**
45 * The response range does not agree with the requested continuation.
46 */
47 InvalidRange,
48 /**
49 * The response ended before the promised range was complete.
50 */
51 IncompleteRange,
52 /**
53 * The response status cannot complete the selected resume operation.
54 */
55 UnexpectedStatus
58/**
59 * Explicit partial-file and metadata paths, mismatch policy, and metadata size bound. The two
60 * paths must differ.
61 */
62public class HttpResumeOptions internal constructor(
63 /**
64 * The explicit path retaining incomplete representation bytes.
65 */
66 public val partialFile: Path,
67 /**
68 * The distinct path retaining validation metadata.
69 */
70 public val metadataFile: Path,
71 /**
72 * Whether unusable resume state causes restart or failure.
73 */
74 public val mismatch: HttpResumeMismatch = HttpResumeMismatch.Restart,
75 /**
76 * The positive limit on resume metadata input bytes.
77 */
78 public val maxMetadataBytes: Long = 65536L
79) {
80 init {
81 if (maxMetadataBytes <= 0L)
82 throw IllegalArgumentException(Some("resume metadata limit must be positive"))
83 if (partialFile.normalizeLexically() == metadataFile.normalizeLexically())
84 throw IllegalArgumentException(Some("resume data and metadata need different paths"))
85 }
88/**
89 * A continuation failure with a precise category, explanation, and optional response/cause.
90 */
91public class HttpResumeException public constructor(
92 /**
93 * The continuation failure category.
94 */
95 public val reason: HttpResumeFailureReason,
96 /**
97 * The mismatch explanation.
98 */
99 public val detail: String,
100 /**
101 * The response head involved, when available.
102 */
103 public val head: HttpResponseHead? = None,
104 /**
105 * The underlying I/O or validation failure, when available.
106 */
107 public val cause: Throwable? = None
108): Exception(Some(detail))