Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/omega-mv/blob/main/aienux/allen/http.om # omega-mv Omega: a language for verified programs, semantic identity and machine realization. Seed-born work and existing implementations have distinct provenance. Brought by drakestapleton Sign in to star 1 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `main` Branches Tags History `omega-mv / aienux / allen / http.om` 495 lines ยท 6914 bytes Raw Blame History 1 note SPDX-License-Identifier: MIT 2 note HTTP/1.1 framing for one authenticated api.github.com connection, RFC 9110/9112. 3 note Only TLS-authenticated plaintext enters Hchunk. No redirects, compression or pipelining. 4 global Httpreq uchar 8192 5 global Httpreqn ulong 1 6 global Hchunk uchar 16384 7 global Hstate ulong 8 8 global Hline uchar 8192 9 global Hp ulong 16 10 text Hget "GET " 11 text Htail " HTTP/1.1\nHost: api.github.com\nUser-Agent: Allen-Omega/1.0\nAccept-Encoding: identity\nX-GitHub-Api-Version: 2022-11-28\nConnection: close\nAccept: " 12 text Hjson "application/vnd.github+json" 13 text Hraw "application/vnd.github.raw+json" 14 text Hver "HTTP/1.1 " 15 text Hcl "content-length" 16 text Hte "transfer-encoding" 17 text Hce "content-encoding" 18 text Hckword "chunked" 19 text Hident "identity" 20 text Htokens "!#$%&'*+-.^_`|~" 21 note Hstate: state(0idle,1reading,2done,3error),status,body bytes,generation,kind,error. 22 note Hp: phase,line bytes,CR pending,header bytes,CL present,CL,TE,remaining,maxbody,interim. 23 fn hplower c uchar to uchar 24 if and ge c 65 le c 90 25 ret uchar add ulong c 32 26 end 27 ret c 28 end 29 fn hpkw kind ulong at ulong to uchar 30 if eq kind 0 31 ret get Hcl at 32 end 33 if eq kind 1 34 ret get Hte at 35 end 36 if eq kind 2 37 ret get Hce at 38 end 39 if eq kind 3 40 ret get Hckword at 41 end 42 ret get Hident at 43 end 44 fn hpeq at ulong n ulong kind ulong size ulong to bool 45 if ne n size 46 ret false 47 end 48 for i ulong size 49 if ne hplower get Hline add at i hpkw kind i 50 ret false 51 end 52 end 53 ret true 54 end 55 fn hpfail code ulong to void 56 put Hstate 0 3 57 put Hstate 5 code 58 put Hstate 2 0 59 put Httpreqn 0 0 60 put Hp 0 10 61 end 62 fn hpemit c uchar to void 63 n = get Httpreqn 0 64 if ge n len Httpreq 65 hpfail 1 66 ret 67 end 68 put Httpreq n c 69 put Httpreqn 0 add n 1 70 end 71 fn hpcrlf to void 72 hpemit 13 73 hpemit 10 74 end 75 fn httpstart kind ulong gen ulong mode ulong maxbody ulong pathlen ulong to bool 76 for i ulong 16 77 put Hp i 0 78 end 79 for i ulong 8 80 put Hstate i 0 81 end 82 put Httpreqn 0 0 83 if or or eq pathlen 0 ge pathlen len Ghpath gt maxbody len Ghbody 84 hpfail 2 85 ret false 86 end 87 if or gt mode 1 ne get Ghpath 0 47 88 hpfail 2 89 ret false 90 end 91 for i ulong pathlen 92 c = get Ghpath i 93 if or or le c 32 ge c 127 eq c 35 94 hpfail 2 95 ret false 96 end 97 end 98 for i ulong len Hget 99 hpemit get Hget i 100 end 101 for i ulong pathlen 102 hpemit get Ghpath i 103 end 104 for i ulong len Htail 105 c = get Htail i 106 if eq c 10 107 hpcrlf 108 else 109 hpemit c 110 end 111 end 112 if eq mode 0 113 for i ulong len Hjson 114 hpemit get Hjson i 115 end 116 else 117 for i ulong len Hraw 118 hpemit get Hraw i 119 end 120 end 121 hpcrlf 122 hpcrlf 123 if eq get Hstate 0 3 124 ret false 125 end 126 put Hstate 0 1 127 put Hstate 3 gen 128 put Hstate 4 kind 129 put Hp 8 maxbody 130 ret true 131 end 132 fn hptoken c uchar to bool 133 if or or and ge c 65 le c 90 and ge c 97 le c 122 and ge c 48 le c 57 134 ret true 135 end 136 for i ulong len Htokens 137 if eq c get Htokens i 138 ret true 139 end 140 end 141 ret false 142 end 143 fn hpfinish to void 144 put Hp 0 9 145 put Hstate 0 2 146 end 147 fn hpstatus to void 148 n = get Hp 1 149 if lt n 12 150 hpfail 3 151 ret 152 end 153 for i ulong len Hver 154 if ne get Hline i get Hver i 155 hpfail 3 156 ret 157 end 158 end 159 s = ulong 0 160 for i ulong 3 161 c = get Hline add i 9 162 if or lt c 48 gt c 57 163 hpfail 3 164 ret 165 end 166 s = add mul s 10 sub ulong c 48 167 end 168 if or lt s 100 gt s 599 169 hpfail 3 170 ret 171 end 172 if gt n 12 173 if ne get Hline 12 32 174 hpfail 3 175 ret 176 end 177 end 178 put Hstate 1 s 179 put Hp 0 1 180 end 181 fn hpheadersend to void 182 s = get Hstate 1 183 if lt s 200 184 if or or eq s 101 gt get Hp 9 2 ne get Hp 6 0 185 hpfail 4 186 ret 187 end 188 if and ne get Hp 4 0 ne get Hp 5 0 189 hpfail 4 190 ret 191 end 192 put Hp 9 add get Hp 9 1 193 put Hp 0 0 194 put Hp 4 0 195 put Hp 5 0 196 put Hp 6 0 197 ret 198 end 199 if and ne get Hp 4 0 ne get Hp 6 0 200 hpfail 5 201 ret 202 end 203 if or eq s 204 eq s 304 204 if or ne get Hp 6 0 and ne get Hp 4 0 ne get Hp 5 0 205 hpfail 5 206 else 207 hpfinish 208 end 209 ret 210 end 211 if ne get Hp 6 0 212 put Hp 0 3 213 ret 214 end 215 if ne get Hp 4 0 216 put Hp 7 get Hp 5 217 if eq get Hp 7 0 218 hpfinish 219 else 220 put Hp 0 2 221 end 222 ret 223 end 224 note Close-delimited bodies complete only after authenticated TLS close_notify via httpend. 225 put Hp 0 8 226 end 227 fn hpdecimal at ulong stop ulong to bool 228 v = ulong 0 229 for i ulong sub stop at 230 c = get Hline add at i 231 if or lt c 48 gt c 57 232 ret false 233 end 234 d = sub ulong c 48 235 if gt v div get Hp 8 10 236 ret false 237 end 238 v = add mul v 10 d 239 if gt v get Hp 8 240 ret false 241 end 242 end 243 put Hp 5 v 244 ret true 245 end 246 fn hpheader trailer bool to void 247 n = get Hp 1 248 if eq n 0 249 if trailer 250 hpfinish 251 else 252 hpheadersend 253 end 254 ret 255 end 256 p = ulong 0 257 while lt p n 258 if eq get Hline p 58 259 break 260 end 261 if not hptoken get Hline p 262 hpfail 6 263 ret 264 end 265 p = add p 1 266 end 267 if or eq p 0 eq p n 268 hpfail 6 269 ret 270 end 271 beg = add p 1 272 stop = n 273 while lt beg stop 274 c = get Hline beg 275 if and ne c 32 ne c 9 276 break 277 end 278 beg = add beg 1 279 end 280 while gt stop beg 281 c = get Hline sub stop 1 282 if and ne c 32 ne c 9 283 break 284 end 285 stop = sub stop 1 286 end 287 cl = hpeq 0 p 0 14 288 te = hpeq 0 p 1 17 289 ce = hpeq 0 p 2 16 290 if trailer 291 if or or cl te ce 292 hpfail 7 293 end 294 ret 295 end 296 if cl 297 if or ne get Hp 4 0 eq beg stop 298 hpfail 5 299 ret 300 end 301 if not hpdecimal beg stop 302 hpfail 8 303 ret 304 end 305 put Hp 4 1 306 end 307 if te 308 if or ne get Hp 6 0 not hpeq beg sub stop beg 3 7 309 hpfail 5 310 ret 311 end 312 put Hp 6 1 313 end 314 if ce 315 if not hpeq beg sub stop beg 4 8 316 hpfail 9 317 end 318 end 319 end 320 fn hphex c uchar to ulong 321 if and ge c 48 le c 57 322 ret sub ulong c 48 323 end 324 x = hplower c 325 if and ge x 97 le x 102 326 ret sub ulong x 87 327 end 328 ret 16 329 end 330 fn hpchunkline to void 331 n = get Hp 1 332 v = ulong 0 333 p = ulong 0 334 while lt p n 335 c = get Hline p 336 if eq c 59 337 break 338 end 339 d = hphex c 340 if or ge d 16 gt v div get Hp 8 16 341 hpfail 10 342 ret 343 end 344 v = add mul v 16 d 345 if gt v sub get Hp 8 get Hstate 2 346 hpfail 8 347 ret 348 end 349 p = add p 1 350 end 351 if eq p 0 352 hpfail 10 353 ret 354 end 355 if and lt p n eq add p 1 n 356 hpfail 10 357 ret 358 end 359 put Hp 7 v 360 if eq v 0 361 put Hp 0 7 362 else 363 put Hp 0 4 364 end 365 end 366 fn hplineend to void 367 p = get Hp 0 368 if eq p 0 369 hpstatus 370 else 371 if eq p 1 372 hpheader false 373 else 374 if eq p 3 375 hpchunkline 376 else 377 if eq p 7 378 hpheader true 379 else 380 hpfail 11 381 end 382 end 383 end 384 end 385 put Hp 1 0 386 put Hp 2 0 387 end 388 fn hplinebyte c uchar to void 389 put Hp 3 add get Hp 3 1 390 if gt get Hp 3 65536 391 hpfail 12 392 ret 393 end 394 if ne get Hp 2 0 395 if ne c 10 396 hpfail 6 397 else 398 hplineend 399 end 400 ret 401 end 402 if eq c 13 403 put Hp 2 1 404 ret 405 end 406 if or or eq c 10 and lt c 32 ne c 9 eq c 127 407 hpfail 6 408 ret 409 end 410 n = get Hp 1 411 if ge n len Hline 412 hpfail 12 413 ret 414 end 415 put Hline n c 416 put Hp 1 add n 1 417 end 418 fn hpbody c uchar to void 419 n = get Hstate 2 420 if ge n get Hp 8 421 hpfail 8 422 ret 423 end 424 put Ghbody n c 425 put Hstate 2 add n 1 426 phase = get Hp 0 427 if or eq phase 2 eq phase 4 428 left = sub get Hp 7 1 429 put Hp 7 left 430 if eq left 0 431 if eq phase 2 432 hpfinish 433 else 434 put Hp 0 5 435 end 436 end 437 end 438 end 439 fn httpfeed n ulong to bool 440 if or gt n len Hchunk and eq get Hstate 0 2 ne n 0 441 hpfail 13 442 ret false 443 end 444 if ne get Hstate 0 1 445 ret false 446 end 447 for i ulong n 448 c = get Hchunk i 449 phase = get Hp 0 450 if or or eq phase 0 eq phase 1 or eq phase 3 eq phase 7 451 hplinebyte c 452 else 453 if or or eq phase 2 eq phase 4 eq phase 8 454 hpbody c 455 else 456 if eq phase 5 457 if eq c 13 458 put Hp 0 6 459 else 460 hpfail 10 461 end 462 else 463 if eq phase 6 464 if eq c 10 465 put Hp 0 3 466 else 467 hpfail 10 468 end 469 else 470 hpfail 13 471 end 472 end 473 end 474 end 475 if eq get Hstate 0 3 476 ret false 477 end 478 end 479 ret true 480 end 481 fn httpend auth bool to bool 482 if not auth 483 hpfail 14 484 ret false 485 end 486 if eq get Hstate 0 2 487 ret true 488 end 489 if and eq get Hstate 0 1 eq get Hp 0 8 490 hpfinish 491 ret true 492 end 493 hpfail 14 494 ret false 495 end