diff options
author | Akshay <[email protected]> | 2020-08-23 08:33:21 +0100 |
---|---|---|
committer | Akshay <[email protected]> | 2020-08-23 08:33:21 +0100 |
commit | 21f1d776762035012f02be39c96978b0719e0613 (patch) | |
tree | 24fd73624f305281c391825875dcaf941e716090 | |
parent | f36a8fb2eee46cffa87213e070136e5f28194a16 (diff) |
initial multipart handling
-rw-r--r-- | Cargo.lock | 402 | ||||
-rw-r--r-- | Cargo.toml | 6 | ||||
-rw-r--r-- | src/main.rs | 72 |
3 files changed, 198 insertions, 282 deletions
@@ -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]] |
4 | name = "aho-corasick" | ||
5 | version = "0.7.13" | ||
6 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
7 | checksum = "043164d8ba5c4c3035fec9bbee8647c0261d788f3474306f93bb65901cae0e86" | ||
8 | dependencies = [ | ||
9 | "memchr", | ||
10 | ] | ||
11 | |||
12 | [[package]] | ||
4 | name = "anyhow" | 13 | name = "anyhow" |
5 | version = "1.0.32" | 14 | version = "1.0.32" |
6 | source = "registry+https://github.com/rust-lang/crates.io-index" | 15 | source = "registry+https://github.com/rust-lang/crates.io-index" |
@@ -25,38 +34,12 @@ source = "registry+https://github.com/rust-lang/crates.io-index" | |||
25 | checksum = "cdb031dd78e28731d87d56cc8ffef4a8f36ca26c38fe2de700543e627f8a464a" | 34 | checksum = "cdb031dd78e28731d87d56cc8ffef4a8f36ca26c38fe2de700543e627f8a464a" |
26 | 35 | ||
27 | [[package]] | 36 | [[package]] |
28 | name = "base64" | ||
29 | version = "0.9.3" | ||
30 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
31 | checksum = "489d6c0ed21b11d038c31b6ceccca973e65d73ba3bd8ecb9a2babf5546164643" | ||
32 | dependencies = [ | ||
33 | "byteorder", | ||
34 | "safemem", | ||
35 | ] | ||
36 | |||
37 | [[package]] | ||
38 | name = "bitflags" | 37 | name = "bitflags" |
39 | version = "1.2.1" | 38 | version = "1.2.1" |
40 | source = "registry+https://github.com/rust-lang/crates.io-index" | 39 | source = "registry+https://github.com/rust-lang/crates.io-index" |
41 | checksum = "cf1de2fe8c75bc145a2f577add951f8134889b4795d47466a54a5c846d691693" | 40 | checksum = "cf1de2fe8c75bc145a2f577add951f8134889b4795d47466a54a5c846d691693" |
42 | 41 | ||
43 | [[package]] | 42 | [[package]] |
44 | name = "buf_redux" | ||
45 | version = "0.8.4" | ||
46 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
47 | checksum = "b953a6887648bb07a535631f2bc00fbdb2a2216f135552cb3f534ed136b9c07f" | ||
48 | dependencies = [ | ||
49 | "memchr", | ||
50 | "safemem", | ||
51 | ] | ||
52 | |||
53 | [[package]] | ||
54 | name = "byteorder" | ||
55 | version = "1.3.4" | ||
56 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
57 | checksum = "08c48aae112d48ed9f069b33538ea9e3e90aa263cfa3d1c24309612b1f7472de" | ||
58 | |||
59 | [[package]] | ||
60 | name = "bytes" | 43 | name = "bytes" |
61 | version = "0.5.6" | 44 | version = "0.5.6" |
62 | source = "registry+https://github.com/rust-lang/crates.io-index" | 45 | source = "registry+https://github.com/rust-lang/crates.io-index" |
@@ -78,6 +61,26 @@ dependencies = [ | |||
78 | ] | 61 | ] |
79 | 62 | ||
80 | [[package]] | 63 | [[package]] |
64 | name = "derive_more" | ||
65 | version = "0.99.9" | ||
66 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
67 | checksum = "298998b1cf6b5b2c8a7b023dfd45821825ce3ba8a8af55c921a0e734e4653f76" | ||
68 | dependencies = [ | ||
69 | "proc-macro2", | ||
70 | "quote", | ||
71 | "syn", | ||
72 | ] | ||
73 | |||
74 | [[package]] | ||
75 | name = "encoding_rs" | ||
76 | version = "0.8.23" | ||
77 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
78 | checksum = "e8ac63f94732332f44fe654443c46f6375d1939684c17b0afb6cb56b0456e171" | ||
79 | dependencies = [ | ||
80 | "cfg-if", | ||
81 | ] | ||
82 | |||
83 | [[package]] | ||
81 | name = "fallible-iterator" | 84 | name = "fallible-iterator" |
82 | version = "0.2.0" | 85 | version = "0.2.0" |
83 | source = "registry+https://github.com/rust-lang/crates.io-index" | 86 | source = "registry+https://github.com/rust-lang/crates.io-index" |
@@ -118,12 +121,28 @@ source = "registry+https://github.com/rust-lang/crates.io-index" | |||
118 | checksum = "3dcaa9ae7725d12cdb85b3ad99a434db70b468c09ded17e012d86b5c1010f7a7" | 121 | checksum = "3dcaa9ae7725d12cdb85b3ad99a434db70b468c09ded17e012d86b5c1010f7a7" |
119 | 122 | ||
120 | [[package]] | 123 | [[package]] |
124 | name = "futures" | ||
125 | version = "0.3.5" | ||
126 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
127 | checksum = "1e05b85ec287aac0dc34db7d4a569323df697f9c55b99b15d6b4ef8cde49f613" | ||
128 | dependencies = [ | ||
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]] | ||
121 | name = "futures-channel" | 139 | name = "futures-channel" |
122 | version = "0.3.5" | 140 | version = "0.3.5" |
123 | source = "registry+https://github.com/rust-lang/crates.io-index" | 141 | source = "registry+https://github.com/rust-lang/crates.io-index" |
124 | checksum = "f366ad74c28cca6ba456d95e6422883cfb4b252a83bed929c83abfdbbf2967d5" | 142 | checksum = "f366ad74c28cca6ba456d95e6422883cfb4b252a83bed929c83abfdbbf2967d5" |
125 | dependencies = [ | 143 | dependencies = [ |
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" | |||
133 | checksum = "59f5fff90fd5d971f936ad674802482ba441b6f09ba5e15fd8b39145582ca399" | 152 | checksum = "59f5fff90fd5d971f936ad674802482ba441b6f09ba5e15fd8b39145582ca399" |
134 | 153 | ||
135 | [[package]] | 154 | [[package]] |
155 | name = "futures-executor" | ||
156 | version = "0.3.5" | ||
157 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
158 | checksum = "10d6bb888be1153d3abeb9006b11b02cf5e9b209fda28693c31ae1e4e012e314" | ||
159 | dependencies = [ | ||
160 | "futures-core", | ||
161 | "futures-task", | ||
162 | "futures-util", | ||
163 | ] | ||
164 | |||
165 | [[package]] | ||
166 | name = "futures-io" | ||
167 | version = "0.3.5" | ||
168 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
169 | checksum = "de27142b013a8e869c14957e6d2edeef89e97c289e69d042ee3a49acd8b51789" | ||
170 | |||
171 | [[package]] | ||
172 | name = "futures-macro" | ||
173 | version = "0.3.5" | ||
174 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
175 | checksum = "d0b5a30a4328ab5473878237c447333c093297bded83a4983d10f4deea240d39" | ||
176 | dependencies = [ | ||
177 | "proc-macro-hack", | ||
178 | "proc-macro2", | ||
179 | "quote", | ||
180 | "syn", | ||
181 | ] | ||
182 | |||
183 | [[package]] | ||
136 | name = "futures-sink" | 184 | name = "futures-sink" |
137 | version = "0.3.5" | 185 | version = "0.3.5" |
138 | source = "registry+https://github.com/rust-lang/crates.io-index" | 186 | source = "registry+https://github.com/rust-lang/crates.io-index" |
@@ -143,6 +191,9 @@ name = "futures-task" | |||
143 | version = "0.3.5" | 191 | version = "0.3.5" |
144 | source = "registry+https://github.com/rust-lang/crates.io-index" | 192 | source = "registry+https://github.com/rust-lang/crates.io-index" |
145 | checksum = "bdb66b5f09e22019b1ab0830f7785bcea8e7a42148683f99214f73f8ec21a626" | 193 | checksum = "bdb66b5f09e22019b1ab0830f7785bcea8e7a42148683f99214f73f8ec21a626" |
194 | dependencies = [ | ||
195 | "once_cell", | ||
196 | ] | ||
146 | 197 | ||
147 | [[package]] | 198 | [[package]] |
148 | name = "futures-util" | 199 | name = "futures-util" |
@@ -150,21 +201,18 @@ version = "0.3.5" | |||
150 | source = "registry+https://github.com/rust-lang/crates.io-index" | 201 | source = "registry+https://github.com/rust-lang/crates.io-index" |
151 | checksum = "8764574ff08b701a084482c3c7031349104b07ac897393010494beaa18ce32c6" | 202 | checksum = "8764574ff08b701a084482c3c7031349104b07ac897393010494beaa18ce32c6" |
152 | dependencies = [ | 203 | dependencies = [ |
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", |
160 | name = "getrandom" | ||
161 | version = "0.1.14" | ||
162 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
163 | checksum = "7abc8dd8451921606d809ba32e95b6111925cd2906060d2dcc29c070220503eb" | ||
164 | dependencies = [ | ||
165 | "cfg-if", | ||
166 | "libc", | ||
167 | "wasi", | ||
168 | ] | 216 | ] |
169 | 217 | ||
170 | [[package]] | 218 | [[package]] |
@@ -200,12 +248,13 @@ name = "hedge" | |||
200 | version = "0.1.0" | 248 | version = "0.1.0" |
201 | dependencies = [ | 249 | dependencies = [ |
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]] |
248 | name = "hyper" | 297 | name = "hyper" |
249 | version = "0.10.16" | ||
250 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
251 | checksum = "0a0652d9a2609a968c14be1a9ea00bf4b1d64e2e1f53a1b51b6fff3a6e829273" | ||
252 | dependencies = [ | ||
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]] | ||
267 | name = "hyper" | ||
268 | version = "0.13.7" | 298 | version = "0.13.7" |
269 | source = "registry+https://github.com/rust-lang/crates.io-index" | 299 | source = "registry+https://github.com/rust-lang/crates.io-index" |
270 | checksum = "3e68a8dd9716185d9e64ea473ea6ef63529252e3e27623295a0378a19665d5eb" | 300 | checksum = "3e68a8dd9716185d9e64ea473ea6ef63529252e3e27623295a0378a19665d5eb" |
@@ -289,17 +319,6 @@ dependencies = [ | |||
289 | 319 | ||
290 | [[package]] | 320 | [[package]] |
291 | name = "idna" | 321 | name = "idna" |
292 | version = "0.1.5" | ||
293 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
294 | checksum = "38f09e0f0b1fb55fdee1f17470ad800da77af5186a1a76c026b679358b7e844e" | ||
295 | dependencies = [ | ||
296 | "matches", | ||
297 | "unicode-bidi", | ||
298 | "unicode-normalization", | ||
299 | ] | ||
300 | |||
301 | [[package]] | ||
302 | name = "idna" | ||
303 | version = "0.2.0" | 322 | version = "0.2.0" |
304 | source = "registry+https://github.com/rust-lang/crates.io-index" | 323 | source = "registry+https://github.com/rust-lang/crates.io-index" |
305 | checksum = "02e2673c30ee86b5b96a9cb52ad15718aa1f966f5ab9ad54a8b95d5ca33120a9" | 324 | checksum = "02e2673c30ee86b5b96a9cb52ad15718aa1f966f5ab9ad54a8b95d5ca33120a9" |
@@ -345,12 +364,6 @@ dependencies = [ | |||
345 | ] | 364 | ] |
346 | 365 | ||
347 | [[package]] | 366 | [[package]] |
348 | name = "language-tags" | ||
349 | version = "0.2.2" | ||
350 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
351 | checksum = "a91d884b6667cd606bb5a69aa0c99ba811a115fc68915e7056ec08a46e93199a" | ||
352 | |||
353 | [[package]] | ||
354 | name = "lazy_static" | 367 | name = "lazy_static" |
355 | version = "1.4.0" | 368 | version = "1.4.0" |
356 | source = "registry+https://github.com/rust-lang/crates.io-index" | 369 | source = "registry+https://github.com/rust-lang/crates.io-index" |
@@ -380,15 +393,6 @@ checksum = "8dd5a6d5999d9907cda8ed67bbd137d3af8085216c2ac62de5be860bd41f304a" | |||
380 | 393 | ||
381 | [[package]] | 394 | [[package]] |
382 | name = "log" | 395 | name = "log" |
383 | version = "0.3.9" | ||
384 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
385 | checksum = "e19e8d5c34a3e0e2223db8e060f9e8264aeeb5c5fc64a4ee9965c062211c024b" | ||
386 | dependencies = [ | ||
387 | "log 0.4.11", | ||
388 | ] | ||
389 | |||
390 | [[package]] | ||
391 | name = "log" | ||
392 | version = "0.4.11" | 396 | version = "0.4.11" |
393 | source = "registry+https://github.com/rust-lang/crates.io-index" | 397 | source = "registry+https://github.com/rust-lang/crates.io-index" |
394 | checksum = "4fabed175da42fed1fa0746b0ea71f412aa9d35e76e95e59b192c64b9dc2bf8b" | 398 | checksum = "4fabed175da42fed1fa0746b0ea71f412aa9d35e76e95e59b192c64b9dc2bf8b" |
@@ -419,30 +423,11 @@ checksum = "3728d817d99e5ac407411fa471ff9800a778d88a24685968b36824eaf4bee400" | |||
419 | 423 | ||
420 | [[package]] | 424 | [[package]] |
421 | name = "mime" | 425 | name = "mime" |
422 | version = "0.2.6" | ||
423 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
424 | checksum = "ba626b8a6de5da682e1caa06bdb42a335aee5a84db8e5046a3e8ab17ba0a3ae0" | ||
425 | dependencies = [ | ||
426 | "log 0.3.9", | ||
427 | ] | ||
428 | |||
429 | [[package]] | ||
430 | name = "mime" | ||
431 | version = "0.3.16" | 426 | version = "0.3.16" |
432 | source = "registry+https://github.com/rust-lang/crates.io-index" | 427 | source = "registry+https://github.com/rust-lang/crates.io-index" |
433 | checksum = "2a60c7ce501c71e03a9c9c0d35b861413ae925bd979cc7a4e30d060069aaac8d" | 428 | checksum = "2a60c7ce501c71e03a9c9c0d35b861413ae925bd979cc7a4e30d060069aaac8d" |
434 | 429 | ||
435 | [[package]] | 430 | [[package]] |
436 | name = "mime_guess" | ||
437 | version = "2.0.3" | ||
438 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
439 | checksum = "2684d4c2e97d99848d30b324b00c8fcc7e5c897b7cbb5819b09e7c90e8baf212" | ||
440 | dependencies = [ | ||
441 | "mime 0.3.16", | ||
442 | "unicase 2.6.0", | ||
443 | ] | ||
444 | |||
445 | [[package]] | ||
446 | name = "mio" | 431 | name = "mio" |
447 | version = "0.6.22" | 432 | version = "0.6.22" |
448 | source = "registry+https://github.com/rust-lang/crates.io-index" | 433 | source = "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" | |||
467 | source = "registry+https://github.com/rust-lang/crates.io-index" | 452 | source = "registry+https://github.com/rust-lang/crates.io-index" |
468 | checksum = "0840c1c50fd55e521b247f949c241c9997709f23bd7f023b9762cd561e935656" | 453 | checksum = "0840c1c50fd55e521b247f949c241c9997709f23bd7f023b9762cd561e935656" |
469 | dependencies = [ | 454 | dependencies = [ |
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]] |
510 | name = "multipart" | 495 | name = "multer" |
511 | version = "0.17.0" | 496 | version = "1.2.2" |
512 | source = "registry+https://github.com/rust-lang/crates.io-index" | 497 | source = "registry+https://github.com/rust-lang/crates.io-index" |
513 | checksum = "8209c33c951f07387a8497841122fc6f712165e3f9bda3e6be4645b58188f676" | 498 | checksum = "99851e6ad01b0fbe086dda2dea00d68bb84fc7d7eae2c39ca7313da9197f4d31" |
514 | dependencies = [ | 499 | dependencies = [ |
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" | |||
531 | source = "registry+https://github.com/rust-lang/crates.io-index" | 516 | source = "registry+https://github.com/rust-lang/crates.io-index" |
532 | checksum = "a6226bc4e142124cb44e309a37a04cd9bb10e740d8642855441d3b14808f635e" | 517 | checksum = "a6226bc4e142124cb44e309a37a04cd9bb10e740d8642855441d3b14808f635e" |
533 | dependencies = [ | 518 | dependencies = [ |
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]] |
559 | name = "percent-encoding" | 544 | name = "once_cell" |
560 | version = "1.0.1" | 545 | version = "1.4.1" |
561 | source = "registry+https://github.com/rust-lang/crates.io-index" | 546 | source = "registry+https://github.com/rust-lang/crates.io-index" |
562 | checksum = "31010dd2e1ac33d5b46a5b413495239882813e0369f8ed8a5e266f173602f831" | 547 | checksum = "260e51e7efe62b592207e9e13a68e43692a7a279171d6ba57abd208bf23645ad" |
563 | 548 | ||
564 | [[package]] | 549 | [[package]] |
565 | name = "percent-encoding" | 550 | name = "percent-encoding" |
@@ -606,10 +591,16 @@ source = "registry+https://github.com/rust-lang/crates.io-index" | |||
606 | checksum = "d36492546b6af1463394d46f0c834346f31548646f6ba10849802c9c9a27ac33" | 591 | checksum = "d36492546b6af1463394d46f0c834346f31548646f6ba10849802c9c9a27ac33" |
607 | 592 | ||
608 | [[package]] | 593 | [[package]] |
609 | name = "ppv-lite86" | 594 | name = "proc-macro-hack" |
610 | version = "0.2.9" | 595 | version = "0.5.18" |
596 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
597 | checksum = "99c605b9a0adc77b7211c6b1f722dcb613d68d66859a44f3d485a6da332b0598" | ||
598 | |||
599 | [[package]] | ||
600 | name = "proc-macro-nested" | ||
601 | version = "0.1.6" | ||
611 | source = "registry+https://github.com/rust-lang/crates.io-index" | 602 | source = "registry+https://github.com/rust-lang/crates.io-index" |
612 | checksum = "c36fa947111f5c62a733b652544dd0016a43ce89619538a8ef92724a6f501a20" | 603 | checksum = "eba180dafb9038b050a4c280019bbedf9f2467b61e5d892dcad585bb57aadc5a" |
613 | 604 | ||
614 | [[package]] | 605 | [[package]] |
615 | name = "proc-macro2" | 606 | name = "proc-macro2" |
@@ -621,12 +612,6 @@ dependencies = [ | |||
621 | ] | 612 | ] |
622 | 613 | ||
623 | [[package]] | 614 | [[package]] |
624 | name = "quick-error" | ||
625 | version = "1.2.3" | ||
626 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
627 | checksum = "a1d01941d82fa2ab50be1e79e6714289dd7cde78eba4c074bc5a4374f650dfe0" | ||
628 | |||
629 | [[package]] | ||
630 | name = "quote" | 615 | name = "quote" |
631 | version = "1.0.7" | 616 | version = "1.0.7" |
632 | source = "registry+https://github.com/rust-lang/crates.io-index" | 617 | source = "registry+https://github.com/rust-lang/crates.io-index" |
@@ -643,9 +628,9 @@ checksum = "6d71dacdc3c88c1fde3885a3be3fbab9f35724e6ce99467f7d9c5026132184ca" | |||
643 | dependencies = [ | 628 | dependencies = [ |
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]] |
658 | name = "rand" | ||
659 | version = "0.7.3" | ||
660 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
661 | checksum = "6a6b1679d49b24bbfe0c803429aa1874472f50d9b363131f0e89fc356b544d03" | ||
662 | dependencies = [ | ||
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]] | ||
671 | name = "rand_chacha" | 643 | name = "rand_chacha" |
672 | version = "0.1.1" | 644 | version = "0.1.1" |
673 | source = "registry+https://github.com/rust-lang/crates.io-index" | 645 | source = "registry+https://github.com/rust-lang/crates.io-index" |
@@ -678,16 +650,6 @@ dependencies = [ | |||
678 | ] | 650 | ] |
679 | 651 | ||
680 | [[package]] | 652 | [[package]] |
681 | name = "rand_chacha" | ||
682 | version = "0.2.2" | ||
683 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
684 | checksum = "f4c8ed856279c9737206bf725bf36935d8666ead7aa69b52be55af369d193402" | ||
685 | dependencies = [ | ||
686 | "ppv-lite86", | ||
687 | "rand_core 0.5.1", | ||
688 | ] | ||
689 | |||
690 | [[package]] | ||
691 | name = "rand_core" | 653 | name = "rand_core" |
692 | version = "0.3.1" | 654 | version = "0.3.1" |
693 | source = "registry+https://github.com/rust-lang/crates.io-index" | 655 | source = "registry+https://github.com/rust-lang/crates.io-index" |
@@ -703,15 +665,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index" | |||
703 | checksum = "9c33a3c44ca05fa6f1807d8e6743f3824e8509beca625669633be0acbdf509dc" | 665 | checksum = "9c33a3c44ca05fa6f1807d8e6743f3824e8509beca625669633be0acbdf509dc" |
704 | 666 | ||
705 | [[package]] | 667 | [[package]] |
706 | name = "rand_core" | ||
707 | version = "0.5.1" | ||
708 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
709 | checksum = "90bde5296fc891b0cef12a6d03ddccc162ce7b2aff54160af9338f8d40df6d19" | ||
710 | dependencies = [ | ||
711 | "getrandom", | ||
712 | ] | ||
713 | |||
714 | [[package]] | ||
715 | name = "rand_hc" | 668 | name = "rand_hc" |
716 | version = "0.1.0" | 669 | version = "0.1.0" |
717 | source = "registry+https://github.com/rust-lang/crates.io-index" | 670 | source = "registry+https://github.com/rust-lang/crates.io-index" |
@@ -721,15 +674,6 @@ dependencies = [ | |||
721 | ] | 674 | ] |
722 | 675 | ||
723 | [[package]] | 676 | [[package]] |
724 | name = "rand_hc" | ||
725 | version = "0.2.0" | ||
726 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
727 | checksum = "ca3129af7b92a17112d59ad498c6f81eaf463253766b90396d39ea7a39d6613c" | ||
728 | dependencies = [ | ||
729 | "rand_core 0.5.1", | ||
730 | ] | ||
731 | |||
732 | [[package]] | ||
733 | name = "rand_isaac" | 677 | name = "rand_isaac" |
734 | version = "0.1.1" | 678 | version = "0.1.1" |
735 | source = "registry+https://github.com/rust-lang/crates.io-index" | 679 | source = "registry+https://github.com/rust-lang/crates.io-index" |
@@ -798,15 +742,24 @@ source = "registry+https://github.com/rust-lang/crates.io-index" | |||
798 | checksum = "41cc0f7e4d5d4544e8861606a285bb08d3e70712ccc7d2b84d7c0ccfaf4b05ce" | 742 | checksum = "41cc0f7e4d5d4544e8861606a285bb08d3e70712ccc7d2b84d7c0ccfaf4b05ce" |
799 | 743 | ||
800 | [[package]] | 744 | [[package]] |
801 | name = "remove_dir_all" | 745 | name = "regex" |
802 | version = "0.5.3" | 746 | version = "1.3.9" |
803 | source = "registry+https://github.com/rust-lang/crates.io-index" | 747 | source = "registry+https://github.com/rust-lang/crates.io-index" |
804 | checksum = "3acd125665422973a33ac9d3dd2df85edad0f4ae9b00dafb1a05e43a9f5ef8e7" | 748 | checksum = "9c3780fcf44b193bc4d09f36d2a3c87b251da4a046c87795a0d35f4f927ad8e6" |
805 | dependencies = [ | 749 | dependencies = [ |
806 | "winapi 0.3.9", | 750 | "aho-corasick", |
751 | "memchr", | ||
752 | "regex-syntax", | ||
753 | "thread_local", | ||
807 | ] | 754 | ] |
808 | 755 | ||
809 | [[package]] | 756 | [[package]] |
757 | name = "regex-syntax" | ||
758 | version = "0.6.18" | ||
759 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
760 | checksum = "26412eb97c6b088a6997e05f69403a802a92d520de2f8e63c2b65f9e0f47c4e8" | ||
761 | |||
762 | [[package]] | ||
810 | name = "rusqlite" | 763 | name = "rusqlite" |
811 | version = "0.24.0" | 764 | version = "0.24.0" |
812 | source = "registry+https://github.com/rust-lang/crates.io-index" | 765 | source = "registry+https://github.com/rust-lang/crates.io-index" |
@@ -822,12 +775,6 @@ dependencies = [ | |||
822 | ] | 775 | ] |
823 | 776 | ||
824 | [[package]] | 777 | [[package]] |
825 | name = "safemem" | ||
826 | version = "0.3.3" | ||
827 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
828 | checksum = "ef703b7cb59335eae2eb93ceb664c0eb7ea6bf567079d843e09420219668e072" | ||
829 | |||
830 | [[package]] | ||
831 | name = "signal-hook-registry" | 778 | name = "signal-hook-registry" |
832 | version = "1.2.1" | 779 | version = "1.2.1" |
833 | source = "registry+https://github.com/rust-lang/crates.io-index" | 780 | source = "registry+https://github.com/rust-lang/crates.io-index" |
@@ -873,17 +820,12 @@ dependencies = [ | |||
873 | ] | 820 | ] |
874 | 821 | ||
875 | [[package]] | 822 | [[package]] |
876 | name = "tempfile" | 823 | name = "thread_local" |
877 | version = "3.1.0" | 824 | version = "1.0.1" |
878 | source = "registry+https://github.com/rust-lang/crates.io-index" | 825 | source = "registry+https://github.com/rust-lang/crates.io-index" |
879 | checksum = "7a6e24d9338a0a5be79593e2fa15a648add6138caa803e2d5bc782c371732ca9" | 826 | checksum = "d40c6d1b69745a6ec6fb1ca717914848da4b44ae29d9b3080cbee91d72a69b14" |
880 | dependencies = [ | 827 | dependencies = [ |
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" | |||
964 | checksum = "6d79ca061b032d6ce30c660fded31189ca0b9922bf483cd70759f13a2d86786c" | 906 | checksum = "6d79ca061b032d6ce30c660fded31189ca0b9922bf483cd70759f13a2d86786c" |
965 | dependencies = [ | 907 | dependencies = [ |
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]] |
981 | name = "traitobject" | ||
982 | version = "0.1.0" | ||
983 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
984 | checksum = "efd1f82c56340fdf16f2a953d7bda4f8fdffba13d93b00844c25572110b26079" | ||
985 | |||
986 | [[package]] | ||
987 | name = "try-lock" | 923 | name = "try-lock" |
988 | version = "0.2.3" | 924 | version = "0.2.3" |
989 | source = "registry+https://github.com/rust-lang/crates.io-index" | 925 | source = "registry+https://github.com/rust-lang/crates.io-index" |
@@ -991,36 +927,19 @@ checksum = "59547bce71d9c38b83d9c0e92b6066c4253371f15005def0c30d9657f50c7642" | |||
991 | 927 | ||
992 | [[package]] | 928 | [[package]] |
993 | name = "twoway" | 929 | name = "twoway" |
994 | version = "0.1.8" | 930 | version = "0.2.1" |
995 | source = "registry+https://github.com/rust-lang/crates.io-index" | 931 | source = "registry+https://github.com/rust-lang/crates.io-index" |
996 | checksum = "59b11b2b5241ba34be09c3cc85a36e56e48f9888862e19cedf23336d35316ed1" | 932 | checksum = "6b40075910de3a912adbd80b5d8bad6ad10a23eeb1f5bf9d4006839e899ba5bc" |
997 | dependencies = [ | 933 | dependencies = [ |
998 | "memchr", | 934 | "memchr", |
935 | "unchecked-index", | ||
999 | ] | 936 | ] |
1000 | 937 | ||
1001 | [[package]] | 938 | [[package]] |
1002 | name = "typeable" | 939 | name = "unchecked-index" |
1003 | version = "0.1.2" | 940 | version = "0.2.2" |
1004 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
1005 | checksum = "1410f6f91f21d1612654e7cc69193b0334f909dcf2c790c4826254fbb86f8887" | ||
1006 | |||
1007 | [[package]] | ||
1008 | name = "unicase" | ||
1009 | version = "1.4.2" | ||
1010 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
1011 | checksum = "7f4765f83163b74f957c797ad9253caf97f103fb064d3999aea9568d09fc8a33" | ||
1012 | dependencies = [ | ||
1013 | "version_check 0.1.5", | ||
1014 | ] | ||
1015 | |||
1016 | [[package]] | ||
1017 | name = "unicase" | ||
1018 | version = "2.6.0" | ||
1019 | source = "registry+https://github.com/rust-lang/crates.io-index" | 941 | source = "registry+https://github.com/rust-lang/crates.io-index" |
1020 | checksum = "50f37be617794602aabbeee0be4f259dc1778fabe05e2d67ee8f79326d5cb4f6" | 942 | checksum = "eeba86d422ce181a719445e51872fa30f1f7413b62becb52e95ec91aa262d85c" |
1021 | dependencies = [ | ||
1022 | "version_check 0.9.2", | ||
1023 | ] | ||
1024 | 943 | ||
1025 | [[package]] | 944 | [[package]] |
1026 | name = "unicode-bidi" | 945 | name = "unicode-bidi" |
@@ -1048,24 +967,13 @@ checksum = "f7fe0bb3479651439c9112f72b6c505038574c9fbb575ed1bf3b797fa39dd564" | |||
1048 | 967 | ||
1049 | [[package]] | 968 | [[package]] |
1050 | name = "url" | 969 | name = "url" |
1051 | version = "1.7.2" | ||
1052 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
1053 | checksum = "dd4e7c0d531266369519a4aa4f399d748bd37043b00bde1e4ff1f60a120b355a" | ||
1054 | dependencies = [ | ||
1055 | "idna 0.1.5", | ||
1056 | "matches", | ||
1057 | "percent-encoding 1.0.1", | ||
1058 | ] | ||
1059 | |||
1060 | [[package]] | ||
1061 | name = "url" | ||
1062 | version = "2.1.1" | 970 | version = "2.1.1" |
1063 | source = "registry+https://github.com/rust-lang/crates.io-index" | 971 | source = "registry+https://github.com/rust-lang/crates.io-index" |
1064 | checksum = "829d4a8476c35c9bf0bbce5a3b23f4106f79728039b726d292bb93bc106787cb" | 972 | checksum = "829d4a8476c35c9bf0bbce5a3b23f4106f79728039b726d292bb93bc106787cb" |
1065 | dependencies = [ | 973 | dependencies = [ |
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" | |||
1075 | checksum = "6454029bf181f092ad1b853286f23e2c507d8e8194d01d92da4a55c274a5508c" | 983 | checksum = "6454029bf181f092ad1b853286f23e2c507d8e8194d01d92da4a55c274a5508c" |
1076 | 984 | ||
1077 | [[package]] | 985 | [[package]] |
1078 | name = "version_check" | ||
1079 | version = "0.1.5" | ||
1080 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
1081 | checksum = "914b1a6776c4c929a602fafd8bc742e06365d4bcbe48c30f9cca5824f70dc9dd" | ||
1082 | |||
1083 | [[package]] | ||
1084 | name = "version_check" | ||
1085 | version = "0.9.2" | ||
1086 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
1087 | checksum = "b5a972e5669d67ba988ce3dc826706fb0a8b01471c088cb0b6110b805cc36aed" | ||
1088 | |||
1089 | [[package]] | ||
1090 | name = "want" | 986 | name = "want" |
1091 | version = "0.3.0" | 987 | version = "0.3.0" |
1092 | source = "registry+https://github.com/rust-lang/crates.io-index" | 988 | source = "registry+https://github.com/rust-lang/crates.io-index" |
1093 | checksum = "1ce8a968cb1cd110d136ff8b819a556d6fb6d919363c61534f6860c7eb172ba0" | 989 | checksum = "1ce8a968cb1cd110d136ff8b819a556d6fb6d919363c61534f6860c7eb172ba0" |
1094 | dependencies = [ | 990 | dependencies = [ |
1095 | "log 0.4.11", | 991 | "log", |
1096 | "try-lock", | 992 | "try-lock", |
1097 | ] | 993 | ] |
1098 | 994 | ||
1099 | [[package]] | 995 | [[package]] |
1100 | name = "wasi" | ||
1101 | version = "0.9.0+wasi-snapshot-preview1" | ||
1102 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
1103 | checksum = "cccddf32554fecc6acb585f82a32a72e28b48f8c4c1883ddfeeeaa96f7d8e519" | ||
1104 | |||
1105 | [[package]] | ||
1106 | name = "winapi" | 996 | name = "winapi" |
1107 | version = "0.2.8" | 997 | version = "0.2.8" |
1108 | source = "registry+https://github.com/rust-lang/crates.io-index" | 998 | source = "registry+https://github.com/rust-lang/crates.io-index" |
@@ -13,8 +13,6 @@ rusqlite = "0.24.0" | |||
13 | nanoid = "0.3.0" | 13 | nanoid = "0.3.0" |
14 | url = "2.1.1" | 14 | url = "2.1.1" |
15 | anyhow = "1.0" | 15 | anyhow = "1.0" |
16 | futures = "0.3.5" | ||
17 | multer = "1.2" | ||
16 | 18 | ||
17 | [dependencies.multipart] | ||
18 | default-features = false | ||
19 | features = [ "hyper", "server" ] | ||
20 | version = "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 @@ | |||
1 | use anyhow::{Context, Result}; | 1 | use anyhow::{Context, Result}; |
2 | use hyper::header::CONTENT_TYPE; | ||
2 | use hyper::service::{make_service_fn, service_fn}; | 3 | use hyper::service::{make_service_fn, service_fn}; |
3 | use hyper::{Body, Method, Request, Response, Server, StatusCode}; | 4 | use hyper::{Body, Method, Request, Response, Server, StatusCode}; |
5 | use multer::Multipart; | ||
4 | use nanoid::nanoid; | 6 | use nanoid::nanoid; |
5 | use rusqlite::{params, Connection, OpenFlags, NO_PARAMS}; | 7 | use rusqlite::{params, Connection, OpenFlags, NO_PARAMS}; |
6 | use url::form_urlencoded; | 8 | use 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 | ||
39 | async 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 | |||
37 | async fn shortner_service(req: Request<Body>) -> Result<Response<Body>> { | 53 | async 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 | } |