Testing a small http-client on Linux using no_std & embedded reqwless.
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

add baseline https feature for reqwless downloader

rektide df9d8d3f 3c277804

+418 -15
+349 -13
Cargo.lock
··· 3 3 version = 4 4 4 5 5 [[package]] 6 + name = "aead" 7 + version = "0.5.2" 8 + source = "registry+https://github.com/rust-lang/crates.io-index" 9 + checksum = "d122413f284cf2d62fb1b7db97e02edb8cda96d769b16e443a4f6195e35662b0" 10 + dependencies = [ 11 + "crypto-common", 12 + "generic-array 0.14.9", 13 + ] 14 + 15 + [[package]] 16 + name = "aes" 17 + version = "0.8.4" 18 + source = "registry+https://github.com/rust-lang/crates.io-index" 19 + checksum = "b169f7a6d4742236a0a00c541b845991d0ac43e546831af1249753ab4c3aa3a0" 20 + dependencies = [ 21 + "cfg-if", 22 + "cipher", 23 + "cpufeatures", 24 + ] 25 + 26 + [[package]] 27 + name = "aes-gcm" 28 + version = "0.10.3" 29 + source = "registry+https://github.com/rust-lang/crates.io-index" 30 + checksum = "831010a0f742e1209b3bcea8fab6a8e149051ba6099432c8cb2cc117dec3ead1" 31 + dependencies = [ 32 + "aead", 33 + "aes", 34 + "cipher", 35 + "ctr", 36 + "ghash", 37 + "subtle", 38 + ] 39 + 40 + [[package]] 41 + name = "as-slice" 42 + version = "0.1.5" 43 + source = "registry+https://github.com/rust-lang/crates.io-index" 44 + checksum = "45403b49e3954a4b8428a0ac21a4b7afadccf92bfd96273f1a58cd4812496ae0" 45 + dependencies = [ 46 + "generic-array 0.12.4", 47 + "generic-array 0.13.3", 48 + "generic-array 0.14.9", 49 + "stable_deref_trait", 50 + ] 51 + 52 + [[package]] 6 53 name = "base16ct" 7 54 version = "0.2.0" 8 55 source = "registry+https://github.com/rust-lang/crates.io-index" ··· 20 67 source = "registry+https://github.com/rust-lang/crates.io-index" 21 68 checksum = "3078c7629b62d3f0439517fa394996acacc5cbc91c5a20d8c658e77abd503a71" 22 69 dependencies = [ 23 - "generic-array", 70 + "generic-array 0.14.9", 24 71 ] 25 72 26 73 [[package]] ··· 46 93 checksum = "9330f8b2ff13f34540b44e946ef35111825727b38d33286ef986142615121801" 47 94 48 95 [[package]] 96 + name = "cipher" 97 + version = "0.4.4" 98 + source = "registry+https://github.com/rust-lang/crates.io-index" 99 + checksum = "773f3b9af64447d2ce9850330c473515014aa235e6a783b02db81ff39e4a3dad" 100 + dependencies = [ 101 + "crypto-common", 102 + "inout", 103 + ] 104 + 105 + [[package]] 49 106 name = "const-oid" 50 107 version = "0.9.6" 51 108 source = "registry+https://github.com/rust-lang/crates.io-index" 52 109 checksum = "c2459377285ad874054d797f3ccebf984978aa39129f6eafde5cdc8315b612f8" 53 110 54 111 [[package]] 112 + name = "const-oid" 113 + version = "0.10.2" 114 + source = "registry+https://github.com/rust-lang/crates.io-index" 115 + checksum = "a6ef517f0926dd24a1582492c791b6a4818a4d94e789a334894aa15b0d12f55c" 116 + 117 + [[package]] 55 118 name = "cpufeatures" 56 119 version = "0.2.17" 57 120 source = "registry+https://github.com/rust-lang/crates.io-index" ··· 66 129 source = "registry+https://github.com/rust-lang/crates.io-index" 67 130 checksum = "0dc92fb57ca44df6db8059111ab3af99a63d5d0f8375d9972e319a379c6bab76" 68 131 dependencies = [ 69 - "generic-array", 132 + "generic-array 0.14.9", 70 133 "rand_core", 71 134 "subtle", 72 135 "zeroize", ··· 78 141 source = "registry+https://github.com/rust-lang/crates.io-index" 79 142 checksum = "1bfb12502f3fc46cca1bb51ac28df9d618d813cdc3d2f25b9fe775a34af26bb3" 80 143 dependencies = [ 81 - "generic-array", 144 + "generic-array 0.14.9", 82 145 "typenum", 83 146 ] 84 147 85 148 [[package]] 149 + name = "ctr" 150 + version = "0.9.2" 151 + source = "registry+https://github.com/rust-lang/crates.io-index" 152 + checksum = "0369ee1ad671834580515889b80f2ea915f23b8be8d0daa4bbaf2ac5c7590835" 153 + dependencies = [ 154 + "cipher", 155 + ] 156 + 157 + [[package]] 158 + name = "curve25519-dalek" 159 + version = "4.1.3" 160 + source = "registry+https://github.com/rust-lang/crates.io-index" 161 + checksum = "97fb8b7c4503de7d6ae7b42ab72a5a59857b4c937ec27a3d4539dba95b5ab2be" 162 + dependencies = [ 163 + "cfg-if", 164 + "cpufeatures", 165 + "curve25519-dalek-derive", 166 + "digest", 167 + "fiat-crypto", 168 + "rustc_version", 169 + "subtle", 170 + ] 171 + 172 + [[package]] 173 + name = "curve25519-dalek-derive" 174 + version = "0.1.1" 175 + source = "registry+https://github.com/rust-lang/crates.io-index" 176 + checksum = "f46882e17999c6cc590af592290432be3bce0428cb0d5f8b6715e4dc7b383eb3" 177 + dependencies = [ 178 + "proc-macro2", 179 + "quote", 180 + "syn", 181 + ] 182 + 183 + [[package]] 86 184 name = "der" 87 185 version = "0.7.10" 88 186 source = "registry+https://github.com/rust-lang/crates.io-index" 89 187 checksum = "e7c1832837b905bbfb5101e07cc24c8deddf52f93225eee6ead5f4d63d53ddcb" 90 188 dependencies = [ 91 - "const-oid", 189 + "const-oid 0.9.6", 92 190 "zeroize", 93 191 ] 94 192 95 193 [[package]] 194 + name = "der" 195 + version = "0.8.0" 196 + source = "registry+https://github.com/rust-lang/crates.io-index" 197 + checksum = "71fd89660b2dc699704064e59e9dba0147b903e85319429e131620d022be411b" 198 + dependencies = [ 199 + "const-oid 0.10.2", 200 + "der_derive", 201 + "heapless 0.9.2", 202 + "time", 203 + ] 204 + 205 + [[package]] 206 + name = "der_derive" 207 + version = "0.8.0" 208 + source = "registry+https://github.com/rust-lang/crates.io-index" 209 + checksum = "59600e2c2d636fde9b65e99cc6445ac770c63d3628195ff39932b8d6d7409903" 210 + dependencies = [ 211 + "proc-macro2", 212 + "quote", 213 + "syn", 214 + ] 215 + 216 + [[package]] 217 + name = "deranged" 218 + version = "0.5.8" 219 + source = "registry+https://github.com/rust-lang/crates.io-index" 220 + checksum = "7cd812cc2bc1d69d4764bd80df88b4317eaef9e773c75226407d9bc0876b211c" 221 + dependencies = [ 222 + "powerfmt", 223 + ] 224 + 225 + [[package]] 96 226 name = "digest" 97 227 version = "0.10.7" 98 228 source = "registry+https://github.com/rust-lang/crates.io-index" 99 229 checksum = "9ed9a281f7bc9b7576e61468ba615a66a5c8cfdff42420a70aa82701a3b1e292" 100 230 dependencies = [ 101 231 "block-buffer", 102 - "const-oid", 232 + "const-oid 0.9.6", 103 233 "crypto-common", 104 234 "subtle", 105 235 ] ··· 110 240 source = "registry+https://github.com/rust-lang/crates.io-index" 111 241 checksum = "ee27f32b5c5292967d2d4a9d7f1e0b0aed2c15daded5a60300e4abb9d8020bca" 112 242 dependencies = [ 113 - "der", 243 + "der 0.7.10", 114 244 "digest", 115 245 "elliptic-curve", 116 246 "rfc6979", ··· 118 248 ] 119 249 120 250 [[package]] 251 + name = "ed25519" 252 + version = "2.2.3" 253 + source = "registry+https://github.com/rust-lang/crates.io-index" 254 + checksum = "115531babc129696a58c64a4fef0a8bf9e9698629fb97e9e40767d235cfbcd53" 255 + dependencies = [ 256 + "signature", 257 + ] 258 + 259 + [[package]] 260 + name = "ed25519-dalek" 261 + version = "2.2.0" 262 + source = "registry+https://github.com/rust-lang/crates.io-index" 263 + checksum = "70e796c081cee67dc755e1a36a0a172b897fab85fc3f6bc48307991f64e4eca9" 264 + dependencies = [ 265 + "curve25519-dalek", 266 + "ed25519", 267 + "sha2", 268 + "subtle", 269 + ] 270 + 271 + [[package]] 121 272 name = "elliptic-curve" 122 273 version = "0.13.8" 123 274 source = "registry+https://github.com/rust-lang/crates.io-index" ··· 127 278 "crypto-bigint", 128 279 "digest", 129 280 "ff", 130 - "generic-array", 281 + "generic-array 0.14.9", 131 282 "group", 132 283 "hkdf", 133 284 "rand_core", ··· 171 322 ] 172 323 173 324 [[package]] 325 + name = "embedded-tls" 326 + version = "0.18.0" 327 + source = "registry+https://github.com/rust-lang/crates.io-index" 328 + checksum = "09d1e46155b61b5b5cc486e01dacc55a623689bded89835965b15436734f078a" 329 + dependencies = [ 330 + "aes-gcm", 331 + "const-oid 0.10.2", 332 + "der 0.8.0", 333 + "digest", 334 + "ecdsa", 335 + "ed25519-dalek", 336 + "embedded-io", 337 + "embedded-io-async", 338 + "generic-array 0.14.9", 339 + "heapless 0.6.1", 340 + "heapless 0.9.2", 341 + "hkdf", 342 + "hmac", 343 + "p256", 344 + "p384", 345 + "portable-atomic", 346 + "rand_core", 347 + "sha2", 348 + "signature", 349 + "typenum", 350 + ] 351 + 352 + [[package]] 174 353 name = "ff" 175 354 version = "0.13.1" 176 355 source = "registry+https://github.com/rust-lang/crates.io-index" ··· 181 360 ] 182 361 183 362 [[package]] 363 + name = "fiat-crypto" 364 + version = "0.2.9" 365 + source = "registry+https://github.com/rust-lang/crates.io-index" 366 + checksum = "28dea519a9695b9977216879a3ebfddf92f1c08c05d984f8996aecd6ecdc811d" 367 + 368 + [[package]] 369 + name = "generic-array" 370 + version = "0.12.4" 371 + source = "registry+https://github.com/rust-lang/crates.io-index" 372 + checksum = "ffdf9f34f1447443d37393cc6c2b8313aebddcd96906caf34e54c68d8e57d7bd" 373 + dependencies = [ 374 + "typenum", 375 + ] 376 + 377 + [[package]] 378 + name = "generic-array" 379 + version = "0.13.3" 380 + source = "registry+https://github.com/rust-lang/crates.io-index" 381 + checksum = "f797e67af32588215eaaab8327027ee8e71b9dd0b2b26996aedf20c030fce309" 382 + dependencies = [ 383 + "typenum", 384 + ] 385 + 386 + [[package]] 184 387 name = "generic-array" 185 388 version = "0.14.9" 186 389 source = "registry+https://github.com/rust-lang/crates.io-index" ··· 189 392 "typenum", 190 393 "version_check", 191 394 "zeroize", 395 + ] 396 + 397 + [[package]] 398 + name = "ghash" 399 + version = "0.5.1" 400 + source = "registry+https://github.com/rust-lang/crates.io-index" 401 + checksum = "f0d8a4362ccb29cb0b265253fb0a2728f592895ee6854fd9bc13f2ffda266ff1" 402 + dependencies = [ 403 + "opaque-debug", 404 + "polyval", 192 405 ] 193 406 194 407 [[package]] ··· 204 417 205 418 [[package]] 206 419 name = "hash32" 420 + version = "0.1.1" 421 + source = "registry+https://github.com/rust-lang/crates.io-index" 422 + checksum = "d4041af86e63ac4298ce40e5cca669066e75b6f1aa3390fe2561ffa5e1d9f4cc" 423 + dependencies = [ 424 + "byteorder", 425 + ] 426 + 427 + [[package]] 428 + name = "hash32" 207 429 version = "0.3.1" 208 430 source = "registry+https://github.com/rust-lang/crates.io-index" 209 431 checksum = "47d60b12902ba28e2730cd37e95b8c9223af2808df9e902d4df49588d1470606" ··· 213 435 214 436 [[package]] 215 437 name = "heapless" 438 + version = "0.6.1" 439 + source = "registry+https://github.com/rust-lang/crates.io-index" 440 + checksum = "634bd4d29cbf24424d0a4bfcbf80c6960129dc24424752a7d1d1390607023422" 441 + dependencies = [ 442 + "as-slice", 443 + "generic-array 0.14.9", 444 + "hash32 0.1.1", 445 + "stable_deref_trait", 446 + ] 447 + 448 + [[package]] 449 + name = "heapless" 216 450 version = "0.9.2" 217 451 source = "registry+https://github.com/rust-lang/crates.io-index" 218 452 checksum = "2af2455f757db2b292a9b1768c4b70186d443bcb3b316252d6b540aec1cd89ed" 219 453 dependencies = [ 220 - "hash32", 454 + "hash32 0.3.1", 221 455 "stable_deref_trait", 222 456 ] 223 457 ··· 252 486 checksum = "6dbf3de79e51f3d586ab4cb9d5c3e2c14aa28ed23d180cf89b4df0454a69cc87" 253 487 254 488 [[package]] 489 + name = "inout" 490 + version = "0.1.4" 491 + source = "registry+https://github.com/rust-lang/crates.io-index" 492 + checksum = "879f10e63c20629ecabbb64a8010319738c66a5cd0c29b02d63d272b03751d01" 493 + dependencies = [ 494 + "generic-array 0.14.9", 495 + ] 496 + 497 + [[package]] 255 498 name = "libc" 256 499 version = "0.2.183" 257 500 source = "registry+https://github.com/rust-lang/crates.io-index" ··· 270 513 checksum = "aa07b0722c63805057dec824444fdc814bdfd30d1c782a3a8f63bbcf67c4ed1c" 271 514 272 515 [[package]] 516 + name = "num-conv" 517 + version = "0.2.0" 518 + source = "registry+https://github.com/rust-lang/crates.io-index" 519 + checksum = "cf97ec579c3c42f953ef76dbf8d55ac91fb219dde70e49aa4a6b7d74e9919050" 520 + 521 + [[package]] 522 + name = "opaque-debug" 523 + version = "0.3.1" 524 + source = "registry+https://github.com/rust-lang/crates.io-index" 525 + checksum = "c08d65885ee38876c4f86fa503fb49d7b507c2b62552df7c70b2fce627e06381" 526 + 527 + [[package]] 273 528 name = "p256" 274 529 version = "0.13.2" 275 530 source = "registry+https://github.com/rust-lang/crates.io-index" ··· 282 537 ] 283 538 284 539 [[package]] 540 + name = "p384" 541 + version = "0.13.1" 542 + source = "registry+https://github.com/rust-lang/crates.io-index" 543 + checksum = "fe42f1670a52a47d448f14b6a5c61dd78fce51856e68edaa38f7ae3a46b8d6b6" 544 + dependencies = [ 545 + "ecdsa", 546 + "elliptic-curve", 547 + "primeorder", 548 + "sha2", 549 + ] 550 + 551 + [[package]] 285 552 name = "pkcs8" 286 553 version = "0.10.2" 287 554 source = "registry+https://github.com/rust-lang/crates.io-index" 288 555 checksum = "f950b2377845cebe5cf8b5165cb3cc1a5e0fa5cfa3e1f7f55707d8fd82e0a7b7" 289 556 dependencies = [ 290 - "der", 557 + "der 0.7.10", 291 558 "spki", 292 559 ] 293 560 294 561 [[package]] 562 + name = "polyval" 563 + version = "0.6.2" 564 + source = "registry+https://github.com/rust-lang/crates.io-index" 565 + checksum = "9d1fe60d06143b2430aa532c94cfe9e29783047f06c0d7fd359a9a51b729fa25" 566 + dependencies = [ 567 + "cfg-if", 568 + "cpufeatures", 569 + "opaque-debug", 570 + "universal-hash", 571 + ] 572 + 573 + [[package]] 574 + name = "portable-atomic" 575 + version = "1.13.1" 576 + source = "registry+https://github.com/rust-lang/crates.io-index" 577 + checksum = "c33a9471896f1c69cecef8d20cbe2f7accd12527ce60845ff44c153bb2a21b49" 578 + 579 + [[package]] 580 + name = "powerfmt" 581 + version = "0.2.0" 582 + source = "registry+https://github.com/rust-lang/crates.io-index" 583 + checksum = "439ee305def115ba05938db6eb1644ff94165c5ab5e9420d1c1bcedbba909391" 584 + 585 + [[package]] 295 586 name = "ppv-lite86" 296 587 version = "0.2.21" 297 588 source = "registry+https://github.com/rust-lang/crates.io-index" ··· 354 645 "embedded-io", 355 646 "embedded-io-async", 356 647 "embedded-nal-async", 357 - "heapless", 648 + "embedded-tls", 649 + "heapless 0.9.2", 358 650 "hex", 359 651 "httparse", 360 652 "nourl", ··· 368 660 name = "reqwless-linux" 369 661 version = "0.1.0" 370 662 dependencies = [ 663 + "der 0.8.0", 371 664 "embedded-io", 372 665 "embedded-io-async", 373 666 "embedded-nal-async", ··· 386 679 ] 387 680 388 681 [[package]] 682 + name = "rustc_version" 683 + version = "0.4.1" 684 + source = "registry+https://github.com/rust-lang/crates.io-index" 685 + checksum = "cfcb3a22ef46e85b45de6ee7e79d063319ebb6594faafcf1c225ea92ab6e9b92" 686 + dependencies = [ 687 + "semver", 688 + ] 689 + 690 + [[package]] 389 691 name = "sec1" 390 692 version = "0.7.3" 391 693 source = "registry+https://github.com/rust-lang/crates.io-index" 392 694 checksum = "d3e97a565f76233a6003f9f5c54be1d9c5bdfa3eccfb189469f11ec4901c47dc" 393 695 dependencies = [ 394 696 "base16ct", 395 - "der", 396 - "generic-array", 697 + "der 0.7.10", 698 + "generic-array 0.14.9", 397 699 "subtle", 398 700 "zeroize", 399 701 ] 400 702 401 703 [[package]] 704 + name = "semver" 705 + version = "1.0.27" 706 + source = "registry+https://github.com/rust-lang/crates.io-index" 707 + checksum = "d767eb0aabc880b29956c35734170f26ed551a859dbd361d140cdbeca61ab1e2" 708 + 709 + [[package]] 402 710 name = "sha2" 403 711 version = "0.10.9" 404 712 source = "registry+https://github.com/rust-lang/crates.io-index" ··· 425 733 source = "registry+https://github.com/rust-lang/crates.io-index" 426 734 checksum = "d91ed6c858b01f942cd56b37a94b3e0a1798290327d1236e4d9cf4eaca44d29d" 427 735 dependencies = [ 428 - "der", 736 + "der 0.7.10", 429 737 ] 430 738 431 739 [[package]] ··· 452 760 ] 453 761 454 762 [[package]] 763 + name = "time" 764 + version = "0.3.47" 765 + source = "registry+https://github.com/rust-lang/crates.io-index" 766 + checksum = "743bd48c283afc0388f9b8827b976905fb217ad9e647fae3a379a9283c4def2c" 767 + dependencies = [ 768 + "deranged", 769 + "num-conv", 770 + "powerfmt", 771 + "time-core", 772 + ] 773 + 774 + [[package]] 775 + name = "time-core" 776 + version = "0.1.8" 777 + source = "registry+https://github.com/rust-lang/crates.io-index" 778 + checksum = "7694e1cfe791f8d31026952abf09c69ca6f6fa4e1a1229e18988f06a04a12dca" 779 + 780 + [[package]] 455 781 name = "typenum" 456 782 version = "1.19.0" 457 783 source = "registry+https://github.com/rust-lang/crates.io-index" ··· 462 788 version = "1.0.24" 463 789 source = "registry+https://github.com/rust-lang/crates.io-index" 464 790 checksum = "e6e4313cd5fcd3dad5cafa179702e2b244f760991f45397d14d4ebf38247da75" 791 + 792 + [[package]] 793 + name = "universal-hash" 794 + version = "0.5.1" 795 + source = "registry+https://github.com/rust-lang/crates.io-index" 796 + checksum = "fc1de2c688dc15305988b563c3854064043356019f97a4b46276fe734c4f07ea" 797 + dependencies = [ 798 + "crypto-common", 799 + "subtle", 800 + ] 465 801 466 802 [[package]] 467 803 name = "version_check"
+5
Cargo.toml
··· 3 3 version = "0.1.0" 4 4 edition = "2024" 5 5 6 + [features] 7 + default = [] 8 + https = ["reqwless/embedded-tls", "dep:der"] 9 + 6 10 [dependencies] 7 11 embedded-io = { version = "0.7", default-features = false } 8 12 embedded-io-async = { version = "0.7", default-features = false } 9 13 embedded-nal-async = { version = "0.9", default-features = false } 14 + der = { version = "0.8", default-features = false, features = ["derive", "oid", "time", "heapless"], optional = true } 10 15 libc = { version = "0.2", default-features = false } 11 16 reqwless = { version = "0.14", default-features = false } 12 17
+8 -1
README.md
··· 10 10 11 11 This prints the HTTP response body to stdout. 12 12 13 + To enable baseline HTTPS support: 14 + 15 + ```bash 16 + cargo run --features https -- https://example.com 17 + ``` 18 + 13 19 ## Notes 14 20 15 21 - `no_std` + `no_main` binary using Linux libc syscalls 16 - - Uses `reqwless` with `default-features = false` (HTTP only) 22 + - Uses `reqwless` with `default-features = false` 23 + - HTTPS is optional via `--features https` and currently uses `TlsVerify::None` (insecure baseline) 17 24 - Uses fixed-size stack buffers for request/response and output chunks 18 25 - Performs best-effort low-allocation operation (no `String`/`Vec` in app code)
+56 -1
src/main.rs
··· 16 16 use embedded_nal_async::{AddrType, Dns, TcpConnect}; 17 17 use reqwless::TryBufRead; 18 18 use reqwless::client::HttpClient; 19 + #[cfg(feature = "https")] 20 + use reqwless::client::{TlsConfig, TlsVerify}; 19 21 use reqwless::request::Method; 20 22 21 23 const EXIT_OK: c_int = 0; ··· 23 25 const EXIT_FAILURE: c_int = 1; 24 26 25 27 const DNS_HOST_MAX: usize = 255; 28 + #[cfg(feature = "https")] 29 + const TLS_BUFFER_SIZE: usize = 16 * 1024; 30 + #[cfg(feature = "https")] 31 + const TLS_DUMMY_SEED: u64 = 0xA17E_5EED_D00D_F00D; 26 32 27 33 struct LinuxTcp; 28 34 ··· 35 41 #[derive(Debug)] 36 42 enum AppError { 37 43 MissingUrl, 44 + #[cfg(not(feature = "https"))] 45 + HttpsFeatureDisabled, 38 46 InvalidUtf8, 39 47 UrlTooLong, 40 48 NulInHost, ··· 48 56 fn kind(&self) -> ErrorKind { 49 57 match self { 50 58 Self::MissingUrl => ErrorKind::InvalidInput, 59 + #[cfg(not(feature = "https"))] 60 + Self::HttpsFeatureDisabled => ErrorKind::Unsupported, 51 61 Self::InvalidUtf8 => ErrorKind::InvalidData, 52 62 Self::UrlTooLong => ErrorKind::InvalidInput, 53 63 Self::NulInHost => ErrorKind::InvalidInput, ··· 77 87 fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { 78 88 let message = match self { 79 89 Self::MissingUrl => "missing url argument", 90 + #[cfg(not(feature = "https"))] 91 + Self::HttpsFeatureDisabled => "https support not enabled", 80 92 Self::InvalidUtf8 => "url argument must be valid utf-8", 81 93 Self::UrlTooLong => "hostname is too long", 82 94 Self::NulInHost => "hostname contains NUL byte", ··· 189 201 let url = match read_url_argument(argc, argv) { 190 202 Ok(url) => url, 191 203 Err(AppError::MissingUrl) => { 192 - write_stderr(b"usage: reqwless-linux <http://url>\n"); 204 + print_usage(); 193 205 return EXIT_USAGE; 194 206 } 195 207 Err(error) => { ··· 208 220 } 209 221 210 222 async fn download_to_stdout(url: &str) -> Result<(), AppError> { 223 + if url.starts_with("https://") { 224 + return download_https_to_stdout(url).await; 225 + } 226 + 227 + download_http_to_stdout(url).await 228 + } 229 + 230 + async fn download_http_to_stdout(url: &str) -> Result<(), AppError> { 211 231 let tcp = LinuxTcp; 212 232 let dns = LinuxDns; 213 233 let mut client = HttpClient::new(&tcp, &dns); 234 + stream_get_to_stdout(&mut client, url).await 235 + } 236 + 237 + #[cfg(feature = "https")] 238 + async fn download_https_to_stdout(url: &str) -> Result<(), AppError> { 239 + let tcp = LinuxTcp; 240 + let dns = LinuxDns; 241 + let mut tls_read_buf = [0_u8; TLS_BUFFER_SIZE]; 242 + let mut tls_write_buf = [0_u8; TLS_BUFFER_SIZE]; 243 + let mut client = HttpClient::new_with_tls( 244 + &tcp, 245 + &dns, 246 + TlsConfig::new(TLS_DUMMY_SEED, &mut tls_read_buf, &mut tls_write_buf, TlsVerify::None), 247 + ); 248 + stream_get_to_stdout(&mut client, url).await 249 + } 250 + 251 + #[cfg(not(feature = "https"))] 252 + async fn download_https_to_stdout(_url: &str) -> Result<(), AppError> { 253 + Err(AppError::HttpsFeatureDisabled) 254 + } 255 + 256 + async fn stream_get_to_stdout(client: &mut HttpClient<'_, LinuxTcp, LinuxDns>, url: &str) -> Result<(), AppError> { 214 257 let mut rx_buf = [0_u8; 8192]; 215 258 216 259 let mut request = client.request(Method::GET, url).await.map_err(AppError::Http)?; ··· 227 270 } 228 271 229 272 Ok(()) 273 + } 274 + 275 + fn print_usage() { 276 + #[cfg(feature = "https")] 277 + write_stderr(b"usage: reqwless-linux <http://url|https://url>\n"); 278 + 279 + #[cfg(not(feature = "https"))] 280 + write_stderr(b"usage: reqwless-linux <http://url>\n"); 230 281 } 231 282 232 283 fn read_url_argument<'a>(argc: c_int, argv: *const *const c_char) -> Result<&'a str, AppError> { ··· 390 441 fn report_error(error: AppError) { 391 442 match error { 392 443 AppError::MissingUrl => write_stderr(b"missing url argument\n"), 444 + #[cfg(not(feature = "https"))] 445 + AppError::HttpsFeatureDisabled => write_stderr(b"https url requires --features https\n"), 393 446 AppError::InvalidUtf8 => write_stderr(b"url argument must be valid utf-8\n"), 394 447 AppError::UrlTooLong => write_stderr(b"hostname is too long\n"), 395 448 AppError::NulInHost => write_stderr(b"hostname contains NUL byte\n"), ··· 399 452 AppError::Http(reqwless::Error::InvalidUrl(_)) => write_stderr(b"invalid url\n"), 400 453 AppError::Http(reqwless::Error::Dns) => write_stderr(b"http dns error\n"), 401 454 AppError::Http(reqwless::Error::BufferTooSmall) => write_stderr(b"response buffer too small\n"), 455 + #[cfg(feature = "https")] 456 + AppError::Http(reqwless::Error::Tls(_)) => write_stderr(b"tls handshake failed\n"), 402 457 AppError::Http(_) => write_stderr(b"http request failed\n"), 403 458 } 404 459 }