aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAkshay <[email protected]>2020-08-23 08:33:21 +0100
committerAkshay <[email protected]>2020-08-23 08:33:21 +0100
commit21f1d776762035012f02be39c96978b0719e0613 (patch)
tree24fd73624f305281c391825875dcaf941e716090
parentf36a8fb2eee46cffa87213e070136e5f28194a16 (diff)
initial multipart handling
-rw-r--r--Cargo.lock402
-rw-r--r--Cargo.toml6
-rw-r--r--src/main.rs72
3 files changed, 198 insertions, 282 deletions
diff --git a/Cargo.lock b/Cargo.lock
index 7e67cca..1c73a0e 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -1,6 +1,15 @@
1# This file is automatically @generated by Cargo. 1# This file is automatically @generated by Cargo.
2# It is not intended for manual editing. 2# It is not intended for manual editing.
3[[package]] 3[[package]]
4name = "aho-corasick"
5version = "0.7.13"
6source = "registry+https://github.com/rust-lang/crates.io-index"
7checksum = "043164d8ba5c4c3035fec9bbee8647c0261d788f3474306f93bb65901cae0e86"
8dependencies = [
9 "memchr",
10]
11
12[[package]]
4name = "anyhow" 13name = "anyhow"
5version = "1.0.32" 14version = "1.0.32"
6source = "registry+https://github.com/rust-lang/crates.io-index" 15source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -25,38 +34,12 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
25checksum = "cdb031dd78e28731d87d56cc8ffef4a8f36ca26c38fe2de700543e627f8a464a" 34checksum = "cdb031dd78e28731d87d56cc8ffef4a8f36ca26c38fe2de700543e627f8a464a"
26 35
27[[package]] 36[[package]]
28name = "base64"
29version = "0.9.3"
30source = "registry+https://github.com/rust-lang/crates.io-index"
31checksum = "489d6c0ed21b11d038c31b6ceccca973e65d73ba3bd8ecb9a2babf5546164643"
32dependencies = [
33 "byteorder",
34 "safemem",
35]
36
37[[package]]
38name = "bitflags" 37name = "bitflags"
39version = "1.2.1" 38version = "1.2.1"
40source = "registry+https://github.com/rust-lang/crates.io-index" 39source = "registry+https://github.com/rust-lang/crates.io-index"
41checksum = "cf1de2fe8c75bc145a2f577add951f8134889b4795d47466a54a5c846d691693" 40checksum = "cf1de2fe8c75bc145a2f577add951f8134889b4795d47466a54a5c846d691693"
42 41
43[[package]] 42[[package]]
44name = "buf_redux"
45version = "0.8.4"
46source = "registry+https://github.com/rust-lang/crates.io-index"
47checksum = "b953a6887648bb07a535631f2bc00fbdb2a2216f135552cb3f534ed136b9c07f"
48dependencies = [
49 "memchr",
50 "safemem",
51]
52
53[[package]]
54name = "byteorder"
55version = "1.3.4"
56source = "registry+https://github.com/rust-lang/crates.io-index"
57checksum = "08c48aae112d48ed9f069b33538ea9e3e90aa263cfa3d1c24309612b1f7472de"
58
59[[package]]
60name = "bytes" 43name = "bytes"
61version = "0.5.6" 44version = "0.5.6"
62source = "registry+https://github.com/rust-lang/crates.io-index" 45source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -78,6 +61,26 @@ dependencies = [
78] 61]
79 62
80[[package]] 63[[package]]
64name = "derive_more"
65version = "0.99.9"
66source = "registry+https://github.com/rust-lang/crates.io-index"
67checksum = "298998b1cf6b5b2c8a7b023dfd45821825ce3ba8a8af55c921a0e734e4653f76"
68dependencies = [
69 "proc-macro2",
70 "quote",
71 "syn",
72]
73
74[[package]]
75name = "encoding_rs"
76version = "0.8.23"
77source = "registry+https://github.com/rust-lang/crates.io-index"
78checksum = "e8ac63f94732332f44fe654443c46f6375d1939684c17b0afb6cb56b0456e171"
79dependencies = [
80 "cfg-if",
81]
82
83[[package]]
81name = "fallible-iterator" 84name = "fallible-iterator"
82version = "0.2.0" 85version = "0.2.0"
83source = "registry+https://github.com/rust-lang/crates.io-index" 86source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -118,12 +121,28 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
118checksum = "3dcaa9ae7725d12cdb85b3ad99a434db70b468c09ded17e012d86b5c1010f7a7" 121checksum = "3dcaa9ae7725d12cdb85b3ad99a434db70b468c09ded17e012d86b5c1010f7a7"
119 122
120[[package]] 123[[package]]
124name = "futures"
125version = "0.3.5"
126source = "registry+https://github.com/rust-lang/crates.io-index"
127checksum = "1e05b85ec287aac0dc34db7d4a569323df697f9c55b99b15d6b4ef8cde49f613"
128dependencies = [
129 "futures-channel",
130 "futures-core",
131 "futures-executor",
132 "futures-io",
133 "futures-sink",
134 "futures-task",
135 "futures-util",
136]
137
138[[package]]
121name = "futures-channel" 139name = "futures-channel"
122version = "0.3.5" 140version = "0.3.5"
123source = "registry+https://github.com/rust-lang/crates.io-index" 141source = "registry+https://github.com/rust-lang/crates.io-index"
124checksum = "f366ad74c28cca6ba456d95e6422883cfb4b252a83bed929c83abfdbbf2967d5" 142checksum = "f366ad74c28cca6ba456d95e6422883cfb4b252a83bed929c83abfdbbf2967d5"
125dependencies = [ 143dependencies = [
126 "futures-core", 144 "futures-core",
145 "futures-sink",
127] 146]
128 147
129[[package]] 148[[package]]
@@ -133,6 +152,35 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
133checksum = "59f5fff90fd5d971f936ad674802482ba441b6f09ba5e15fd8b39145582ca399" 152checksum = "59f5fff90fd5d971f936ad674802482ba441b6f09ba5e15fd8b39145582ca399"
134 153
135[[package]] 154[[package]]
155name = "futures-executor"
156version = "0.3.5"
157source = "registry+https://github.com/rust-lang/crates.io-index"
158checksum = "10d6bb888be1153d3abeb9006b11b02cf5e9b209fda28693c31ae1e4e012e314"
159dependencies = [
160 "futures-core",
161 "futures-task",
162 "futures-util",
163]
164
165[[package]]
166name = "futures-io"
167version = "0.3.5"
168source = "registry+https://github.com/rust-lang/crates.io-index"
169checksum = "de27142b013a8e869c14957e6d2edeef89e97c289e69d042ee3a49acd8b51789"
170
171[[package]]
172name = "futures-macro"
173version = "0.3.5"
174source = "registry+https://github.com/rust-lang/crates.io-index"
175checksum = "d0b5a30a4328ab5473878237c447333c093297bded83a4983d10f4deea240d39"
176dependencies = [
177 "proc-macro-hack",
178 "proc-macro2",
179 "quote",
180 "syn",
181]
182
183[[package]]
136name = "futures-sink" 184name = "futures-sink"
137version = "0.3.5" 185version = "0.3.5"
138source = "registry+https://github.com/rust-lang/crates.io-index" 186source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -143,6 +191,9 @@ name = "futures-task"
143version = "0.3.5" 191version = "0.3.5"
144source = "registry+https://github.com/rust-lang/crates.io-index" 192source = "registry+https://github.com/rust-lang/crates.io-index"
145checksum = "bdb66b5f09e22019b1ab0830f7785bcea8e7a42148683f99214f73f8ec21a626" 193checksum = "bdb66b5f09e22019b1ab0830f7785bcea8e7a42148683f99214f73f8ec21a626"
194dependencies = [
195 "once_cell",
196]
146 197
147[[package]] 198[[package]]
148name = "futures-util" 199name = "futures-util"
@@ -150,21 +201,18 @@ version = "0.3.5"
150source = "registry+https://github.com/rust-lang/crates.io-index" 201source = "registry+https://github.com/rust-lang/crates.io-index"
151checksum = "8764574ff08b701a084482c3c7031349104b07ac897393010494beaa18ce32c6" 202checksum = "8764574ff08b701a084482c3c7031349104b07ac897393010494beaa18ce32c6"
152dependencies = [ 203dependencies = [
204 "futures-channel",
153 "futures-core", 205 "futures-core",
206 "futures-io",
207 "futures-macro",
208 "futures-sink",
154 "futures-task", 209 "futures-task",
210 "memchr",
155 "pin-project", 211 "pin-project",
156 "pin-utils", 212 "pin-utils",
157] 213 "proc-macro-hack",
158 214 "proc-macro-nested",
159[[package]] 215 "slab",
160name = "getrandom"
161version = "0.1.14"
162source = "registry+https://github.com/rust-lang/crates.io-index"
163checksum = "7abc8dd8451921606d809ba32e95b6111925cd2906060d2dcc29c070220503eb"
164dependencies = [
165 "cfg-if",
166 "libc",
167 "wasi",
168] 216]
169 217
170[[package]] 218[[package]]
@@ -200,12 +248,13 @@ name = "hedge"
200version = "0.1.0" 248version = "0.1.0"
201dependencies = [ 249dependencies = [
202 "anyhow", 250 "anyhow",
203 "hyper 0.13.7", 251 "futures",
204 "multipart", 252 "hyper",
253 "multer",
205 "nanoid", 254 "nanoid",
206 "rusqlite", 255 "rusqlite",
207 "tokio", 256 "tokio",
208 "url 2.1.1", 257 "url",
209] 258]
210 259
211[[package]] 260[[package]]
@@ -246,25 +295,6 @@ checksum = "cd179ae861f0c2e53da70d892f5f3029f9594be0c41dc5269cd371691b1dc2f9"
246 295
247[[package]] 296[[package]]
248name = "hyper" 297name = "hyper"
249version = "0.10.16"
250source = "registry+https://github.com/rust-lang/crates.io-index"
251checksum = "0a0652d9a2609a968c14be1a9ea00bf4b1d64e2e1f53a1b51b6fff3a6e829273"
252dependencies = [
253 "base64",
254 "httparse",
255 "language-tags",
256 "log 0.3.9",
257 "mime 0.2.6",
258 "num_cpus",
259 "time",
260 "traitobject",
261 "typeable",
262 "unicase 1.4.2",
263 "url 1.7.2",
264]
265
266[[package]]
267name = "hyper"
268version = "0.13.7" 298version = "0.13.7"
269source = "registry+https://github.com/rust-lang/crates.io-index" 299source = "registry+https://github.com/rust-lang/crates.io-index"
270checksum = "3e68a8dd9716185d9e64ea473ea6ef63529252e3e27623295a0378a19665d5eb" 300checksum = "3e68a8dd9716185d9e64ea473ea6ef63529252e3e27623295a0378a19665d5eb"
@@ -289,17 +319,6 @@ dependencies = [
289 319
290[[package]] 320[[package]]
291name = "idna" 321name = "idna"
292version = "0.1.5"
293source = "registry+https://github.com/rust-lang/crates.io-index"
294checksum = "38f09e0f0b1fb55fdee1f17470ad800da77af5186a1a76c026b679358b7e844e"
295dependencies = [
296 "matches",
297 "unicode-bidi",
298 "unicode-normalization",
299]
300
301[[package]]
302name = "idna"
303version = "0.2.0" 322version = "0.2.0"
304source = "registry+https://github.com/rust-lang/crates.io-index" 323source = "registry+https://github.com/rust-lang/crates.io-index"
305checksum = "02e2673c30ee86b5b96a9cb52ad15718aa1f966f5ab9ad54a8b95d5ca33120a9" 324checksum = "02e2673c30ee86b5b96a9cb52ad15718aa1f966f5ab9ad54a8b95d5ca33120a9"
@@ -345,12 +364,6 @@ dependencies = [
345] 364]
346 365
347[[package]] 366[[package]]
348name = "language-tags"
349version = "0.2.2"
350source = "registry+https://github.com/rust-lang/crates.io-index"
351checksum = "a91d884b6667cd606bb5a69aa0c99ba811a115fc68915e7056ec08a46e93199a"
352
353[[package]]
354name = "lazy_static" 367name = "lazy_static"
355version = "1.4.0" 368version = "1.4.0"
356source = "registry+https://github.com/rust-lang/crates.io-index" 369source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -380,15 +393,6 @@ checksum = "8dd5a6d5999d9907cda8ed67bbd137d3af8085216c2ac62de5be860bd41f304a"
380 393
381[[package]] 394[[package]]
382name = "log" 395name = "log"
383version = "0.3.9"
384source = "registry+https://github.com/rust-lang/crates.io-index"
385checksum = "e19e8d5c34a3e0e2223db8e060f9e8264aeeb5c5fc64a4ee9965c062211c024b"
386dependencies = [
387 "log 0.4.11",
388]
389
390[[package]]
391name = "log"
392version = "0.4.11" 396version = "0.4.11"
393source = "registry+https://github.com/rust-lang/crates.io-index" 397source = "registry+https://github.com/rust-lang/crates.io-index"
394checksum = "4fabed175da42fed1fa0746b0ea71f412aa9d35e76e95e59b192c64b9dc2bf8b" 398checksum = "4fabed175da42fed1fa0746b0ea71f412aa9d35e76e95e59b192c64b9dc2bf8b"
@@ -419,30 +423,11 @@ checksum = "3728d817d99e5ac407411fa471ff9800a778d88a24685968b36824eaf4bee400"
419 423
420[[package]] 424[[package]]
421name = "mime" 425name = "mime"
422version = "0.2.6"
423source = "registry+https://github.com/rust-lang/crates.io-index"
424checksum = "ba626b8a6de5da682e1caa06bdb42a335aee5a84db8e5046a3e8ab17ba0a3ae0"
425dependencies = [
426 "log 0.3.9",
427]
428
429[[package]]
430name = "mime"
431version = "0.3.16" 426version = "0.3.16"
432source = "registry+https://github.com/rust-lang/crates.io-index" 427source = "registry+https://github.com/rust-lang/crates.io-index"
433checksum = "2a60c7ce501c71e03a9c9c0d35b861413ae925bd979cc7a4e30d060069aaac8d" 428checksum = "2a60c7ce501c71e03a9c9c0d35b861413ae925bd979cc7a4e30d060069aaac8d"
434 429
435[[package]] 430[[package]]
436name = "mime_guess"
437version = "2.0.3"
438source = "registry+https://github.com/rust-lang/crates.io-index"
439checksum = "2684d4c2e97d99848d30b324b00c8fcc7e5c897b7cbb5819b09e7c90e8baf212"
440dependencies = [
441 "mime 0.3.16",
442 "unicase 2.6.0",
443]
444
445[[package]]
446name = "mio" 431name = "mio"
447version = "0.6.22" 432version = "0.6.22"
448source = "registry+https://github.com/rust-lang/crates.io-index" 433source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -454,7 +439,7 @@ dependencies = [
454 "iovec", 439 "iovec",
455 "kernel32-sys", 440 "kernel32-sys",
456 "libc", 441 "libc",
457 "log 0.4.11", 442 "log",
458 "miow 0.2.1", 443 "miow 0.2.1",
459 "net2", 444 "net2",
460 "slab", 445 "slab",
@@ -467,7 +452,7 @@ version = "0.1.7"
467source = "registry+https://github.com/rust-lang/crates.io-index" 452source = "registry+https://github.com/rust-lang/crates.io-index"
468checksum = "0840c1c50fd55e521b247f949c241c9997709f23bd7f023b9762cd561e935656" 453checksum = "0840c1c50fd55e521b247f949c241c9997709f23bd7f023b9762cd561e935656"
469dependencies = [ 454dependencies = [
470 "log 0.4.11", 455 "log",
471 "mio", 456 "mio",
472 "miow 0.3.5", 457 "miow 0.3.5",
473 "winapi 0.3.9", 458 "winapi 0.3.9",
@@ -507,21 +492,21 @@ dependencies = [
507] 492]
508 493
509[[package]] 494[[package]]
510name = "multipart" 495name = "multer"
511version = "0.17.0" 496version = "1.2.2"
512source = "registry+https://github.com/rust-lang/crates.io-index" 497source = "registry+https://github.com/rust-lang/crates.io-index"
513checksum = "8209c33c951f07387a8497841122fc6f712165e3f9bda3e6be4645b58188f676" 498checksum = "99851e6ad01b0fbe086dda2dea00d68bb84fc7d7eae2c39ca7313da9197f4d31"
514dependencies = [ 499dependencies = [
515 "buf_redux", 500 "bytes",
501 "derive_more",
502 "encoding_rs",
503 "futures",
504 "http",
516 "httparse", 505 "httparse",
517 "hyper 0.10.16", 506 "lazy_static",
518 "log 0.4.11", 507 "log",
519 "mime 0.3.16", 508 "mime",
520 "mime_guess", 509 "regex",
521 "quick-error",
522 "rand 0.6.5",
523 "safemem",
524 "tempfile",
525 "twoway", 510 "twoway",
526] 511]
527 512
@@ -531,7 +516,7 @@ version = "0.3.0"
531source = "registry+https://github.com/rust-lang/crates.io-index" 516source = "registry+https://github.com/rust-lang/crates.io-index"
532checksum = "a6226bc4e142124cb44e309a37a04cd9bb10e740d8642855441d3b14808f635e" 517checksum = "a6226bc4e142124cb44e309a37a04cd9bb10e740d8642855441d3b14808f635e"
533dependencies = [ 518dependencies = [
534 "rand 0.6.5", 519 "rand",
535] 520]
536 521
537[[package]] 522[[package]]
@@ -556,10 +541,10 @@ dependencies = [
556] 541]
557 542
558[[package]] 543[[package]]
559name = "percent-encoding" 544name = "once_cell"
560version = "1.0.1" 545version = "1.4.1"
561source = "registry+https://github.com/rust-lang/crates.io-index" 546source = "registry+https://github.com/rust-lang/crates.io-index"
562checksum = "31010dd2e1ac33d5b46a5b413495239882813e0369f8ed8a5e266f173602f831" 547checksum = "260e51e7efe62b592207e9e13a68e43692a7a279171d6ba57abd208bf23645ad"
563 548
564[[package]] 549[[package]]
565name = "percent-encoding" 550name = "percent-encoding"
@@ -606,10 +591,16 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
606checksum = "d36492546b6af1463394d46f0c834346f31548646f6ba10849802c9c9a27ac33" 591checksum = "d36492546b6af1463394d46f0c834346f31548646f6ba10849802c9c9a27ac33"
607 592
608[[package]] 593[[package]]
609name = "ppv-lite86" 594name = "proc-macro-hack"
610version = "0.2.9" 595version = "0.5.18"
596source = "registry+https://github.com/rust-lang/crates.io-index"
597checksum = "99c605b9a0adc77b7211c6b1f722dcb613d68d66859a44f3d485a6da332b0598"
598
599[[package]]
600name = "proc-macro-nested"
601version = "0.1.6"
611source = "registry+https://github.com/rust-lang/crates.io-index" 602source = "registry+https://github.com/rust-lang/crates.io-index"
612checksum = "c36fa947111f5c62a733b652544dd0016a43ce89619538a8ef92724a6f501a20" 603checksum = "eba180dafb9038b050a4c280019bbedf9f2467b61e5d892dcad585bb57aadc5a"
613 604
614[[package]] 605[[package]]
615name = "proc-macro2" 606name = "proc-macro2"
@@ -621,12 +612,6 @@ dependencies = [
621] 612]
622 613
623[[package]] 614[[package]]
624name = "quick-error"
625version = "1.2.3"
626source = "registry+https://github.com/rust-lang/crates.io-index"
627checksum = "a1d01941d82fa2ab50be1e79e6714289dd7cde78eba4c074bc5a4374f650dfe0"
628
629[[package]]
630name = "quote" 615name = "quote"
631version = "1.0.7" 616version = "1.0.7"
632source = "registry+https://github.com/rust-lang/crates.io-index" 617source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -643,9 +628,9 @@ checksum = "6d71dacdc3c88c1fde3885a3be3fbab9f35724e6ce99467f7d9c5026132184ca"
643dependencies = [ 628dependencies = [
644 "autocfg 0.1.7", 629 "autocfg 0.1.7",
645 "libc", 630 "libc",
646 "rand_chacha 0.1.1", 631 "rand_chacha",
647 "rand_core 0.4.2", 632 "rand_core 0.4.2",
648 "rand_hc 0.1.0", 633 "rand_hc",
649 "rand_isaac", 634 "rand_isaac",
650 "rand_jitter", 635 "rand_jitter",
651 "rand_os", 636 "rand_os",
@@ -655,19 +640,6 @@ dependencies = [
655] 640]
656 641
657[[package]] 642[[package]]
658name = "rand"
659version = "0.7.3"
660source = "registry+https://github.com/rust-lang/crates.io-index"
661checksum = "6a6b1679d49b24bbfe0c803429aa1874472f50d9b363131f0e89fc356b544d03"
662dependencies = [
663 "getrandom",
664 "libc",
665 "rand_chacha 0.2.2",
666 "rand_core 0.5.1",
667 "rand_hc 0.2.0",
668]
669
670[[package]]
671name = "rand_chacha" 643name = "rand_chacha"
672version = "0.1.1" 644version = "0.1.1"
673source = "registry+https://github.com/rust-lang/crates.io-index" 645source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -678,16 +650,6 @@ dependencies = [
678] 650]
679 651
680[[package]] 652[[package]]
681name = "rand_chacha"
682version = "0.2.2"
683source = "registry+https://github.com/rust-lang/crates.io-index"
684checksum = "f4c8ed856279c9737206bf725bf36935d8666ead7aa69b52be55af369d193402"
685dependencies = [
686 "ppv-lite86",
687 "rand_core 0.5.1",
688]
689
690[[package]]
691name = "rand_core" 653name = "rand_core"
692version = "0.3.1" 654version = "0.3.1"
693source = "registry+https://github.com/rust-lang/crates.io-index" 655source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -703,15 +665,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
703checksum = "9c33a3c44ca05fa6f1807d8e6743f3824e8509beca625669633be0acbdf509dc" 665checksum = "9c33a3c44ca05fa6f1807d8e6743f3824e8509beca625669633be0acbdf509dc"
704 666
705[[package]] 667[[package]]
706name = "rand_core"
707version = "0.5.1"
708source = "registry+https://github.com/rust-lang/crates.io-index"
709checksum = "90bde5296fc891b0cef12a6d03ddccc162ce7b2aff54160af9338f8d40df6d19"
710dependencies = [
711 "getrandom",
712]
713
714[[package]]
715name = "rand_hc" 668name = "rand_hc"
716version = "0.1.0" 669version = "0.1.0"
717source = "registry+https://github.com/rust-lang/crates.io-index" 670source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -721,15 +674,6 @@ dependencies = [
721] 674]
722 675
723[[package]] 676[[package]]
724name = "rand_hc"
725version = "0.2.0"
726source = "registry+https://github.com/rust-lang/crates.io-index"
727checksum = "ca3129af7b92a17112d59ad498c6f81eaf463253766b90396d39ea7a39d6613c"
728dependencies = [
729 "rand_core 0.5.1",
730]
731
732[[package]]
733name = "rand_isaac" 677name = "rand_isaac"
734version = "0.1.1" 678version = "0.1.1"
735source = "registry+https://github.com/rust-lang/crates.io-index" 679source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -798,15 +742,24 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
798checksum = "41cc0f7e4d5d4544e8861606a285bb08d3e70712ccc7d2b84d7c0ccfaf4b05ce" 742checksum = "41cc0f7e4d5d4544e8861606a285bb08d3e70712ccc7d2b84d7c0ccfaf4b05ce"
799 743
800[[package]] 744[[package]]
801name = "remove_dir_all" 745name = "regex"
802version = "0.5.3" 746version = "1.3.9"
803source = "registry+https://github.com/rust-lang/crates.io-index" 747source = "registry+https://github.com/rust-lang/crates.io-index"
804checksum = "3acd125665422973a33ac9d3dd2df85edad0f4ae9b00dafb1a05e43a9f5ef8e7" 748checksum = "9c3780fcf44b193bc4d09f36d2a3c87b251da4a046c87795a0d35f4f927ad8e6"
805dependencies = [ 749dependencies = [
806 "winapi 0.3.9", 750 "aho-corasick",
751 "memchr",
752 "regex-syntax",
753 "thread_local",
807] 754]
808 755
809[[package]] 756[[package]]
757name = "regex-syntax"
758version = "0.6.18"
759source = "registry+https://github.com/rust-lang/crates.io-index"
760checksum = "26412eb97c6b088a6997e05f69403a802a92d520de2f8e63c2b65f9e0f47c4e8"
761
762[[package]]
810name = "rusqlite" 763name = "rusqlite"
811version = "0.24.0" 764version = "0.24.0"
812source = "registry+https://github.com/rust-lang/crates.io-index" 765source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -822,12 +775,6 @@ dependencies = [
822] 775]
823 776
824[[package]] 777[[package]]
825name = "safemem"
826version = "0.3.3"
827source = "registry+https://github.com/rust-lang/crates.io-index"
828checksum = "ef703b7cb59335eae2eb93ceb664c0eb7ea6bf567079d843e09420219668e072"
829
830[[package]]
831name = "signal-hook-registry" 778name = "signal-hook-registry"
832version = "1.2.1" 779version = "1.2.1"
833source = "registry+https://github.com/rust-lang/crates.io-index" 780source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -873,17 +820,12 @@ dependencies = [
873] 820]
874 821
875[[package]] 822[[package]]
876name = "tempfile" 823name = "thread_local"
877version = "3.1.0" 824version = "1.0.1"
878source = "registry+https://github.com/rust-lang/crates.io-index" 825source = "registry+https://github.com/rust-lang/crates.io-index"
879checksum = "7a6e24d9338a0a5be79593e2fa15a648add6138caa803e2d5bc782c371732ca9" 826checksum = "d40c6d1b69745a6ec6fb1ca717914848da4b44ae29d9b3080cbee91d72a69b14"
880dependencies = [ 827dependencies = [
881 "cfg-if", 828 "lazy_static",
882 "libc",
883 "rand 0.7.3",
884 "redox_syscall",
885 "remove_dir_all",
886 "winapi 0.3.9",
887] 829]
888 830
889[[package]] 831[[package]]
@@ -946,7 +888,7 @@ dependencies = [
946 "bytes", 888 "bytes",
947 "futures-core", 889 "futures-core",
948 "futures-sink", 890 "futures-sink",
949 "log 0.4.11", 891 "log",
950 "pin-project-lite", 892 "pin-project-lite",
951 "tokio", 893 "tokio",
952] 894]
@@ -964,7 +906,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
964checksum = "6d79ca061b032d6ce30c660fded31189ca0b9922bf483cd70759f13a2d86786c" 906checksum = "6d79ca061b032d6ce30c660fded31189ca0b9922bf483cd70759f13a2d86786c"
965dependencies = [ 907dependencies = [
966 "cfg-if", 908 "cfg-if",
967 "log 0.4.11", 909 "log",
968 "tracing-core", 910 "tracing-core",
969] 911]
970 912
@@ -978,12 +920,6 @@ dependencies = [
978] 920]
979 921
980[[package]] 922[[package]]
981name = "traitobject"
982version = "0.1.0"
983source = "registry+https://github.com/rust-lang/crates.io-index"
984checksum = "efd1f82c56340fdf16f2a953d7bda4f8fdffba13d93b00844c25572110b26079"
985
986[[package]]
987name = "try-lock" 923name = "try-lock"
988version = "0.2.3" 924version = "0.2.3"
989source = "registry+https://github.com/rust-lang/crates.io-index" 925source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -991,36 +927,19 @@ checksum = "59547bce71d9c38b83d9c0e92b6066c4253371f15005def0c30d9657f50c7642"
991 927
992[[package]] 928[[package]]
993name = "twoway" 929name = "twoway"
994version = "0.1.8" 930version = "0.2.1"
995source = "registry+https://github.com/rust-lang/crates.io-index" 931source = "registry+https://github.com/rust-lang/crates.io-index"
996checksum = "59b11b2b5241ba34be09c3cc85a36e56e48f9888862e19cedf23336d35316ed1" 932checksum = "6b40075910de3a912adbd80b5d8bad6ad10a23eeb1f5bf9d4006839e899ba5bc"
997dependencies = [ 933dependencies = [
998 "memchr", 934 "memchr",
935 "unchecked-index",
999] 936]
1000 937
1001[[package]] 938[[package]]
1002name = "typeable" 939name = "unchecked-index"
1003version = "0.1.2" 940version = "0.2.2"
1004source = "registry+https://github.com/rust-lang/crates.io-index"
1005checksum = "1410f6f91f21d1612654e7cc69193b0334f909dcf2c790c4826254fbb86f8887"
1006
1007[[package]]
1008name = "unicase"
1009version = "1.4.2"
1010source = "registry+https://github.com/rust-lang/crates.io-index"
1011checksum = "7f4765f83163b74f957c797ad9253caf97f103fb064d3999aea9568d09fc8a33"
1012dependencies = [
1013 "version_check 0.1.5",
1014]
1015
1016[[package]]
1017name = "unicase"
1018version = "2.6.0"
1019source = "registry+https://github.com/rust-lang/crates.io-index" 941source = "registry+https://github.com/rust-lang/crates.io-index"
1020checksum = "50f37be617794602aabbeee0be4f259dc1778fabe05e2d67ee8f79326d5cb4f6" 942checksum = "eeba86d422ce181a719445e51872fa30f1f7413b62becb52e95ec91aa262d85c"
1021dependencies = [
1022 "version_check 0.9.2",
1023]
1024 943
1025[[package]] 944[[package]]
1026name = "unicode-bidi" 945name = "unicode-bidi"
@@ -1048,24 +967,13 @@ checksum = "f7fe0bb3479651439c9112f72b6c505038574c9fbb575ed1bf3b797fa39dd564"
1048 967
1049[[package]] 968[[package]]
1050name = "url" 969name = "url"
1051version = "1.7.2"
1052source = "registry+https://github.com/rust-lang/crates.io-index"
1053checksum = "dd4e7c0d531266369519a4aa4f399d748bd37043b00bde1e4ff1f60a120b355a"
1054dependencies = [
1055 "idna 0.1.5",
1056 "matches",
1057 "percent-encoding 1.0.1",
1058]
1059
1060[[package]]
1061name = "url"
1062version = "2.1.1" 970version = "2.1.1"
1063source = "registry+https://github.com/rust-lang/crates.io-index" 971source = "registry+https://github.com/rust-lang/crates.io-index"
1064checksum = "829d4a8476c35c9bf0bbce5a3b23f4106f79728039b726d292bb93bc106787cb" 972checksum = "829d4a8476c35c9bf0bbce5a3b23f4106f79728039b726d292bb93bc106787cb"
1065dependencies = [ 973dependencies = [
1066 "idna 0.2.0", 974 "idna",
1067 "matches", 975 "matches",
1068 "percent-encoding 2.1.0", 976 "percent-encoding",
1069] 977]
1070 978
1071[[package]] 979[[package]]
@@ -1075,34 +983,16 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
1075checksum = "6454029bf181f092ad1b853286f23e2c507d8e8194d01d92da4a55c274a5508c" 983checksum = "6454029bf181f092ad1b853286f23e2c507d8e8194d01d92da4a55c274a5508c"
1076 984
1077[[package]] 985[[package]]
1078name = "version_check"
1079version = "0.1.5"
1080source = "registry+https://github.com/rust-lang/crates.io-index"
1081checksum = "914b1a6776c4c929a602fafd8bc742e06365d4bcbe48c30f9cca5824f70dc9dd"
1082
1083[[package]]
1084name = "version_check"
1085version = "0.9.2"
1086source = "registry+https://github.com/rust-lang/crates.io-index"
1087checksum = "b5a972e5669d67ba988ce3dc826706fb0a8b01471c088cb0b6110b805cc36aed"
1088
1089[[package]]
1090name = "want" 986name = "want"
1091version = "0.3.0" 987version = "0.3.0"
1092source = "registry+https://github.com/rust-lang/crates.io-index" 988source = "registry+https://github.com/rust-lang/crates.io-index"
1093checksum = "1ce8a968cb1cd110d136ff8b819a556d6fb6d919363c61534f6860c7eb172ba0" 989checksum = "1ce8a968cb1cd110d136ff8b819a556d6fb6d919363c61534f6860c7eb172ba0"
1094dependencies = [ 990dependencies = [
1095 "log 0.4.11", 991 "log",
1096 "try-lock", 992 "try-lock",
1097] 993]
1098 994
1099[[package]] 995[[package]]
1100name = "wasi"
1101version = "0.9.0+wasi-snapshot-preview1"
1102source = "registry+https://github.com/rust-lang/crates.io-index"
1103checksum = "cccddf32554fecc6acb585f82a32a72e28b48f8c4c1883ddfeeeaa96f7d8e519"
1104
1105[[package]]
1106name = "winapi" 996name = "winapi"
1107version = "0.2.8" 997version = "0.2.8"
1108source = "registry+https://github.com/rust-lang/crates.io-index" 998source = "registry+https://github.com/rust-lang/crates.io-index"
diff --git a/Cargo.toml b/Cargo.toml
index 4eada2d..b180b0d 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -13,8 +13,6 @@ rusqlite = "0.24.0"
13nanoid = "0.3.0" 13nanoid = "0.3.0"
14url = "2.1.1" 14url = "2.1.1"
15anyhow = "1.0" 15anyhow = "1.0"
16futures = "0.3.5"
17multer = "1.2"
16 18
17[dependencies.multipart]
18default-features = false
19features = [ "hyper", "server" ]
20version = "0.17.0"
diff --git a/src/main.rs b/src/main.rs
index cb76d5b..769ed03 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -1,6 +1,8 @@
1use anyhow::{Context, Result}; 1use anyhow::{Context, Result};
2use hyper::header::CONTENT_TYPE;
2use hyper::service::{make_service_fn, service_fn}; 3use hyper::service::{make_service_fn, service_fn};
3use hyper::{Body, Method, Request, Response, Server, StatusCode}; 4use hyper::{Body, Method, Request, Response, Server, StatusCode};
5use multer::Multipart;
4use nanoid::nanoid; 6use nanoid::nanoid;
5use rusqlite::{params, Connection, OpenFlags, NO_PARAMS}; 7use rusqlite::{params, Connection, OpenFlags, NO_PARAMS};
6use url::form_urlencoded; 8use url::form_urlencoded;
@@ -34,34 +36,62 @@ fn get_link<S: AsRef<str>>(url: S, conn: &mut Connection) -> Result<Option<Strin
34 } 36 }
35} 37}
36 38
39async fn process_multipart(body: Body, boundary: String) -> Result<Response<Body>> {
40 let mut m = Multipart::new(body, boundary);
41 if let Some(field) = m.next_field().await? {
42 let content = field
43 .text()
44 .await
45 .with_context(|| format!("Expected field name"))?;
46 eprintln!("{}", content);
47 }
48 Ok(Response::builder()
49 .status(StatusCode::OK)
50 .body(Body::empty())?)
51}
52
37async fn shortner_service(req: Request<Body>) -> Result<Response<Body>> { 53async fn shortner_service(req: Request<Body>) -> Result<Response<Body>> {
38 let mut conn = init_db("./urls.db_3").unwrap(); 54 let mut conn = init_db("./urls.db_3").unwrap();
39 eprintln!("{:?}", req);
40 55
41 match req.method() { 56 match req.method() {
42 &Method::POST => { 57 &Method::POST => {
43 let b = hyper::body::to_bytes(req) 58 let boundary = req
44 .await 59 .headers()
45 .with_context(|| format!("Failed to stream request body!"))?; 60 .get(CONTENT_TYPE)
61 .and_then(|ct| ct.to_str().ok())
62 .and_then(|ct| multer::parse_boundary(ct).ok());
46 63
47 let params = form_urlencoded::parse(b.as_ref()) 64 // Send `BAD_REQUEST` status if the content-type is not multipart/form-data.
48 .into_owned() 65 if boundary.is_none() {
49 .collect::<HashMap<String, String>>(); 66 let b = hyper::body::to_bytes(req)
67 .await
68 .with_context(|| format!("Failed to stream request body!"))?;
50 69
51 if let Some(n) = params.get("shorten") { 70 let params = form_urlencoded::parse(b.as_ref())
52 let shortlink = shorten(n, &mut conn)?; 71 .into_owned()
53 eprintln!("{}", shortlink); 72 .collect::<HashMap<String, String>>();
54 let res = Response::builder() 73
55 .status(StatusCode::OK) 74 if let Some(n) = params.get("shorten") {
56 .header("content-type", "text/html") 75 let shortlink = shorten(n, &mut conn)?;
57 .body(Body::from(shortlink))?; 76 eprintln!("{}", shortlink);
58 Ok(res) 77 let res = Response::builder()
78 .status(StatusCode::OK)
79 .header("content-type", "text/html")
80 .body(Body::from(shortlink))?;
81 return Ok(res);
82 } else {
83 eprintln!("hello world");
84 let res = Response::builder()
85 .status(StatusCode::UNPROCESSABLE_ENTITY)
86 .body(Body::empty())?;
87 return Ok(res);
88 }
89 }
90
91 if let Ok(res) = process_multipart(req.into_body(), boundary.unwrap()).await {
92 return Ok(res);
59 } else { 93 } else {
60 eprintln!("hello world"); 94 panic!("nani");
61 let res = Response::builder()
62 .status(StatusCode::UNPROCESSABLE_ENTITY)
63 .body(Body::empty())?;
64 Ok(res)
65 } 95 }
66 } 96 }
67 &Method::GET => { 97 &Method::GET => {
@@ -113,9 +143,7 @@ async fn main() -> Result<()> {
113 make_service_fn(|_| async { Ok::<_, hyper::Error>(service_fn(shortner_service)) }); 143 make_service_fn(|_| async { Ok::<_, hyper::Error>(service_fn(shortner_service)) });
114 144
115 let server = Server::bind(&addr).serve(service); 145 let server = Server::bind(&addr).serve(service);
116
117 println!("Listening on http://{}", addr); 146 println!("Listening on http://{}", addr);
118
119 server.await.unwrap(); 147 server.await.unwrap();
120 Ok(()) 148 Ok(())
121} 149}