├── .gitignore ├── .travis.yml ├── Cargo.lock ├── Cargo.toml ├── LICENSE ├── README.md ├── benches └── rustnish_vs_varnish.rs ├── examples ├── hello_9091.rs └── rustnish_9090.rs ├── src ├── cache.rs ├── lib.rs └── main.rs └── tests ├── cache.rs ├── common └── mod.rs └── response_and_headers.rs /.gitignore: -------------------------------------------------------------------------------- 1 | target/ 2 | **/*.rs.bk 3 | /.vscode 4 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: rust 2 | cache: cargo 3 | dist: bionic 4 | os: 5 | - linux 6 | - osx 7 | sudo: false 8 | 9 | # We only care about the latest stable release of Rust. 10 | rust: 11 | - stable 12 | 13 | env: 14 | - RUST_BACKTRACE=1 15 | -------------------------------------------------------------------------------- /Cargo.lock: -------------------------------------------------------------------------------- 1 | # This file is automatically @generated by Cargo. 2 | # It is not intended for manual editing. 3 | [[package]] 4 | name = "aho-corasick" 5 | version = "0.7.6" 6 | source = "registry+https://github.com/rust-lang/crates.io-index" 7 | dependencies = [ 8 | "memchr 2.2.1 (registry+https://github.com/rust-lang/crates.io-index)", 9 | ] 10 | 11 | [[package]] 12 | name = "autocfg" 13 | version = "0.1.7" 14 | source = "registry+https://github.com/rust-lang/crates.io-index" 15 | 16 | [[package]] 17 | name = "backtrace" 18 | version = "0.3.40" 19 | source = "registry+https://github.com/rust-lang/crates.io-index" 20 | dependencies = [ 21 | "backtrace-sys 0.1.32 (registry+https://github.com/rust-lang/crates.io-index)", 22 | "cfg-if 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)", 23 | "libc 0.2.65 (registry+https://github.com/rust-lang/crates.io-index)", 24 | "rustc-demangle 0.1.16 (registry+https://github.com/rust-lang/crates.io-index)", 25 | ] 26 | 27 | [[package]] 28 | name = "backtrace-sys" 29 | version = "0.1.32" 30 | source = "registry+https://github.com/rust-lang/crates.io-index" 31 | dependencies = [ 32 | "cc 1.0.47 (registry+https://github.com/rust-lang/crates.io-index)", 33 | "libc 0.2.65 (registry+https://github.com/rust-lang/crates.io-index)", 34 | ] 35 | 36 | [[package]] 37 | name = "bitflags" 38 | version = "1.2.1" 39 | source = "registry+https://github.com/rust-lang/crates.io-index" 40 | 41 | [[package]] 42 | name = "byteorder" 43 | version = "1.3.2" 44 | source = "registry+https://github.com/rust-lang/crates.io-index" 45 | 46 | [[package]] 47 | name = "bytes" 48 | version = "0.4.12" 49 | source = "registry+https://github.com/rust-lang/crates.io-index" 50 | dependencies = [ 51 | "byteorder 1.3.2 (registry+https://github.com/rust-lang/crates.io-index)", 52 | "either 1.5.3 (registry+https://github.com/rust-lang/crates.io-index)", 53 | "iovec 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)", 54 | ] 55 | 56 | [[package]] 57 | name = "c2-chacha" 58 | version = "0.2.3" 59 | source = "registry+https://github.com/rust-lang/crates.io-index" 60 | dependencies = [ 61 | "ppv-lite86 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)", 62 | ] 63 | 64 | [[package]] 65 | name = "cc" 66 | version = "1.0.47" 67 | source = "registry+https://github.com/rust-lang/crates.io-index" 68 | 69 | [[package]] 70 | name = "cfg-if" 71 | version = "0.1.10" 72 | source = "registry+https://github.com/rust-lang/crates.io-index" 73 | 74 | [[package]] 75 | name = "cloudabi" 76 | version = "0.0.3" 77 | source = "registry+https://github.com/rust-lang/crates.io-index" 78 | dependencies = [ 79 | "bitflags 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)", 80 | ] 81 | 82 | [[package]] 83 | name = "crossbeam-deque" 84 | version = "0.7.2" 85 | source = "registry+https://github.com/rust-lang/crates.io-index" 86 | dependencies = [ 87 | "crossbeam-epoch 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", 88 | "crossbeam-utils 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", 89 | ] 90 | 91 | [[package]] 92 | name = "crossbeam-epoch" 93 | version = "0.8.0" 94 | source = "registry+https://github.com/rust-lang/crates.io-index" 95 | dependencies = [ 96 | "autocfg 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)", 97 | "cfg-if 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)", 98 | "crossbeam-utils 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", 99 | "lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)", 100 | "memoffset 0.5.3 (registry+https://github.com/rust-lang/crates.io-index)", 101 | "scopeguard 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", 102 | ] 103 | 104 | [[package]] 105 | name = "crossbeam-queue" 106 | version = "0.1.2" 107 | source = "registry+https://github.com/rust-lang/crates.io-index" 108 | dependencies = [ 109 | "crossbeam-utils 0.6.6 (registry+https://github.com/rust-lang/crates.io-index)", 110 | ] 111 | 112 | [[package]] 113 | name = "crossbeam-utils" 114 | version = "0.6.6" 115 | source = "registry+https://github.com/rust-lang/crates.io-index" 116 | dependencies = [ 117 | "cfg-if 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)", 118 | "lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)", 119 | ] 120 | 121 | [[package]] 122 | name = "crossbeam-utils" 123 | version = "0.7.0" 124 | source = "registry+https://github.com/rust-lang/crates.io-index" 125 | dependencies = [ 126 | "autocfg 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)", 127 | "cfg-if 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)", 128 | "lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)", 129 | ] 130 | 131 | [[package]] 132 | name = "either" 133 | version = "1.5.3" 134 | source = "registry+https://github.com/rust-lang/crates.io-index" 135 | 136 | [[package]] 137 | name = "error-chain" 138 | version = "0.12.1" 139 | source = "registry+https://github.com/rust-lang/crates.io-index" 140 | dependencies = [ 141 | "backtrace 0.3.40 (registry+https://github.com/rust-lang/crates.io-index)", 142 | "version_check 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", 143 | ] 144 | 145 | [[package]] 146 | name = "fake_clock" 147 | version = "0.3.0" 148 | source = "registry+https://github.com/rust-lang/crates.io-index" 149 | 150 | [[package]] 151 | name = "fnv" 152 | version = "1.0.6" 153 | source = "registry+https://github.com/rust-lang/crates.io-index" 154 | 155 | [[package]] 156 | name = "fuchsia-zircon" 157 | version = "0.3.3" 158 | source = "registry+https://github.com/rust-lang/crates.io-index" 159 | dependencies = [ 160 | "bitflags 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)", 161 | "fuchsia-zircon-sys 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", 162 | ] 163 | 164 | [[package]] 165 | name = "fuchsia-zircon-sys" 166 | version = "0.3.3" 167 | source = "registry+https://github.com/rust-lang/crates.io-index" 168 | 169 | [[package]] 170 | name = "futures" 171 | version = "0.1.29" 172 | source = "registry+https://github.com/rust-lang/crates.io-index" 173 | 174 | [[package]] 175 | name = "futures-cpupool" 176 | version = "0.1.8" 177 | source = "registry+https://github.com/rust-lang/crates.io-index" 178 | dependencies = [ 179 | "futures 0.1.29 (registry+https://github.com/rust-lang/crates.io-index)", 180 | "num_cpus 1.11.1 (registry+https://github.com/rust-lang/crates.io-index)", 181 | ] 182 | 183 | [[package]] 184 | name = "getrandom" 185 | version = "0.1.13" 186 | source = "registry+https://github.com/rust-lang/crates.io-index" 187 | dependencies = [ 188 | "cfg-if 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)", 189 | "libc 0.2.65 (registry+https://github.com/rust-lang/crates.io-index)", 190 | "wasi 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", 191 | ] 192 | 193 | [[package]] 194 | name = "h2" 195 | version = "0.1.26" 196 | source = "registry+https://github.com/rust-lang/crates.io-index" 197 | dependencies = [ 198 | "byteorder 1.3.2 (registry+https://github.com/rust-lang/crates.io-index)", 199 | "bytes 0.4.12 (registry+https://github.com/rust-lang/crates.io-index)", 200 | "fnv 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)", 201 | "futures 0.1.29 (registry+https://github.com/rust-lang/crates.io-index)", 202 | "http 0.1.19 (registry+https://github.com/rust-lang/crates.io-index)", 203 | "indexmap 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)", 204 | "log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", 205 | "slab 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", 206 | "string 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", 207 | "tokio-io 0.1.12 (registry+https://github.com/rust-lang/crates.io-index)", 208 | ] 209 | 210 | [[package]] 211 | name = "hermit-abi" 212 | version = "0.1.3" 213 | source = "registry+https://github.com/rust-lang/crates.io-index" 214 | dependencies = [ 215 | "libc 0.2.65 (registry+https://github.com/rust-lang/crates.io-index)", 216 | ] 217 | 218 | [[package]] 219 | name = "http" 220 | version = "0.1.19" 221 | source = "registry+https://github.com/rust-lang/crates.io-index" 222 | dependencies = [ 223 | "bytes 0.4.12 (registry+https://github.com/rust-lang/crates.io-index)", 224 | "fnv 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)", 225 | "itoa 0.4.4 (registry+https://github.com/rust-lang/crates.io-index)", 226 | ] 227 | 228 | [[package]] 229 | name = "http-body" 230 | version = "0.1.0" 231 | source = "registry+https://github.com/rust-lang/crates.io-index" 232 | dependencies = [ 233 | "bytes 0.4.12 (registry+https://github.com/rust-lang/crates.io-index)", 234 | "futures 0.1.29 (registry+https://github.com/rust-lang/crates.io-index)", 235 | "http 0.1.19 (registry+https://github.com/rust-lang/crates.io-index)", 236 | "tokio-buf 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", 237 | ] 238 | 239 | [[package]] 240 | name = "httparse" 241 | version = "1.3.4" 242 | source = "registry+https://github.com/rust-lang/crates.io-index" 243 | 244 | [[package]] 245 | name = "hyper" 246 | version = "0.12.35" 247 | source = "registry+https://github.com/rust-lang/crates.io-index" 248 | dependencies = [ 249 | "bytes 0.4.12 (registry+https://github.com/rust-lang/crates.io-index)", 250 | "futures 0.1.29 (registry+https://github.com/rust-lang/crates.io-index)", 251 | "futures-cpupool 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)", 252 | "h2 0.1.26 (registry+https://github.com/rust-lang/crates.io-index)", 253 | "http 0.1.19 (registry+https://github.com/rust-lang/crates.io-index)", 254 | "http-body 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", 255 | "httparse 1.3.4 (registry+https://github.com/rust-lang/crates.io-index)", 256 | "iovec 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)", 257 | "itoa 0.4.4 (registry+https://github.com/rust-lang/crates.io-index)", 258 | "log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", 259 | "net2 0.2.33 (registry+https://github.com/rust-lang/crates.io-index)", 260 | "rustc_version 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", 261 | "time 0.1.42 (registry+https://github.com/rust-lang/crates.io-index)", 262 | "tokio 0.1.22 (registry+https://github.com/rust-lang/crates.io-index)", 263 | "tokio-buf 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", 264 | "tokio-executor 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)", 265 | "tokio-io 0.1.12 (registry+https://github.com/rust-lang/crates.io-index)", 266 | "tokio-reactor 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)", 267 | "tokio-tcp 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", 268 | "tokio-threadpool 0.1.16 (registry+https://github.com/rust-lang/crates.io-index)", 269 | "tokio-timer 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)", 270 | "want 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", 271 | ] 272 | 273 | [[package]] 274 | name = "indexmap" 275 | version = "1.3.0" 276 | source = "registry+https://github.com/rust-lang/crates.io-index" 277 | dependencies = [ 278 | "autocfg 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)", 279 | ] 280 | 281 | [[package]] 282 | name = "iovec" 283 | version = "0.1.4" 284 | source = "registry+https://github.com/rust-lang/crates.io-index" 285 | dependencies = [ 286 | "libc 0.2.65 (registry+https://github.com/rust-lang/crates.io-index)", 287 | ] 288 | 289 | [[package]] 290 | name = "itoa" 291 | version = "0.4.4" 292 | source = "registry+https://github.com/rust-lang/crates.io-index" 293 | 294 | [[package]] 295 | name = "kernel32-sys" 296 | version = "0.2.2" 297 | source = "registry+https://github.com/rust-lang/crates.io-index" 298 | dependencies = [ 299 | "winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", 300 | "winapi-build 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", 301 | ] 302 | 303 | [[package]] 304 | name = "lazy_static" 305 | version = "1.4.0" 306 | source = "registry+https://github.com/rust-lang/crates.io-index" 307 | 308 | [[package]] 309 | name = "libc" 310 | version = "0.2.65" 311 | source = "registry+https://github.com/rust-lang/crates.io-index" 312 | 313 | [[package]] 314 | name = "lock_api" 315 | version = "0.3.1" 316 | source = "registry+https://github.com/rust-lang/crates.io-index" 317 | dependencies = [ 318 | "scopeguard 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", 319 | ] 320 | 321 | [[package]] 322 | name = "log" 323 | version = "0.4.8" 324 | source = "registry+https://github.com/rust-lang/crates.io-index" 325 | dependencies = [ 326 | "cfg-if 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)", 327 | ] 328 | 329 | [[package]] 330 | name = "maybe-uninit" 331 | version = "2.0.0" 332 | source = "registry+https://github.com/rust-lang/crates.io-index" 333 | 334 | [[package]] 335 | name = "memchr" 336 | version = "2.2.1" 337 | source = "registry+https://github.com/rust-lang/crates.io-index" 338 | 339 | [[package]] 340 | name = "memoffset" 341 | version = "0.5.3" 342 | source = "registry+https://github.com/rust-lang/crates.io-index" 343 | dependencies = [ 344 | "rustc_version 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", 345 | ] 346 | 347 | [[package]] 348 | name = "mio" 349 | version = "0.6.19" 350 | source = "registry+https://github.com/rust-lang/crates.io-index" 351 | dependencies = [ 352 | "fuchsia-zircon 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", 353 | "fuchsia-zircon-sys 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", 354 | "iovec 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)", 355 | "kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", 356 | "libc 0.2.65 (registry+https://github.com/rust-lang/crates.io-index)", 357 | "log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", 358 | "miow 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", 359 | "net2 0.2.33 (registry+https://github.com/rust-lang/crates.io-index)", 360 | "slab 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", 361 | "winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", 362 | ] 363 | 364 | [[package]] 365 | name = "mio-uds" 366 | version = "0.6.7" 367 | source = "registry+https://github.com/rust-lang/crates.io-index" 368 | dependencies = [ 369 | "iovec 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)", 370 | "libc 0.2.65 (registry+https://github.com/rust-lang/crates.io-index)", 371 | "mio 0.6.19 (registry+https://github.com/rust-lang/crates.io-index)", 372 | ] 373 | 374 | [[package]] 375 | name = "miow" 376 | version = "0.2.1" 377 | source = "registry+https://github.com/rust-lang/crates.io-index" 378 | dependencies = [ 379 | "kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", 380 | "net2 0.2.33 (registry+https://github.com/rust-lang/crates.io-index)", 381 | "winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", 382 | "ws2_32-sys 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", 383 | ] 384 | 385 | [[package]] 386 | name = "net2" 387 | version = "0.2.33" 388 | source = "registry+https://github.com/rust-lang/crates.io-index" 389 | dependencies = [ 390 | "cfg-if 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)", 391 | "libc 0.2.65 (registry+https://github.com/rust-lang/crates.io-index)", 392 | "winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", 393 | ] 394 | 395 | [[package]] 396 | name = "num_cpus" 397 | version = "1.11.1" 398 | source = "registry+https://github.com/rust-lang/crates.io-index" 399 | dependencies = [ 400 | "hermit-abi 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", 401 | "libc 0.2.65 (registry+https://github.com/rust-lang/crates.io-index)", 402 | ] 403 | 404 | [[package]] 405 | name = "parking_lot" 406 | version = "0.9.0" 407 | source = "registry+https://github.com/rust-lang/crates.io-index" 408 | dependencies = [ 409 | "lock_api 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", 410 | "parking_lot_core 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)", 411 | "rustc_version 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", 412 | ] 413 | 414 | [[package]] 415 | name = "parking_lot_core" 416 | version = "0.6.2" 417 | source = "registry+https://github.com/rust-lang/crates.io-index" 418 | dependencies = [ 419 | "cfg-if 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)", 420 | "cloudabi 0.0.3 (registry+https://github.com/rust-lang/crates.io-index)", 421 | "libc 0.2.65 (registry+https://github.com/rust-lang/crates.io-index)", 422 | "redox_syscall 0.1.56 (registry+https://github.com/rust-lang/crates.io-index)", 423 | "rustc_version 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", 424 | "smallvec 0.6.13 (registry+https://github.com/rust-lang/crates.io-index)", 425 | "winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", 426 | ] 427 | 428 | [[package]] 429 | name = "ppv-lite86" 430 | version = "0.2.6" 431 | source = "registry+https://github.com/rust-lang/crates.io-index" 432 | 433 | [[package]] 434 | name = "rand" 435 | version = "0.7.2" 436 | source = "registry+https://github.com/rust-lang/crates.io-index" 437 | dependencies = [ 438 | "getrandom 0.1.13 (registry+https://github.com/rust-lang/crates.io-index)", 439 | "libc 0.2.65 (registry+https://github.com/rust-lang/crates.io-index)", 440 | "rand_chacha 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", 441 | "rand_core 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)", 442 | "rand_hc 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", 443 | ] 444 | 445 | [[package]] 446 | name = "rand_chacha" 447 | version = "0.2.1" 448 | source = "registry+https://github.com/rust-lang/crates.io-index" 449 | dependencies = [ 450 | "c2-chacha 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", 451 | "rand_core 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)", 452 | ] 453 | 454 | [[package]] 455 | name = "rand_core" 456 | version = "0.5.1" 457 | source = "registry+https://github.com/rust-lang/crates.io-index" 458 | dependencies = [ 459 | "getrandom 0.1.13 (registry+https://github.com/rust-lang/crates.io-index)", 460 | ] 461 | 462 | [[package]] 463 | name = "rand_hc" 464 | version = "0.2.0" 465 | source = "registry+https://github.com/rust-lang/crates.io-index" 466 | dependencies = [ 467 | "rand_core 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)", 468 | ] 469 | 470 | [[package]] 471 | name = "redox_syscall" 472 | version = "0.1.56" 473 | source = "registry+https://github.com/rust-lang/crates.io-index" 474 | 475 | [[package]] 476 | name = "regex" 477 | version = "1.3.1" 478 | source = "registry+https://github.com/rust-lang/crates.io-index" 479 | dependencies = [ 480 | "aho-corasick 0.7.6 (registry+https://github.com/rust-lang/crates.io-index)", 481 | "memchr 2.2.1 (registry+https://github.com/rust-lang/crates.io-index)", 482 | "regex-syntax 0.6.12 (registry+https://github.com/rust-lang/crates.io-index)", 483 | "thread_local 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", 484 | ] 485 | 486 | [[package]] 487 | name = "regex-syntax" 488 | version = "0.6.12" 489 | source = "registry+https://github.com/rust-lang/crates.io-index" 490 | 491 | [[package]] 492 | name = "rustc-demangle" 493 | version = "0.1.16" 494 | source = "registry+https://github.com/rust-lang/crates.io-index" 495 | 496 | [[package]] 497 | name = "rustc_version" 498 | version = "0.2.3" 499 | source = "registry+https://github.com/rust-lang/crates.io-index" 500 | dependencies = [ 501 | "semver 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)", 502 | ] 503 | 504 | [[package]] 505 | name = "rustnish" 506 | version = "0.0.1" 507 | dependencies = [ 508 | "error-chain 0.12.1 (registry+https://github.com/rust-lang/crates.io-index)", 509 | "fake_clock 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", 510 | "futures 0.1.29 (registry+https://github.com/rust-lang/crates.io-index)", 511 | "http 0.1.19 (registry+https://github.com/rust-lang/crates.io-index)", 512 | "hyper 0.12.35 (registry+https://github.com/rust-lang/crates.io-index)", 513 | "rand 0.7.2 (registry+https://github.com/rust-lang/crates.io-index)", 514 | "regex 1.3.1 (registry+https://github.com/rust-lang/crates.io-index)", 515 | "tokio 0.1.22 (registry+https://github.com/rust-lang/crates.io-index)", 516 | "tokio-core 0.1.17 (registry+https://github.com/rust-lang/crates.io-index)", 517 | ] 518 | 519 | [[package]] 520 | name = "scoped-tls" 521 | version = "0.1.2" 522 | source = "registry+https://github.com/rust-lang/crates.io-index" 523 | 524 | [[package]] 525 | name = "scopeguard" 526 | version = "1.0.0" 527 | source = "registry+https://github.com/rust-lang/crates.io-index" 528 | 529 | [[package]] 530 | name = "semver" 531 | version = "0.9.0" 532 | source = "registry+https://github.com/rust-lang/crates.io-index" 533 | dependencies = [ 534 | "semver-parser 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", 535 | ] 536 | 537 | [[package]] 538 | name = "semver-parser" 539 | version = "0.7.0" 540 | source = "registry+https://github.com/rust-lang/crates.io-index" 541 | 542 | [[package]] 543 | name = "slab" 544 | version = "0.4.2" 545 | source = "registry+https://github.com/rust-lang/crates.io-index" 546 | 547 | [[package]] 548 | name = "smallvec" 549 | version = "0.6.13" 550 | source = "registry+https://github.com/rust-lang/crates.io-index" 551 | dependencies = [ 552 | "maybe-uninit 2.0.0 (registry+https://github.com/rust-lang/crates.io-index)", 553 | ] 554 | 555 | [[package]] 556 | name = "string" 557 | version = "0.2.1" 558 | source = "registry+https://github.com/rust-lang/crates.io-index" 559 | dependencies = [ 560 | "bytes 0.4.12 (registry+https://github.com/rust-lang/crates.io-index)", 561 | ] 562 | 563 | [[package]] 564 | name = "thread_local" 565 | version = "0.3.6" 566 | source = "registry+https://github.com/rust-lang/crates.io-index" 567 | dependencies = [ 568 | "lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)", 569 | ] 570 | 571 | [[package]] 572 | name = "time" 573 | version = "0.1.42" 574 | source = "registry+https://github.com/rust-lang/crates.io-index" 575 | dependencies = [ 576 | "libc 0.2.65 (registry+https://github.com/rust-lang/crates.io-index)", 577 | "redox_syscall 0.1.56 (registry+https://github.com/rust-lang/crates.io-index)", 578 | "winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", 579 | ] 580 | 581 | [[package]] 582 | name = "tokio" 583 | version = "0.1.22" 584 | source = "registry+https://github.com/rust-lang/crates.io-index" 585 | dependencies = [ 586 | "bytes 0.4.12 (registry+https://github.com/rust-lang/crates.io-index)", 587 | "futures 0.1.29 (registry+https://github.com/rust-lang/crates.io-index)", 588 | "mio 0.6.19 (registry+https://github.com/rust-lang/crates.io-index)", 589 | "num_cpus 1.11.1 (registry+https://github.com/rust-lang/crates.io-index)", 590 | "tokio-codec 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", 591 | "tokio-current-thread 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", 592 | "tokio-executor 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)", 593 | "tokio-fs 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", 594 | "tokio-io 0.1.12 (registry+https://github.com/rust-lang/crates.io-index)", 595 | "tokio-reactor 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)", 596 | "tokio-sync 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)", 597 | "tokio-tcp 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", 598 | "tokio-threadpool 0.1.16 (registry+https://github.com/rust-lang/crates.io-index)", 599 | "tokio-timer 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)", 600 | "tokio-udp 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", 601 | "tokio-uds 0.2.5 (registry+https://github.com/rust-lang/crates.io-index)", 602 | ] 603 | 604 | [[package]] 605 | name = "tokio-buf" 606 | version = "0.1.1" 607 | source = "registry+https://github.com/rust-lang/crates.io-index" 608 | dependencies = [ 609 | "bytes 0.4.12 (registry+https://github.com/rust-lang/crates.io-index)", 610 | "either 1.5.3 (registry+https://github.com/rust-lang/crates.io-index)", 611 | "futures 0.1.29 (registry+https://github.com/rust-lang/crates.io-index)", 612 | ] 613 | 614 | [[package]] 615 | name = "tokio-codec" 616 | version = "0.1.1" 617 | source = "registry+https://github.com/rust-lang/crates.io-index" 618 | dependencies = [ 619 | "bytes 0.4.12 (registry+https://github.com/rust-lang/crates.io-index)", 620 | "futures 0.1.29 (registry+https://github.com/rust-lang/crates.io-index)", 621 | "tokio-io 0.1.12 (registry+https://github.com/rust-lang/crates.io-index)", 622 | ] 623 | 624 | [[package]] 625 | name = "tokio-core" 626 | version = "0.1.17" 627 | source = "registry+https://github.com/rust-lang/crates.io-index" 628 | dependencies = [ 629 | "bytes 0.4.12 (registry+https://github.com/rust-lang/crates.io-index)", 630 | "futures 0.1.29 (registry+https://github.com/rust-lang/crates.io-index)", 631 | "iovec 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)", 632 | "log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", 633 | "mio 0.6.19 (registry+https://github.com/rust-lang/crates.io-index)", 634 | "scoped-tls 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", 635 | "tokio 0.1.22 (registry+https://github.com/rust-lang/crates.io-index)", 636 | "tokio-executor 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)", 637 | "tokio-io 0.1.12 (registry+https://github.com/rust-lang/crates.io-index)", 638 | "tokio-reactor 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)", 639 | "tokio-timer 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)", 640 | ] 641 | 642 | [[package]] 643 | name = "tokio-current-thread" 644 | version = "0.1.6" 645 | source = "registry+https://github.com/rust-lang/crates.io-index" 646 | dependencies = [ 647 | "futures 0.1.29 (registry+https://github.com/rust-lang/crates.io-index)", 648 | "tokio-executor 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)", 649 | ] 650 | 651 | [[package]] 652 | name = "tokio-executor" 653 | version = "0.1.8" 654 | source = "registry+https://github.com/rust-lang/crates.io-index" 655 | dependencies = [ 656 | "crossbeam-utils 0.6.6 (registry+https://github.com/rust-lang/crates.io-index)", 657 | "futures 0.1.29 (registry+https://github.com/rust-lang/crates.io-index)", 658 | ] 659 | 660 | [[package]] 661 | name = "tokio-fs" 662 | version = "0.1.6" 663 | source = "registry+https://github.com/rust-lang/crates.io-index" 664 | dependencies = [ 665 | "futures 0.1.29 (registry+https://github.com/rust-lang/crates.io-index)", 666 | "tokio-io 0.1.12 (registry+https://github.com/rust-lang/crates.io-index)", 667 | "tokio-threadpool 0.1.16 (registry+https://github.com/rust-lang/crates.io-index)", 668 | ] 669 | 670 | [[package]] 671 | name = "tokio-io" 672 | version = "0.1.12" 673 | source = "registry+https://github.com/rust-lang/crates.io-index" 674 | dependencies = [ 675 | "bytes 0.4.12 (registry+https://github.com/rust-lang/crates.io-index)", 676 | "futures 0.1.29 (registry+https://github.com/rust-lang/crates.io-index)", 677 | "log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", 678 | ] 679 | 680 | [[package]] 681 | name = "tokio-reactor" 682 | version = "0.1.10" 683 | source = "registry+https://github.com/rust-lang/crates.io-index" 684 | dependencies = [ 685 | "crossbeam-utils 0.6.6 (registry+https://github.com/rust-lang/crates.io-index)", 686 | "futures 0.1.29 (registry+https://github.com/rust-lang/crates.io-index)", 687 | "lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)", 688 | "log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", 689 | "mio 0.6.19 (registry+https://github.com/rust-lang/crates.io-index)", 690 | "num_cpus 1.11.1 (registry+https://github.com/rust-lang/crates.io-index)", 691 | "parking_lot 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)", 692 | "slab 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", 693 | "tokio-executor 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)", 694 | "tokio-io 0.1.12 (registry+https://github.com/rust-lang/crates.io-index)", 695 | "tokio-sync 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)", 696 | ] 697 | 698 | [[package]] 699 | name = "tokio-sync" 700 | version = "0.1.7" 701 | source = "registry+https://github.com/rust-lang/crates.io-index" 702 | dependencies = [ 703 | "fnv 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)", 704 | "futures 0.1.29 (registry+https://github.com/rust-lang/crates.io-index)", 705 | ] 706 | 707 | [[package]] 708 | name = "tokio-tcp" 709 | version = "0.1.3" 710 | source = "registry+https://github.com/rust-lang/crates.io-index" 711 | dependencies = [ 712 | "bytes 0.4.12 (registry+https://github.com/rust-lang/crates.io-index)", 713 | "futures 0.1.29 (registry+https://github.com/rust-lang/crates.io-index)", 714 | "iovec 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)", 715 | "mio 0.6.19 (registry+https://github.com/rust-lang/crates.io-index)", 716 | "tokio-io 0.1.12 (registry+https://github.com/rust-lang/crates.io-index)", 717 | "tokio-reactor 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)", 718 | ] 719 | 720 | [[package]] 721 | name = "tokio-threadpool" 722 | version = "0.1.16" 723 | source = "registry+https://github.com/rust-lang/crates.io-index" 724 | dependencies = [ 725 | "crossbeam-deque 0.7.2 (registry+https://github.com/rust-lang/crates.io-index)", 726 | "crossbeam-queue 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", 727 | "crossbeam-utils 0.6.6 (registry+https://github.com/rust-lang/crates.io-index)", 728 | "futures 0.1.29 (registry+https://github.com/rust-lang/crates.io-index)", 729 | "lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)", 730 | "log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", 731 | "num_cpus 1.11.1 (registry+https://github.com/rust-lang/crates.io-index)", 732 | "slab 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", 733 | "tokio-executor 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)", 734 | ] 735 | 736 | [[package]] 737 | name = "tokio-timer" 738 | version = "0.2.11" 739 | source = "registry+https://github.com/rust-lang/crates.io-index" 740 | dependencies = [ 741 | "crossbeam-utils 0.6.6 (registry+https://github.com/rust-lang/crates.io-index)", 742 | "futures 0.1.29 (registry+https://github.com/rust-lang/crates.io-index)", 743 | "slab 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", 744 | "tokio-executor 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)", 745 | ] 746 | 747 | [[package]] 748 | name = "tokio-udp" 749 | version = "0.1.5" 750 | source = "registry+https://github.com/rust-lang/crates.io-index" 751 | dependencies = [ 752 | "bytes 0.4.12 (registry+https://github.com/rust-lang/crates.io-index)", 753 | "futures 0.1.29 (registry+https://github.com/rust-lang/crates.io-index)", 754 | "log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", 755 | "mio 0.6.19 (registry+https://github.com/rust-lang/crates.io-index)", 756 | "tokio-codec 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", 757 | "tokio-io 0.1.12 (registry+https://github.com/rust-lang/crates.io-index)", 758 | "tokio-reactor 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)", 759 | ] 760 | 761 | [[package]] 762 | name = "tokio-uds" 763 | version = "0.2.5" 764 | source = "registry+https://github.com/rust-lang/crates.io-index" 765 | dependencies = [ 766 | "bytes 0.4.12 (registry+https://github.com/rust-lang/crates.io-index)", 767 | "futures 0.1.29 (registry+https://github.com/rust-lang/crates.io-index)", 768 | "iovec 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)", 769 | "libc 0.2.65 (registry+https://github.com/rust-lang/crates.io-index)", 770 | "log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", 771 | "mio 0.6.19 (registry+https://github.com/rust-lang/crates.io-index)", 772 | "mio-uds 0.6.7 (registry+https://github.com/rust-lang/crates.io-index)", 773 | "tokio-codec 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", 774 | "tokio-io 0.1.12 (registry+https://github.com/rust-lang/crates.io-index)", 775 | "tokio-reactor 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)", 776 | ] 777 | 778 | [[package]] 779 | name = "try-lock" 780 | version = "0.2.2" 781 | source = "registry+https://github.com/rust-lang/crates.io-index" 782 | 783 | [[package]] 784 | name = "version_check" 785 | version = "0.1.5" 786 | source = "registry+https://github.com/rust-lang/crates.io-index" 787 | 788 | [[package]] 789 | name = "want" 790 | version = "0.2.0" 791 | source = "registry+https://github.com/rust-lang/crates.io-index" 792 | dependencies = [ 793 | "futures 0.1.29 (registry+https://github.com/rust-lang/crates.io-index)", 794 | "log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", 795 | "try-lock 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", 796 | ] 797 | 798 | [[package]] 799 | name = "wasi" 800 | version = "0.7.0" 801 | source = "registry+https://github.com/rust-lang/crates.io-index" 802 | 803 | [[package]] 804 | name = "winapi" 805 | version = "0.2.8" 806 | source = "registry+https://github.com/rust-lang/crates.io-index" 807 | 808 | [[package]] 809 | name = "winapi" 810 | version = "0.3.8" 811 | source = "registry+https://github.com/rust-lang/crates.io-index" 812 | dependencies = [ 813 | "winapi-i686-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", 814 | "winapi-x86_64-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", 815 | ] 816 | 817 | [[package]] 818 | name = "winapi-build" 819 | version = "0.1.1" 820 | source = "registry+https://github.com/rust-lang/crates.io-index" 821 | 822 | [[package]] 823 | name = "winapi-i686-pc-windows-gnu" 824 | version = "0.4.0" 825 | source = "registry+https://github.com/rust-lang/crates.io-index" 826 | 827 | [[package]] 828 | name = "winapi-x86_64-pc-windows-gnu" 829 | version = "0.4.0" 830 | source = "registry+https://github.com/rust-lang/crates.io-index" 831 | 832 | [[package]] 833 | name = "ws2_32-sys" 834 | version = "0.2.1" 835 | source = "registry+https://github.com/rust-lang/crates.io-index" 836 | dependencies = [ 837 | "winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", 838 | "winapi-build 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", 839 | ] 840 | 841 | [metadata] 842 | "checksum aho-corasick 0.7.6 (registry+https://github.com/rust-lang/crates.io-index)" = "58fb5e95d83b38284460a5fda7d6470aa0b8844d283a0b614b8535e880800d2d" 843 | "checksum autocfg 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)" = "1d49d90015b3c36167a20fe2810c5cd875ad504b39cff3d4eae7977e6b7c1cb2" 844 | "checksum backtrace 0.3.40 (registry+https://github.com/rust-lang/crates.io-index)" = "924c76597f0d9ca25d762c25a4d369d51267536465dc5064bdf0eb073ed477ea" 845 | "checksum backtrace-sys 0.1.32 (registry+https://github.com/rust-lang/crates.io-index)" = "5d6575f128516de27e3ce99689419835fce9643a9b215a14d2b5b685be018491" 846 | "checksum bitflags 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "cf1de2fe8c75bc145a2f577add951f8134889b4795d47466a54a5c846d691693" 847 | "checksum byteorder 1.3.2 (registry+https://github.com/rust-lang/crates.io-index)" = "a7c3dd8985a7111efc5c80b44e23ecdd8c007de8ade3b96595387e812b957cf5" 848 | "checksum bytes 0.4.12 (registry+https://github.com/rust-lang/crates.io-index)" = "206fdffcfa2df7cbe15601ef46c813fce0965eb3286db6b56c583b814b51c81c" 849 | "checksum c2-chacha 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "214238caa1bf3a496ec3392968969cab8549f96ff30652c9e56885329315f6bb" 850 | "checksum cc 1.0.47 (registry+https://github.com/rust-lang/crates.io-index)" = "aa87058dce70a3ff5621797f1506cb837edd02ac4c0ae642b4542dce802908b8" 851 | "checksum cfg-if 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)" = "4785bdd1c96b2a846b2bd7cc02e86b6b3dbf14e7e53446c4f54c92a361040822" 852 | "checksum cloudabi 0.0.3 (registry+https://github.com/rust-lang/crates.io-index)" = "ddfc5b9aa5d4507acaf872de71051dfd0e309860e88966e1051e462a077aac4f" 853 | "checksum crossbeam-deque 0.7.2 (registry+https://github.com/rust-lang/crates.io-index)" = "c3aa945d63861bfe624b55d153a39684da1e8c0bc8fba932f7ee3a3c16cea3ca" 854 | "checksum crossbeam-epoch 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)" = "5064ebdbf05ce3cb95e45c8b086f72263f4166b29b97f6baff7ef7fe047b55ac" 855 | "checksum crossbeam-queue 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "7c979cd6cfe72335896575c6b5688da489e420d36a27a0b9eb0c73db574b4a4b" 856 | "checksum crossbeam-utils 0.6.6 (registry+https://github.com/rust-lang/crates.io-index)" = "04973fa96e96579258a5091af6003abde64af786b860f18622b82e026cca60e6" 857 | "checksum crossbeam-utils 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ce446db02cdc3165b94ae73111e570793400d0794e46125cc4056c81cbb039f4" 858 | "checksum either 1.5.3 (registry+https://github.com/rust-lang/crates.io-index)" = "bb1f6b1ce1c140482ea30ddd3335fc0024ac7ee112895426e0a629a6c20adfe3" 859 | "checksum error-chain 0.12.1 (registry+https://github.com/rust-lang/crates.io-index)" = "3ab49e9dcb602294bc42f9a7dfc9bc6e936fca4418ea300dbfb84fe16de0b7d9" 860 | "checksum fake_clock 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "a121cefff0e603c3a3477370e0fc965059d848bdab6b56554c1aa2b5b75bb320" 861 | "checksum fnv 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)" = "2fad85553e09a6f881f739c29f0b00b0f01357c743266d478b68951ce23285f3" 862 | "checksum fuchsia-zircon 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "2e9763c69ebaae630ba35f74888db465e49e259ba1bc0eda7d06f4a067615d82" 863 | "checksum fuchsia-zircon-sys 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "3dcaa9ae7725d12cdb85b3ad99a434db70b468c09ded17e012d86b5c1010f7a7" 864 | "checksum futures 0.1.29 (registry+https://github.com/rust-lang/crates.io-index)" = "1b980f2816d6ee8673b6517b52cb0e808a180efc92e5c19d02cdda79066703ef" 865 | "checksum futures-cpupool 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)" = "ab90cde24b3319636588d0c35fe03b1333857621051837ed769faefb4c2162e4" 866 | "checksum getrandom 0.1.13 (registry+https://github.com/rust-lang/crates.io-index)" = "e7db7ca94ed4cd01190ceee0d8a8052f08a247aa1b469a7f68c6a3b71afcf407" 867 | "checksum h2 0.1.26 (registry+https://github.com/rust-lang/crates.io-index)" = "a5b34c246847f938a410a03c5458c7fee2274436675e76d8b903c08efc29c462" 868 | "checksum hermit-abi 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "307c3c9f937f38e3534b1d6447ecf090cafcc9744e4a6360e8b037b2cf5af120" 869 | "checksum http 0.1.19 (registry+https://github.com/rust-lang/crates.io-index)" = "d7e06e336150b178206af098a055e3621e8336027e2b4d126bda0bc64824baaf" 870 | "checksum http-body 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "6741c859c1b2463a423a1dbce98d418e6c3c3fc720fb0d45528657320920292d" 871 | "checksum httparse 1.3.4 (registry+https://github.com/rust-lang/crates.io-index)" = "cd179ae861f0c2e53da70d892f5f3029f9594be0c41dc5269cd371691b1dc2f9" 872 | "checksum hyper 0.12.35 (registry+https://github.com/rust-lang/crates.io-index)" = "9dbe6ed1438e1f8ad955a4701e9a944938e9519f6888d12d8558b645e247d5f6" 873 | "checksum indexmap 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "712d7b3ea5827fcb9d4fda14bf4da5f136f0db2ae9c8f4bd4e2d1c6fde4e6db2" 874 | "checksum iovec 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)" = "b2b3ea6ff95e175473f8ffe6a7eb7c00d054240321b84c57051175fe3c1e075e" 875 | "checksum itoa 0.4.4 (registry+https://github.com/rust-lang/crates.io-index)" = "501266b7edd0174f8530248f87f99c88fbe60ca4ef3dd486835b8d8d53136f7f" 876 | "checksum kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "7507624b29483431c0ba2d82aece8ca6cdba9382bff4ddd0f7490560c056098d" 877 | "checksum lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" 878 | "checksum libc 0.2.65 (registry+https://github.com/rust-lang/crates.io-index)" = "1a31a0627fdf1f6a39ec0dd577e101440b7db22672c0901fe00a9a6fbb5c24e8" 879 | "checksum lock_api 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "f8912e782533a93a167888781b836336a6ca5da6175c05944c86cf28c31104dc" 880 | "checksum log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)" = "14b6052be84e6b71ab17edffc2eeabf5c2c3ae1fdb464aae35ac50c67a44e1f7" 881 | "checksum maybe-uninit 2.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "60302e4db3a61da70c0cb7991976248362f30319e88850c487b9b95bbf059e00" 882 | "checksum memchr 2.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "88579771288728879b57485cc7d6b07d648c9f0141eb955f8ab7f9d45394468e" 883 | "checksum memoffset 0.5.3 (registry+https://github.com/rust-lang/crates.io-index)" = "75189eb85871ea5c2e2c15abbdd541185f63b408415e5051f5cac122d8c774b9" 884 | "checksum mio 0.6.19 (registry+https://github.com/rust-lang/crates.io-index)" = "83f51996a3ed004ef184e16818edc51fadffe8e7ca68be67f9dee67d84d0ff23" 885 | "checksum mio-uds 0.6.7 (registry+https://github.com/rust-lang/crates.io-index)" = "966257a94e196b11bb43aca423754d87429960a768de9414f3691d6957abf125" 886 | "checksum miow 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "8c1f2f3b1cf331de6896aabf6e9d55dca90356cc9960cca7eaaf408a355ae919" 887 | "checksum net2 0.2.33 (registry+https://github.com/rust-lang/crates.io-index)" = "42550d9fb7b6684a6d404d9fa7250c2eb2646df731d1c06afc06dcee9e1bcf88" 888 | "checksum num_cpus 1.11.1 (registry+https://github.com/rust-lang/crates.io-index)" = "76dac5ed2a876980778b8b85f75a71b6cbf0db0b1232ee12f826bccb00d09d72" 889 | "checksum parking_lot 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "f842b1982eb6c2fe34036a4fbfb06dd185a3f5c8edfaacdf7d1ea10b07de6252" 890 | "checksum parking_lot_core 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)" = "b876b1b9e7ac6e1a74a6da34d25c42e17e8862aa409cbbbdcfc8d86c6f3bc62b" 891 | "checksum ppv-lite86 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)" = "74490b50b9fbe561ac330df47c08f3f33073d2d00c150f719147d7c54522fa1b" 892 | "checksum rand 0.7.2 (registry+https://github.com/rust-lang/crates.io-index)" = "3ae1b169243eaf61759b8475a998f0a385e42042370f3a7dbaf35246eacc8412" 893 | "checksum rand_chacha 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "03a2a90da8c7523f554344f921aa97283eadf6ac484a6d2a7d0212fa7f8d6853" 894 | "checksum rand_core 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "90bde5296fc891b0cef12a6d03ddccc162ce7b2aff54160af9338f8d40df6d19" 895 | "checksum rand_hc 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ca3129af7b92a17112d59ad498c6f81eaf463253766b90396d39ea7a39d6613c" 896 | "checksum redox_syscall 0.1.56 (registry+https://github.com/rust-lang/crates.io-index)" = "2439c63f3f6139d1b57529d16bc3b8bb855230c8efcc5d3a896c8bea7c3b1e84" 897 | "checksum regex 1.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "dc220bd33bdce8f093101afe22a037b8eb0e5af33592e6a9caafff0d4cb81cbd" 898 | "checksum regex-syntax 0.6.12 (registry+https://github.com/rust-lang/crates.io-index)" = "11a7e20d1cce64ef2fed88b66d347f88bd9babb82845b2b858f3edbf59a4f716" 899 | "checksum rustc-demangle 0.1.16 (registry+https://github.com/rust-lang/crates.io-index)" = "4c691c0e608126e00913e33f0ccf3727d5fc84573623b8d65b2df340b5201783" 900 | "checksum rustc_version 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "138e3e0acb6c9fb258b19b67cb8abd63c00679d2851805ea151465464fe9030a" 901 | "checksum scoped-tls 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "332ffa32bf586782a3efaeb58f127980944bbc8c4d6913a86107ac2a5ab24b28" 902 | "checksum scopeguard 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "b42e15e59b18a828bbf5c58ea01debb36b9b096346de35d941dcb89009f24a0d" 903 | "checksum semver 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "1d7eb9ef2c18661902cc47e535f9bc51b78acd254da71d375c2f6720d9a40403" 904 | "checksum semver-parser 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "388a1df253eca08550bef6c72392cfe7c30914bf41df5269b68cbd6ff8f570a3" 905 | "checksum slab 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)" = "c111b5bd5695e56cffe5129854aa230b39c93a305372fdbb2668ca2394eea9f8" 906 | "checksum smallvec 0.6.13 (registry+https://github.com/rust-lang/crates.io-index)" = "f7b0758c52e15a8b5e3691eae6cc559f08eee9406e548a4477ba4e67770a82b6" 907 | "checksum string 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "d24114bfcceb867ca7f71a0d3fe45d45619ec47a6fbfa98cb14e14250bfa5d6d" 908 | "checksum thread_local 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)" = "c6b53e329000edc2b34dbe8545fd20e55a333362d0a321909685a19bd28c3f1b" 909 | "checksum time 0.1.42 (registry+https://github.com/rust-lang/crates.io-index)" = "db8dcfca086c1143c9270ac42a2bbd8a7ee477b78ac8e45b19abfb0cbede4b6f" 910 | "checksum tokio 0.1.22 (registry+https://github.com/rust-lang/crates.io-index)" = "5a09c0b5bb588872ab2f09afa13ee6e9dac11e10a0ec9e8e3ba39a5a5d530af6" 911 | "checksum tokio-buf 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "8fb220f46c53859a4b7ec083e41dec9778ff0b1851c0942b211edb89e0ccdc46" 912 | "checksum tokio-codec 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "5c501eceaf96f0e1793cf26beb63da3d11c738c4a943fdf3746d81d64684c39f" 913 | "checksum tokio-core 0.1.17 (registry+https://github.com/rust-lang/crates.io-index)" = "aeeffbbb94209023feaef3c196a41cbcdafa06b4a6f893f68779bb5e53796f71" 914 | "checksum tokio-current-thread 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)" = "d16217cad7f1b840c5a97dfb3c43b0c871fef423a6e8d2118c604e843662a443" 915 | "checksum tokio-executor 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)" = "0f27ee0e6db01c5f0b2973824547ce7e637b2ed79b891a9677b0de9bd532b6ac" 916 | "checksum tokio-fs 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)" = "3fe6dc22b08d6993916647d108a1a7d15b9cd29c4f4496c62b92c45b5041b7af" 917 | "checksum tokio-io 0.1.12 (registry+https://github.com/rust-lang/crates.io-index)" = "5090db468dad16e1a7a54c8c67280c5e4b544f3d3e018f0b913b400261f85926" 918 | "checksum tokio-reactor 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)" = "c56391be9805bc80163151c0b9e5164ee64f4b0200962c346fea12773158f22d" 919 | "checksum tokio-sync 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)" = "d06554cce1ae4a50f42fba8023918afa931413aded705b560e29600ccf7c6d76" 920 | "checksum tokio-tcp 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "1d14b10654be682ac43efee27401d792507e30fd8d26389e1da3b185de2e4119" 921 | "checksum tokio-threadpool 0.1.16 (registry+https://github.com/rust-lang/crates.io-index)" = "2bd2c6a3885302581f4401c82af70d792bb9df1700e7437b0aeb4ada94d5388c" 922 | "checksum tokio-timer 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)" = "f2106812d500ed25a4f38235b9cae8f78a09edf43203e16e59c3b769a342a60e" 923 | "checksum tokio-udp 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "f02298505547f73e60f568359ef0d016d5acd6e830ab9bc7c4a5b3403440121b" 924 | "checksum tokio-uds 0.2.5 (registry+https://github.com/rust-lang/crates.io-index)" = "037ffc3ba0e12a0ab4aca92e5234e0dedeb48fddf6ccd260f1f150a36a9f2445" 925 | "checksum try-lock 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "e604eb7b43c06650e854be16a2a03155743d3752dd1c943f6829e26b7a36e382" 926 | "checksum version_check 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "914b1a6776c4c929a602fafd8bc742e06365d4bcbe48c30f9cca5824f70dc9dd" 927 | "checksum want 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "b6395efa4784b027708f7451087e647ec73cc74f5d9bc2e418404248d679a230" 928 | "checksum wasi 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "b89c3ce4ce14bdc6fb6beaf9ec7928ca331de5df7e5ea278375642a2f478570d" 929 | "checksum winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)" = "167dc9d6949a9b857f3451275e911c3f44255842c1f7a76f33c55103a909087a" 930 | "checksum winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)" = "8093091eeb260906a183e6ae1abdba2ef5ef2257a21801128899c3fc699229c6" 931 | "checksum winapi-build 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "2d315eee3b34aca4797b2da6b13ed88266e6d612562a0c46390af8299fc699bc" 932 | "checksum winapi-i686-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" 933 | "checksum winapi-x86_64-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" 934 | "checksum ws2_32-sys 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "d59cefebd0c892fa2dd6de581e937301d8552cb44489cdff035c6187cb63fa5e" 935 | -------------------------------------------------------------------------------- /Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "rustnish" 3 | version = "0.0.1" 4 | authors = [ "Klaus Purer " ] 5 | edition = "2018" 6 | 7 | [dependencies] 8 | http = "*" 9 | hyper = ">=0.12" 10 | futures = "0.1.21" 11 | error-chain = ">=0.11.0" 12 | tokio = ">=0.1.7" 13 | regex = ">=1" 14 | 15 | [dev-dependencies] 16 | tokio-core = ">=0.1.8" 17 | rand = ">=0.4.1" 18 | fake_clock = ">=0.3" 19 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU General Public License is a free, copyleft license for 11 | software and other kinds of works. 12 | 13 | The licenses for most software and other practical works are designed 14 | to take away your freedom to share and change the works. By contrast, 15 | the GNU General Public License is intended to guarantee your freedom to 16 | share and change all versions of a program--to make sure it remains free 17 | software for all its users. We, the Free Software Foundation, use the 18 | GNU General Public License for most of our software; it applies also to 19 | any other work released this way by its authors. You can apply it to 20 | your programs, too. 21 | 22 | When we speak of free software, we are referring to freedom, not 23 | price. Our General Public Licenses are designed to make sure that you 24 | have the freedom to distribute copies of free software (and charge for 25 | them if you wish), that you receive source code or can get it if you 26 | want it, that you can change the software or use pieces of it in new 27 | free programs, and that you know you can do these things. 28 | 29 | To protect your rights, we need to prevent others from denying you 30 | these rights or asking you to surrender the rights. Therefore, you have 31 | certain responsibilities if you distribute copies of the software, or if 32 | you modify it: responsibilities to respect the freedom of others. 33 | 34 | For example, if you distribute copies of such a program, whether 35 | gratis or for a fee, you must pass on to the recipients the same 36 | freedoms that you received. You must make sure that they, too, receive 37 | or can get the source code. And you must show them these terms so they 38 | know their rights. 39 | 40 | Developers that use the GNU GPL protect your rights with two steps: 41 | (1) assert copyright on the software, and (2) offer you this License 42 | giving you legal permission to copy, distribute and/or modify it. 43 | 44 | For the developers' and authors' protection, the GPL clearly explains 45 | that there is no warranty for this free software. For both users' and 46 | authors' sake, the GPL requires that modified versions be marked as 47 | changed, so that their problems will not be attributed erroneously to 48 | authors of previous versions. 49 | 50 | Some devices are designed to deny users access to install or run 51 | modified versions of the software inside them, although the manufacturer 52 | can do so. This is fundamentally incompatible with the aim of 53 | protecting users' freedom to change the software. The systematic 54 | pattern of such abuse occurs in the area of products for individuals to 55 | use, which is precisely where it is most unacceptable. Therefore, we 56 | have designed this version of the GPL to prohibit the practice for those 57 | products. If such problems arise substantially in other domains, we 58 | stand ready to extend this provision to those domains in future versions 59 | of the GPL, as needed to protect the freedom of users. 60 | 61 | Finally, every program is threatened constantly by software patents. 62 | States should not allow patents to restrict development and use of 63 | software on general-purpose computers, but in those that do, we wish to 64 | avoid the special danger that patents applied to a free program could 65 | make it effectively proprietary. To prevent this, the GPL assures that 66 | patents cannot be used to render the program non-free. 67 | 68 | The precise terms and conditions for copying, distribution and 69 | modification follow. 70 | 71 | TERMS AND CONDITIONS 72 | 73 | 0. Definitions. 74 | 75 | "This License" refers to version 3 of the GNU General Public License. 76 | 77 | "Copyright" also means copyright-like laws that apply to other kinds of 78 | works, such as semiconductor masks. 79 | 80 | "The Program" refers to any copyrightable work licensed under this 81 | License. Each licensee is addressed as "you". "Licensees" and 82 | "recipients" may be individuals or organizations. 83 | 84 | To "modify" a work means to copy from or adapt all or part of the work 85 | in a fashion requiring copyright permission, other than the making of an 86 | exact copy. The resulting work is called a "modified version" of the 87 | earlier work or a work "based on" the earlier work. 88 | 89 | A "covered work" means either the unmodified Program or a work based 90 | on the Program. 91 | 92 | To "propagate" a work means to do anything with it that, without 93 | permission, would make you directly or secondarily liable for 94 | infringement under applicable copyright law, except executing it on a 95 | computer or modifying a private copy. Propagation includes copying, 96 | distribution (with or without modification), making available to the 97 | public, and in some countries other activities as well. 98 | 99 | To "convey" a work means any kind of propagation that enables other 100 | parties to make or receive copies. Mere interaction with a user through 101 | a computer network, with no transfer of a copy, is not conveying. 102 | 103 | An interactive user interface displays "Appropriate Legal Notices" 104 | to the extent that it includes a convenient and prominently visible 105 | feature that (1) displays an appropriate copyright notice, and (2) 106 | tells the user that there is no warranty for the work (except to the 107 | extent that warranties are provided), that licensees may convey the 108 | work under this License, and how to view a copy of this License. If 109 | the interface presents a list of user commands or options, such as a 110 | menu, a prominent item in the list meets this criterion. 111 | 112 | 1. Source Code. 113 | 114 | The "source code" for a work means the preferred form of the work 115 | for making modifications to it. "Object code" means any non-source 116 | form of a work. 117 | 118 | A "Standard Interface" means an interface that either is an official 119 | standard defined by a recognized standards body, or, in the case of 120 | interfaces specified for a particular programming language, one that 121 | is widely used among developers working in that language. 122 | 123 | The "System Libraries" of an executable work include anything, other 124 | than the work as a whole, that (a) is included in the normal form of 125 | packaging a Major Component, but which is not part of that Major 126 | Component, and (b) serves only to enable use of the work with that 127 | Major Component, or to implement a Standard Interface for which an 128 | implementation is available to the public in source code form. A 129 | "Major Component", in this context, means a major essential component 130 | (kernel, window system, and so on) of the specific operating system 131 | (if any) on which the executable work runs, or a compiler used to 132 | produce the work, or an object code interpreter used to run it. 133 | 134 | The "Corresponding Source" for a work in object code form means all 135 | the source code needed to generate, install, and (for an executable 136 | work) run the object code and to modify the work, including scripts to 137 | control those activities. However, it does not include the work's 138 | System Libraries, or general-purpose tools or generally available free 139 | programs which are used unmodified in performing those activities but 140 | which are not part of the work. For example, Corresponding Source 141 | includes interface definition files associated with source files for 142 | the work, and the source code for shared libraries and dynamically 143 | linked subprograms that the work is specifically designed to require, 144 | such as by intimate data communication or control flow between those 145 | subprograms and other parts of the work. 146 | 147 | The Corresponding Source need not include anything that users 148 | can regenerate automatically from other parts of the Corresponding 149 | Source. 150 | 151 | The Corresponding Source for a work in source code form is that 152 | same work. 153 | 154 | 2. Basic Permissions. 155 | 156 | All rights granted under this License are granted for the term of 157 | copyright on the Program, and are irrevocable provided the stated 158 | conditions are met. This License explicitly affirms your unlimited 159 | permission to run the unmodified Program. The output from running a 160 | covered work is covered by this License only if the output, given its 161 | content, constitutes a covered work. This License acknowledges your 162 | rights of fair use or other equivalent, as provided by copyright law. 163 | 164 | You may make, run and propagate covered works that you do not 165 | convey, without conditions so long as your license otherwise remains 166 | in force. You may convey covered works to others for the sole purpose 167 | of having them make modifications exclusively for you, or provide you 168 | with facilities for running those works, provided that you comply with 169 | the terms of this License in conveying all material for which you do 170 | not control copyright. Those thus making or running the covered works 171 | for you must do so exclusively on your behalf, under your direction 172 | and control, on terms that prohibit them from making any copies of 173 | your copyrighted material outside their relationship with you. 174 | 175 | Conveying under any other circumstances is permitted solely under 176 | the conditions stated below. Sublicensing is not allowed; section 10 177 | makes it unnecessary. 178 | 179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 180 | 181 | No covered work shall be deemed part of an effective technological 182 | measure under any applicable law fulfilling obligations under article 183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 184 | similar laws prohibiting or restricting circumvention of such 185 | measures. 186 | 187 | When you convey a covered work, you waive any legal power to forbid 188 | circumvention of technological measures to the extent such circumvention 189 | is effected by exercising rights under this License with respect to 190 | the covered work, and you disclaim any intention to limit operation or 191 | modification of the work as a means of enforcing, against the work's 192 | users, your or third parties' legal rights to forbid circumvention of 193 | technological measures. 194 | 195 | 4. Conveying Verbatim Copies. 196 | 197 | You may convey verbatim copies of the Program's source code as you 198 | receive it, in any medium, provided that you conspicuously and 199 | appropriately publish on each copy an appropriate copyright notice; 200 | keep intact all notices stating that this License and any 201 | non-permissive terms added in accord with section 7 apply to the code; 202 | keep intact all notices of the absence of any warranty; and give all 203 | recipients a copy of this License along with the Program. 204 | 205 | You may charge any price or no price for each copy that you convey, 206 | and you may offer support or warranty protection for a fee. 207 | 208 | 5. Conveying Modified Source Versions. 209 | 210 | You may convey a work based on the Program, or the modifications to 211 | produce it from the Program, in the form of source code under the 212 | terms of section 4, provided that you also meet all of these conditions: 213 | 214 | a) The work must carry prominent notices stating that you modified 215 | it, and giving a relevant date. 216 | 217 | b) The work must carry prominent notices stating that it is 218 | released under this License and any conditions added under section 219 | 7. This requirement modifies the requirement in section 4 to 220 | "keep intact all notices". 221 | 222 | c) You must license the entire work, as a whole, under this 223 | License to anyone who comes into possession of a copy. This 224 | License will therefore apply, along with any applicable section 7 225 | additional terms, to the whole of the work, and all its parts, 226 | regardless of how they are packaged. This License gives no 227 | permission to license the work in any other way, but it does not 228 | invalidate such permission if you have separately received it. 229 | 230 | d) If the work has interactive user interfaces, each must display 231 | Appropriate Legal Notices; however, if the Program has interactive 232 | interfaces that do not display Appropriate Legal Notices, your 233 | work need not make them do so. 234 | 235 | A compilation of a covered work with other separate and independent 236 | works, which are not by their nature extensions of the covered work, 237 | and which are not combined with it such as to form a larger program, 238 | in or on a volume of a storage or distribution medium, is called an 239 | "aggregate" if the compilation and its resulting copyright are not 240 | used to limit the access or legal rights of the compilation's users 241 | beyond what the individual works permit. Inclusion of a covered work 242 | in an aggregate does not cause this License to apply to the other 243 | parts of the aggregate. 244 | 245 | 6. Conveying Non-Source Forms. 246 | 247 | You may convey a covered work in object code form under the terms 248 | of sections 4 and 5, provided that you also convey the 249 | machine-readable Corresponding Source under the terms of this License, 250 | in one of these ways: 251 | 252 | a) Convey the object code in, or embodied in, a physical product 253 | (including a physical distribution medium), accompanied by the 254 | Corresponding Source fixed on a durable physical medium 255 | customarily used for software interchange. 256 | 257 | b) Convey the object code in, or embodied in, a physical product 258 | (including a physical distribution medium), accompanied by a 259 | written offer, valid for at least three years and valid for as 260 | long as you offer spare parts or customer support for that product 261 | model, to give anyone who possesses the object code either (1) a 262 | copy of the Corresponding Source for all the software in the 263 | product that is covered by this License, on a durable physical 264 | medium customarily used for software interchange, for a price no 265 | more than your reasonable cost of physically performing this 266 | conveying of source, or (2) access to copy the 267 | Corresponding Source from a network server at no charge. 268 | 269 | c) Convey individual copies of the object code with a copy of the 270 | written offer to provide the Corresponding Source. This 271 | alternative is allowed only occasionally and noncommercially, and 272 | only if you received the object code with such an offer, in accord 273 | with subsection 6b. 274 | 275 | d) Convey the object code by offering access from a designated 276 | place (gratis or for a charge), and offer equivalent access to the 277 | Corresponding Source in the same way through the same place at no 278 | further charge. You need not require recipients to copy the 279 | Corresponding Source along with the object code. If the place to 280 | copy the object code is a network server, the Corresponding Source 281 | may be on a different server (operated by you or a third party) 282 | that supports equivalent copying facilities, provided you maintain 283 | clear directions next to the object code saying where to find the 284 | Corresponding Source. Regardless of what server hosts the 285 | Corresponding Source, you remain obligated to ensure that it is 286 | available for as long as needed to satisfy these requirements. 287 | 288 | e) Convey the object code using peer-to-peer transmission, provided 289 | you inform other peers where the object code and Corresponding 290 | Source of the work are being offered to the general public at no 291 | charge under subsection 6d. 292 | 293 | A separable portion of the object code, whose source code is excluded 294 | from the Corresponding Source as a System Library, need not be 295 | included in conveying the object code work. 296 | 297 | A "User Product" is either (1) a "consumer product", which means any 298 | tangible personal property which is normally used for personal, family, 299 | or household purposes, or (2) anything designed or sold for incorporation 300 | into a dwelling. In determining whether a product is a consumer product, 301 | doubtful cases shall be resolved in favor of coverage. For a particular 302 | product received by a particular user, "normally used" refers to a 303 | typical or common use of that class of product, regardless of the status 304 | of the particular user or of the way in which the particular user 305 | actually uses, or expects or is expected to use, the product. A product 306 | is a consumer product regardless of whether the product has substantial 307 | commercial, industrial or non-consumer uses, unless such uses represent 308 | the only significant mode of use of the product. 309 | 310 | "Installation Information" for a User Product means any methods, 311 | procedures, authorization keys, or other information required to install 312 | and execute modified versions of a covered work in that User Product from 313 | a modified version of its Corresponding Source. The information must 314 | suffice to ensure that the continued functioning of the modified object 315 | code is in no case prevented or interfered with solely because 316 | modification has been made. 317 | 318 | If you convey an object code work under this section in, or with, or 319 | specifically for use in, a User Product, and the conveying occurs as 320 | part of a transaction in which the right of possession and use of the 321 | User Product is transferred to the recipient in perpetuity or for a 322 | fixed term (regardless of how the transaction is characterized), the 323 | Corresponding Source conveyed under this section must be accompanied 324 | by the Installation Information. But this requirement does not apply 325 | if neither you nor any third party retains the ability to install 326 | modified object code on the User Product (for example, the work has 327 | been installed in ROM). 328 | 329 | The requirement to provide Installation Information does not include a 330 | requirement to continue to provide support service, warranty, or updates 331 | for a work that has been modified or installed by the recipient, or for 332 | the User Product in which it has been modified or installed. Access to a 333 | network may be denied when the modification itself materially and 334 | adversely affects the operation of the network or violates the rules and 335 | protocols for communication across the network. 336 | 337 | Corresponding Source conveyed, and Installation Information provided, 338 | in accord with this section must be in a format that is publicly 339 | documented (and with an implementation available to the public in 340 | source code form), and must require no special password or key for 341 | unpacking, reading or copying. 342 | 343 | 7. Additional Terms. 344 | 345 | "Additional permissions" are terms that supplement the terms of this 346 | License by making exceptions from one or more of its conditions. 347 | Additional permissions that are applicable to the entire Program shall 348 | be treated as though they were included in this License, to the extent 349 | that they are valid under applicable law. If additional permissions 350 | apply only to part of the Program, that part may be used separately 351 | under those permissions, but the entire Program remains governed by 352 | this License without regard to the additional permissions. 353 | 354 | When you convey a copy of a covered work, you may at your option 355 | remove any additional permissions from that copy, or from any part of 356 | it. (Additional permissions may be written to require their own 357 | removal in certain cases when you modify the work.) You may place 358 | additional permissions on material, added by you to a covered work, 359 | for which you have or can give appropriate copyright permission. 360 | 361 | Notwithstanding any other provision of this License, for material you 362 | add to a covered work, you may (if authorized by the copyright holders of 363 | that material) supplement the terms of this License with terms: 364 | 365 | a) Disclaiming warranty or limiting liability differently from the 366 | terms of sections 15 and 16 of this License; or 367 | 368 | b) Requiring preservation of specified reasonable legal notices or 369 | author attributions in that material or in the Appropriate Legal 370 | Notices displayed by works containing it; or 371 | 372 | c) Prohibiting misrepresentation of the origin of that material, or 373 | requiring that modified versions of such material be marked in 374 | reasonable ways as different from the original version; or 375 | 376 | d) Limiting the use for publicity purposes of names of licensors or 377 | authors of the material; or 378 | 379 | e) Declining to grant rights under trademark law for use of some 380 | trade names, trademarks, or service marks; or 381 | 382 | f) Requiring indemnification of licensors and authors of that 383 | material by anyone who conveys the material (or modified versions of 384 | it) with contractual assumptions of liability to the recipient, for 385 | any liability that these contractual assumptions directly impose on 386 | those licensors and authors. 387 | 388 | All other non-permissive additional terms are considered "further 389 | restrictions" within the meaning of section 10. If the Program as you 390 | received it, or any part of it, contains a notice stating that it is 391 | governed by this License along with a term that is a further 392 | restriction, you may remove that term. If a license document contains 393 | a further restriction but permits relicensing or conveying under this 394 | License, you may add to a covered work material governed by the terms 395 | of that license document, provided that the further restriction does 396 | not survive such relicensing or conveying. 397 | 398 | If you add terms to a covered work in accord with this section, you 399 | must place, in the relevant source files, a statement of the 400 | additional terms that apply to those files, or a notice indicating 401 | where to find the applicable terms. 402 | 403 | Additional terms, permissive or non-permissive, may be stated in the 404 | form of a separately written license, or stated as exceptions; 405 | the above requirements apply either way. 406 | 407 | 8. Termination. 408 | 409 | You may not propagate or modify a covered work except as expressly 410 | provided under this License. Any attempt otherwise to propagate or 411 | modify it is void, and will automatically terminate your rights under 412 | this License (including any patent licenses granted under the third 413 | paragraph of section 11). 414 | 415 | However, if you cease all violation of this License, then your 416 | license from a particular copyright holder is reinstated (a) 417 | provisionally, unless and until the copyright holder explicitly and 418 | finally terminates your license, and (b) permanently, if the copyright 419 | holder fails to notify you of the violation by some reasonable means 420 | prior to 60 days after the cessation. 421 | 422 | Moreover, your license from a particular copyright holder is 423 | reinstated permanently if the copyright holder notifies you of the 424 | violation by some reasonable means, this is the first time you have 425 | received notice of violation of this License (for any work) from that 426 | copyright holder, and you cure the violation prior to 30 days after 427 | your receipt of the notice. 428 | 429 | Termination of your rights under this section does not terminate the 430 | licenses of parties who have received copies or rights from you under 431 | this License. If your rights have been terminated and not permanently 432 | reinstated, you do not qualify to receive new licenses for the same 433 | material under section 10. 434 | 435 | 9. Acceptance Not Required for Having Copies. 436 | 437 | You are not required to accept this License in order to receive or 438 | run a copy of the Program. Ancillary propagation of a covered work 439 | occurring solely as a consequence of using peer-to-peer transmission 440 | to receive a copy likewise does not require acceptance. However, 441 | nothing other than this License grants you permission to propagate or 442 | modify any covered work. These actions infringe copyright if you do 443 | not accept this License. Therefore, by modifying or propagating a 444 | covered work, you indicate your acceptance of this License to do so. 445 | 446 | 10. Automatic Licensing of Downstream Recipients. 447 | 448 | Each time you convey a covered work, the recipient automatically 449 | receives a license from the original licensors, to run, modify and 450 | propagate that work, subject to this License. You are not responsible 451 | for enforcing compliance by third parties with this License. 452 | 453 | An "entity transaction" is a transaction transferring control of an 454 | organization, or substantially all assets of one, or subdividing an 455 | organization, or merging organizations. If propagation of a covered 456 | work results from an entity transaction, each party to that 457 | transaction who receives a copy of the work also receives whatever 458 | licenses to the work the party's predecessor in interest had or could 459 | give under the previous paragraph, plus a right to possession of the 460 | Corresponding Source of the work from the predecessor in interest, if 461 | the predecessor has it or can get it with reasonable efforts. 462 | 463 | You may not impose any further restrictions on the exercise of the 464 | rights granted or affirmed under this License. For example, you may 465 | not impose a license fee, royalty, or other charge for exercise of 466 | rights granted under this License, and you may not initiate litigation 467 | (including a cross-claim or counterclaim in a lawsuit) alleging that 468 | any patent claim is infringed by making, using, selling, offering for 469 | sale, or importing the Program or any portion of it. 470 | 471 | 11. Patents. 472 | 473 | A "contributor" is a copyright holder who authorizes use under this 474 | License of the Program or a work on which the Program is based. The 475 | work thus licensed is called the contributor's "contributor version". 476 | 477 | A contributor's "essential patent claims" are all patent claims 478 | owned or controlled by the contributor, whether already acquired or 479 | hereafter acquired, that would be infringed by some manner, permitted 480 | by this License, of making, using, or selling its contributor version, 481 | but do not include claims that would be infringed only as a 482 | consequence of further modification of the contributor version. For 483 | purposes of this definition, "control" includes the right to grant 484 | patent sublicenses in a manner consistent with the requirements of 485 | this License. 486 | 487 | Each contributor grants you a non-exclusive, worldwide, royalty-free 488 | patent license under the contributor's essential patent claims, to 489 | make, use, sell, offer for sale, import and otherwise run, modify and 490 | propagate the contents of its contributor version. 491 | 492 | In the following three paragraphs, a "patent license" is any express 493 | agreement or commitment, however denominated, not to enforce a patent 494 | (such as an express permission to practice a patent or covenant not to 495 | sue for patent infringement). To "grant" such a patent license to a 496 | party means to make such an agreement or commitment not to enforce a 497 | patent against the party. 498 | 499 | If you convey a covered work, knowingly relying on a patent license, 500 | and the Corresponding Source of the work is not available for anyone 501 | to copy, free of charge and under the terms of this License, through a 502 | publicly available network server or other readily accessible means, 503 | then you must either (1) cause the Corresponding Source to be so 504 | available, or (2) arrange to deprive yourself of the benefit of the 505 | patent license for this particular work, or (3) arrange, in a manner 506 | consistent with the requirements of this License, to extend the patent 507 | license to downstream recipients. "Knowingly relying" means you have 508 | actual knowledge that, but for the patent license, your conveying the 509 | covered work in a country, or your recipient's use of the covered work 510 | in a country, would infringe one or more identifiable patents in that 511 | country that you have reason to believe are valid. 512 | 513 | If, pursuant to or in connection with a single transaction or 514 | arrangement, you convey, or propagate by procuring conveyance of, a 515 | covered work, and grant a patent license to some of the parties 516 | receiving the covered work authorizing them to use, propagate, modify 517 | or convey a specific copy of the covered work, then the patent license 518 | you grant is automatically extended to all recipients of the covered 519 | work and works based on it. 520 | 521 | A patent license is "discriminatory" if it does not include within 522 | the scope of its coverage, prohibits the exercise of, or is 523 | conditioned on the non-exercise of one or more of the rights that are 524 | specifically granted under this License. You may not convey a covered 525 | work if you are a party to an arrangement with a third party that is 526 | in the business of distributing software, under which you make payment 527 | to the third party based on the extent of your activity of conveying 528 | the work, and under which the third party grants, to any of the 529 | parties who would receive the covered work from you, a discriminatory 530 | patent license (a) in connection with copies of the covered work 531 | conveyed by you (or copies made from those copies), or (b) primarily 532 | for and in connection with specific products or compilations that 533 | contain the covered work, unless you entered into that arrangement, 534 | or that patent license was granted, prior to 28 March 2007. 535 | 536 | Nothing in this License shall be construed as excluding or limiting 537 | any implied license or other defenses to infringement that may 538 | otherwise be available to you under applicable patent law. 539 | 540 | 12. No Surrender of Others' Freedom. 541 | 542 | If conditions are imposed on you (whether by court order, agreement or 543 | otherwise) that contradict the conditions of this License, they do not 544 | excuse you from the conditions of this License. If you cannot convey a 545 | covered work so as to satisfy simultaneously your obligations under this 546 | License and any other pertinent obligations, then as a consequence you may 547 | not convey it at all. For example, if you agree to terms that obligate you 548 | to collect a royalty for further conveying from those to whom you convey 549 | the Program, the only way you could satisfy both those terms and this 550 | License would be to refrain entirely from conveying the Program. 551 | 552 | 13. Use with the GNU Affero General Public License. 553 | 554 | Notwithstanding any other provision of this License, you have 555 | permission to link or combine any covered work with a work licensed 556 | under version 3 of the GNU Affero General Public License into a single 557 | combined work, and to convey the resulting work. The terms of this 558 | License will continue to apply to the part which is the covered work, 559 | but the special requirements of the GNU Affero General Public License, 560 | section 13, concerning interaction through a network will apply to the 561 | combination as such. 562 | 563 | 14. Revised Versions of this License. 564 | 565 | The Free Software Foundation may publish revised and/or new versions of 566 | the GNU General Public License from time to time. Such new versions will 567 | be similar in spirit to the present version, but may differ in detail to 568 | address new problems or concerns. 569 | 570 | Each version is given a distinguishing version number. If the 571 | Program specifies that a certain numbered version of the GNU General 572 | Public License "or any later version" applies to it, you have the 573 | option of following the terms and conditions either of that numbered 574 | version or of any later version published by the Free Software 575 | Foundation. If the Program does not specify a version number of the 576 | GNU General Public License, you may choose any version ever published 577 | by the Free Software Foundation. 578 | 579 | If the Program specifies that a proxy can decide which future 580 | versions of the GNU General Public License can be used, that proxy's 581 | public statement of acceptance of a version permanently authorizes you 582 | to choose that version for the Program. 583 | 584 | Later license versions may give you additional or different 585 | permissions. However, no additional obligations are imposed on any 586 | author or copyright holder as a result of your choosing to follow a 587 | later version. 588 | 589 | 15. Disclaimer of Warranty. 590 | 591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 599 | 600 | 16. Limitation of Liability. 601 | 602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 610 | SUCH DAMAGES. 611 | 612 | 17. Interpretation of Sections 15 and 16. 613 | 614 | If the disclaimer of warranty and limitation of liability provided 615 | above cannot be given local legal effect according to their terms, 616 | reviewing courts shall apply local law that most closely approximates 617 | an absolute waiver of all civil liability in connection with the 618 | Program, unless a warranty or assumption of liability accompanies a 619 | copy of the Program in return for a fee. 620 | 621 | END OF TERMS AND CONDITIONS 622 | 623 | How to Apply These Terms to Your New Programs 624 | 625 | If you develop a new program, and you want it to be of the greatest 626 | possible use to the public, the best way to achieve this is to make it 627 | free software which everyone can redistribute and change under these terms. 628 | 629 | To do so, attach the following notices to the program. It is safest 630 | to attach them to the start of each source file to most effectively 631 | state the exclusion of warranty; and each file should have at least 632 | the "copyright" line and a pointer to where the full notice is found. 633 | 634 | {one line to give the program's name and a brief idea of what it does.} 635 | Copyright (C) {year} {name of author} 636 | 637 | This program is free software: you can redistribute it and/or modify 638 | it under the terms of the GNU General Public License as published by 639 | the Free Software Foundation, either version 3 of the License, or 640 | (at your option) any later version. 641 | 642 | This program is distributed in the hope that it will be useful, 643 | but WITHOUT ANY WARRANTY; without even the implied warranty of 644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 645 | GNU General Public License for more details. 646 | 647 | You should have received a copy of the GNU General Public License 648 | along with this program. If not, see . 649 | 650 | Also add information on how to contact you by electronic and paper mail. 651 | 652 | If the program does terminal interaction, make it output a short 653 | notice like this when it starts in an interactive mode: 654 | 655 | {project} Copyright (C) {year} {fullname} 656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 657 | This is free software, and you are welcome to redistribute it 658 | under certain conditions; type `show c' for details. 659 | 660 | The hypothetical commands `show w' and `show c' should show the appropriate 661 | parts of the General Public License. Of course, your program's commands 662 | might be different; for a GUI interface, you would use an "about box". 663 | 664 | You should also get your employer (if you work as a programmer) or school, 665 | if any, to sign a "copyright disclaimer" for the program, if necessary. 666 | For more information on this, and how to apply and follow the GNU GPL, see 667 | . 668 | 669 | The GNU General Public License does not permit incorporating your program 670 | into proprietary programs. If your program is a subroutine library, you 671 | may consider it more useful to permit linking proprietary applications with 672 | the library. If this is what you want to do, use the GNU Lesser General 673 | Public License instead of this License. But first, please read 674 | . 675 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Rustnish 2 | 3 | [![Build Status](https://travis-ci.org/klausi/rustnish.svg?branch=goal-05)](https://travis-ci.org/klausi/rustnish) 4 | 5 | Experimental project to learn Rust. A reverse proxy. 6 | 7 | https://klausi.github.io/rustnish/ 8 | 9 | ## Goal 1: Just pipe HTTP requests through 10 | 11 | Completed: yes 12 | 13 | A webserver like Apache is listening on port 80. Write a reverse proxy service 14 | that does nothing but forwarding HTTP requests to port 80. The service must 15 | listen on port 9090. The service must not modify the HTTP response in any way. 16 | 17 | ## Goal 2: One integration test 18 | 19 | Completed: yes 20 | 21 | Write an integration test that confirms that the reverse proxy is working as 22 | expected. The test should issue a real HTTP request and check that passing 23 | through upstream responses works. Refactor the code to accept arbitrary port 24 | numbers so that the tests can simulate a real backend without requiring root 25 | access to bind on port 80. 26 | 27 | ## Goal 3: Convert Hyper server to Tokio 28 | 29 | Completed: yes 30 | 31 | A new version of the [Hyper library](https://hyper.rs/) has been released which 32 | is based on the [Tokio library](https://tokio.rs/). Convert the existing code to 33 | use that new version and provide one integration test case. 34 | 35 | ## Goal 4: Full integration tests 36 | 37 | Completed: yes 38 | 39 | Expand the integration tests to confirm that the reverse proxy is working as 40 | expected. Add tests with broken HTTP requests to cover error handling of the 41 | reverse proxy. All ```unwrap()``` calls in none test code should be removed and 42 | covered by proper error handling. 43 | 44 | ## Goal 5: Continuous integration testing with Travis CI 45 | 46 | Completed: yes 47 | 48 | Enable [Travis CI](http://travis-ci.org/) so that the automated tests are run 49 | after every Git push to the Rustnish repository. Enable 50 | [Clippy](https://github.com/rust-lang-nursery/rust-clippy) that also checks for 51 | Rust best practices. 52 | 53 | ## Goal 6: Add HTTP headers to requests/responses 54 | 55 | Completed: yes 56 | 57 | Add the following HTTP headers to requests/responses passed through Rustnish: 58 | 59 | Headers for requests forwarded upstream: 60 | 61 | * `X-Forwarded-For`: the originating IP address of the client connecting to the 62 | proxy. Append IP address if already set. 63 | * `X-Forwarded-Port`: the originating port of the HTTP request (example: 443). 64 | Append port if already set. 65 | 66 | Headers for responses returned downstream: 67 | 68 | * `Via`: a code name for the Rustnish proxy, with the value rustnish-0.0.1. 69 | Append if already set. 70 | * `Server`: will be added to the response ("rustnish") if the upstream server 71 | didn't add it first. 72 | 73 | ## Goal 7: Add integration test that watches for memory leaks 74 | 75 | Completed: no, because impossible 76 | 77 | Add an integration test that ensures that the proxy server is not leaking memory 78 | (growing RAM usage without shrinking again). Use /proc information to compare 79 | memory usage of the current process before and after the test. 80 | 81 | **Update**: The test case was not stable enough, it had random test fails and 82 | had to be removed. Watching and asserting /proc memory information is not 83 | reliable. 84 | 85 | ## Goal 8: Make Tokio/Hyper server resilient 86 | 87 | Completed: partially 88 | 89 | There is a [known flaw](https://github.com/hyperium/hyper/issues/1358) in the 90 | Tokio/Hyper libraries that stops server execution under high load. Implement a 91 | workaround to make the proxy more resilient. Ensure that the server does not 92 | stop under such an attack and still delivers valid responses after the attack. 93 | 94 | **Update**: The test case was not stable enough, it had random test fails and 95 | had to be removed. Simulating an attack with millions of requests was not 96 | reliable and made different parts of the test case fail. 97 | 98 | ## Goal 9: Benchmark against Varnish 99 | 100 | Completed: yes 101 | 102 | Write benchmark code that compares runtime performance of Rustnish against 103 | [Varnish](https://varnish-cache.org/). Use `cargo bench` to execute the benchmarks. 104 | 105 | ## Goal 10: Cache 20 upstream responses 106 | 107 | Completed: yes 108 | 109 | Create an in-memory store that caches GET HTTP responses for anonymous users. 110 | * A response is considered cachable if the Cache-Control HTTP header contains 111 | "public" and a "max-age" value. 112 | * A request is considered anonymous if the Cookie HTTP header does not contain a key that starts with "SESS". 113 | * The cache key is the full URL path (including query parameters). 114 | * Cache entries should be kept for 1 minute. 115 | * A maximum of 20 cache entries should be used. 116 | 117 | 118 | ## Goal 11: Build a memory constrained cache 119 | 120 | Completed: no 121 | 122 | Improve the in-memory store of cached responses. Make the cache be limited by 123 | memory size and not by number of cache entries. Use a default of 256MB allowed 124 | cache memory size. 125 | 126 | 127 | ## Possible future goals 128 | 129 | * Add HTTP Age header 130 | * Read proxy config from config file 131 | * Read proxy config from Varnish syntax config file 132 | * Support Vary HTTP header in responses 133 | -------------------------------------------------------------------------------- /benches/rustnish_vs_varnish.rs: -------------------------------------------------------------------------------- 1 | #![feature(test)] 2 | 3 | // Performs various timing tests on Rustnish and Varnish. 4 | // 5 | // To better compare Varnish and Rustnish they must be started both externally 6 | // so that the benchmark code here only executes HTTP client timing code. 7 | // 8 | // The backend service must be started with `cargo run --example hello_9091`. 9 | // 10 | // Rustnish must be started with `cargo run --release --example rustnish_9090`. 11 | // 12 | // Varnish must be running and configured to listen on port 6081. The backend 13 | // port must be set to 9091. 14 | // Example Varnish configuration in /etc/varnish/default.vcl: 15 | // ``` 16 | // vcl 4.0; 17 | // # Default backend definition. Set this to point to your content server. 18 | // backend default { 19 | // .host = "127.0.0.1"; 20 | // .port = "9091"; 21 | // } 22 | // 23 | // sub vcl_recv { 24 | // return (pass); 25 | // } 26 | // ``` 27 | // Execute with `cargo bench`. 28 | 29 | extern crate futures; 30 | extern crate hyper; 31 | extern crate test; 32 | extern crate tokio; 33 | extern crate tokio_core; 34 | 35 | use futures::future::{join_all, loop_fn, Loop}; 36 | use futures::{Future, Stream}; 37 | use hyper::StatusCode; 38 | use tokio_core::reactor::Core; 39 | 40 | #[bench] 41 | fn a_1_request(b: &mut test::Bencher) { 42 | bench_requests(b, 1, 1, 9090); 43 | } 44 | 45 | #[bench] 46 | fn a_1_request_varnish(b: &mut test::Bencher) { 47 | // Assume Varnish is already running. 48 | bench_requests(b, 1, 1, 6081); 49 | } 50 | 51 | #[bench] 52 | fn b_10_requests(b: &mut test::Bencher) { 53 | bench_requests(b, 10, 1, 9090); 54 | } 55 | 56 | #[bench] 57 | fn b_10_requests_varnish(b: &mut test::Bencher) { 58 | // Assume Varnish is already running. 59 | bench_requests(b, 10, 1, 6081); 60 | } 61 | 62 | #[bench] 63 | fn c_100_requests(b: &mut test::Bencher) { 64 | bench_requests(b, 100, 1, 9090); 65 | } 66 | 67 | #[bench] 68 | fn c_100_requests_varnish(b: &mut test::Bencher) { 69 | // Assume Varnish is already running. 70 | bench_requests(b, 100, 1, 6081); 71 | } 72 | 73 | #[bench] 74 | fn d_10_parallel_requests(b: &mut test::Bencher) { 75 | bench_requests(b, 10, 10, 9090); 76 | } 77 | 78 | #[bench] 79 | fn d_10_parallel_requests_varnish(b: &mut test::Bencher) { 80 | // Assume Varnish is already running. 81 | bench_requests(b, 10, 10, 6081); 82 | } 83 | 84 | #[bench] 85 | fn e_100_parallel_requests(b: &mut test::Bencher) { 86 | bench_requests(b, 100, 10, 9090); 87 | } 88 | 89 | #[bench] 90 | fn e_100_parallel_requests_varnish(b: &mut test::Bencher) { 91 | // Assume Varnish is already running. 92 | bench_requests(b, 100, 10, 6081); 93 | } 94 | 95 | #[bench] 96 | fn f_1_000_parallel_requests(b: &mut test::Bencher) { 97 | bench_requests(b, 1_000, 100, 9090); 98 | } 99 | 100 | #[bench] 101 | fn f_1_000_parallel_requests_varnish(b: &mut test::Bencher) { 102 | bench_requests(b, 1_000, 100, 6081); 103 | } 104 | 105 | fn bench_requests(b: &mut test::Bencher, amount: u16, concurrency: u16, proxy_port: u16) { 106 | // @todo I tried to convert this to the new tokio crate, but then the 107 | // ownership in the closure does not work anymore. 108 | let mut core = Core::new().unwrap(); 109 | 110 | let client = hyper::Client::new(); 111 | 112 | let url: hyper::Uri = format!("http://127.0.0.1:{}/get", proxy_port) 113 | .parse() 114 | .unwrap(); 115 | 116 | b.iter(move || { 117 | let mut parallel = Vec::with_capacity(concurrency as usize); 118 | for _i in 0..concurrency { 119 | let requests_til_done = loop_fn(0, |counter| { 120 | client 121 | .get(url.clone()) 122 | .and_then(|res| { 123 | assert_eq!( 124 | res.status(), 125 | StatusCode::OK, 126 | "Varnish did not return a 200 HTTP status code. Make sure Varnish is configured on port {} and the backend port is set to 9091 in /etc/varnish/default.vcl", 127 | proxy_port 128 | ); 129 | // Read response body until the end. 130 | res.into_body().for_each(|_chunk| Ok(())) 131 | }) 132 | .and_then(move |_| -> Result<_, hyper::Error> { 133 | if counter < (amount / concurrency) { 134 | Ok(Loop::Continue(counter + 1)) 135 | } else { 136 | Ok(Loop::Break(counter)) 137 | } 138 | }) 139 | }); 140 | parallel.push(requests_til_done); 141 | } 142 | 143 | let work = join_all(parallel); 144 | core.run(work).unwrap(); 145 | }); 146 | } 147 | -------------------------------------------------------------------------------- /examples/hello_9091.rs: -------------------------------------------------------------------------------- 1 | // Copy of the example in Hyper except that we use port 9091. 2 | 3 | #![deny(warnings)] 4 | 5 | use hyper::rt::{self, Future}; 6 | use hyper::service::service_fn_ok; 7 | use hyper::{Body, Response, Server}; 8 | 9 | static PHRASE: &'static [u8] = b"Hello World!"; 10 | 11 | fn main() { 12 | let addr = ([127, 0, 0, 1], 9091).into(); 13 | 14 | // new_service is run for each connection, creating a 'service' 15 | // to handle requests for that specific connection. 16 | let new_service = || { 17 | // This is the `Service` that will handle the connection. 18 | // `service_fn_ok` is a helper to convert a function that 19 | // returns a Response into a `Service`. 20 | service_fn_ok(|_| Response::new(Body::from(PHRASE))) 21 | }; 22 | 23 | let server = Server::bind(&addr) 24 | .serve(new_service) 25 | .map_err(|e| eprintln!("server error: {}", e)); 26 | 27 | println!("Listening on http://{}", addr); 28 | 29 | rt::run(server); 30 | } 31 | -------------------------------------------------------------------------------- /examples/rustnish_9090.rs: -------------------------------------------------------------------------------- 1 | // Copy of main.rs that uses upstream port 9091 instead of 80. 2 | #![deny(warnings)] 3 | 4 | fn main() { 5 | let port: u16 = 9090; 6 | let upstream_port: u16 = 9091; 7 | 8 | if let Err(ref e) = rustnish::start_server_blocking(port, upstream_port) { 9 | use error_chain::ChainedError; 10 | use std::io::Write; // trait which holds `display` 11 | let stderr = &mut ::std::io::stderr(); 12 | let errmsg = "Error writing to stderr"; 13 | 14 | writeln!(stderr, "{}", e.display_chain()).expect(errmsg); 15 | ::std::process::exit(1); 16 | }; 17 | } 18 | -------------------------------------------------------------------------------- /src/cache.rs: -------------------------------------------------------------------------------- 1 | // Fork of https://github.com/maidsafe/lru_time_cache to be memory limited instead. 2 | // 3 | // Copyright 2018 MaidSafe.net limited. 4 | // 5 | // This SAFE Network Software is licensed to you under the MIT license or the Modified BSD license , at your option. This file may not be copied, 8 | // modified, or distributed except according to those terms. Please review the Licences for the 9 | // specific language governing permissions and limitations relating to use of the SAFE Network 10 | // Software. 11 | 12 | #![doc( 13 | html_logo_url = "https://raw.githubusercontent.com/maidsafe/QA/master/Images/maidsafe_logo.png", 14 | html_favicon_url = "https://maidsafe.net/img/favicon.ico", 15 | test(attr(forbid(warnings))) 16 | )] 17 | // For explanation of lint checks, run `rustc -W help` or see 18 | // https://github.com/maidsafe/QA/blob/master/Documentation/Rust%20Lint%20Checks.md 19 | #![forbid( 20 | bad_style, 21 | exceeding_bitshifts, 22 | mutable_transmutes, 23 | no_mangle_const_items, 24 | unknown_crate_types 25 | )] 26 | #![deny( 27 | deprecated, 28 | improper_ctypes, 29 | missing_docs, 30 | non_shorthand_field_patterns, 31 | overflowing_literals, 32 | plugin_as_library, 33 | stable_features, 34 | unconditional_recursion, 35 | unknown_lints, 36 | unsafe_code, 37 | unused_allocation, 38 | unused_attributes, 39 | unused_comparisons, 40 | unused_features, 41 | unused_parens, 42 | while_true 43 | )] 44 | #![warn( 45 | trivial_casts, 46 | trivial_numeric_casts, 47 | unused_extern_crates, 48 | unused_import_braces, 49 | unused_qualifications, 50 | unused_results 51 | )] 52 | #![allow( 53 | box_pointers, 54 | missing_copy_implementations, 55 | missing_debug_implementations, 56 | variant_size_differences, 57 | dead_code 58 | )] 59 | 60 | // During testing we use a mock clock to be time independent. 61 | #[cfg(test)] 62 | use fake_clock::FakeClock as Instant; 63 | use std::borrow::Borrow; 64 | use std::collections::{btree_map, BTreeMap, VecDeque}; 65 | use std::mem::size_of; 66 | #[cfg(not(test))] 67 | use std::time::Instant; 68 | use std::usize; 69 | 70 | /// All values that the cache can store must implement this trait. 71 | /// Returns the approximate memory size in bytes a cache value takes up. 72 | pub trait MemorySizable { 73 | fn get_memory_size(&self) -> usize; 74 | } 75 | 76 | // This could probably be generic for all primitive types. 77 | // @todo look up how to specify trait bounds for primitive types. 78 | impl MemorySizable for usize { 79 | fn get_memory_size(&self) -> usize { 80 | size_of::() 81 | } 82 | } 83 | 84 | /// An iterator over an `LruCache`'s entries that updates the timestamps as values are traversed. 85 | pub struct Iter<'a, Key: 'a, Value: 'a> { 86 | map_iter_mut: btree_map::IterMut<'a, Key, (Value, Instant, usize)>, 87 | list: &'a mut VecDeque, 88 | } 89 | 90 | impl<'a, Key, Value> Iterator for Iter<'a, Key, Value> 91 | where 92 | Key: Ord + Clone, 93 | Value: MemorySizable, 94 | { 95 | type Item = (&'a Key, &'a Value); 96 | 97 | fn next(&mut self) -> Option<(&'a Key, &'a Value)> { 98 | let now = Instant::now(); 99 | let not_expired = self 100 | .map_iter_mut 101 | .find(|&(_, &mut (_, instant, _))| instant > now); 102 | 103 | not_expired.map(|(key, &mut (ref value, _, _))| { 104 | LruCache::::update_key(self.list, key); 105 | (key, value) 106 | }) 107 | } 108 | } 109 | 110 | /// An iterator over an `LruCache`'s entries that does not modify the timestamp. 111 | pub struct PeekIter<'a, Key: 'a, Value: 'a> { 112 | map_iter: btree_map::Iter<'a, Key, (Value, Instant, usize)>, 113 | } 114 | 115 | impl<'a, Key, Value> Iterator for PeekIter<'a, Key, Value> 116 | where 117 | Key: Ord + Clone, 118 | { 119 | type Item = (&'a Key, &'a Value); 120 | 121 | fn next(&mut self) -> Option<(&'a Key, &'a Value)> { 122 | let now = Instant::now(); 123 | let not_expired = self.map_iter.find(|&(_, &(_, instant, _))| instant > now); 124 | not_expired.map(|(key, &(ref value, _, _))| (key, value)) 125 | } 126 | } 127 | 128 | /// Implementation of [LRU cache](index.html#least-recently-used-lru-cache). 129 | #[derive(Debug)] 130 | pub struct LruCache { 131 | // Store the value itself, the expires date and a memory size of the value. 132 | // @todo make this a proper struct instead of an anonymous tuple. 133 | map: BTreeMap, 134 | list: VecDeque, 135 | // Maximum memory constraint. 136 | max_memory_size: usize, 137 | // Current memory usage, initialized with 0. Increased whenever an item is 138 | // inserted into the cache. Decreases when an item is removed or expires. 139 | current_memory_size: usize, 140 | } 141 | 142 | impl LruCache 143 | where 144 | Key: Ord + Clone, 145 | Value: MemorySizable, 146 | { 147 | /// Constructor for a mmemory constrained cache. 148 | pub fn with_memory_size(memory_size: usize) -> LruCache { 149 | LruCache { 150 | map: BTreeMap::new(), 151 | list: VecDeque::new(), 152 | max_memory_size: memory_size, 153 | current_memory_size: 0, 154 | } 155 | } 156 | 157 | /// Inserts a key-value pair into the cache. 158 | /// 159 | /// If the key already existed in the cache, the existing value is returned and overwritten in 160 | /// the cache. Otherwise, the key-value pair is inserted and `None` is returned. 161 | pub fn insert(&mut self, key: Key, value: Value, expires: Instant) -> Option { 162 | self.remove_expired(); 163 | let old_value = self.remove(&key); 164 | 165 | // @todo should we also add some bytes for the key size? Oh noes, we 166 | // also own the key in self.list so the key will also have to implement 167 | // MemorySizable... 168 | let memory_size = 169 | // Size of the value. 170 | value.get_memory_size() 171 | // Size of the expiry timestamp. 172 | + size_of::() 173 | // Size of the memory count. 174 | + size_of::(); 175 | 176 | if memory_size <= self.max_memory_size { 177 | // Remove old cache entries until we have room to insert the new item. 178 | while self.max_memory_size < self.current_memory_size + memory_size { 179 | let remove_key = self 180 | .list 181 | .pop_front() 182 | .expect("Queue is empty but current memory size > 0"); 183 | let (_, _, removed_size) = self 184 | .map 185 | .remove(&remove_key) 186 | .expect("Shrinking cache failed"); 187 | self.current_memory_size -= removed_size; 188 | } 189 | self.list.push_back(key.clone()); 190 | 191 | self.current_memory_size += memory_size; 192 | let _ = self.map.insert(key, (value, expires, memory_size)); 193 | } 194 | old_value 195 | } 196 | 197 | /// Removes a key-value pair from the cache. 198 | pub fn remove(&mut self, key: &Q) -> Option 199 | where 200 | Key: Borrow, 201 | Q: Ord, 202 | { 203 | self.map.remove(key).map(|(value, _, memory_size)| { 204 | let _ = self 205 | .list 206 | .iter() 207 | .position(|l| l.borrow() == key) 208 | .map(|p| self.list.remove(p)); 209 | self.current_memory_size -= memory_size; 210 | value 211 | }) 212 | } 213 | 214 | /// Clears the `LruCache`, removing all values. 215 | pub fn clear(&mut self) { 216 | self.map.clear(); 217 | self.list.clear(); 218 | self.current_memory_size = 0; 219 | } 220 | 221 | /// Retrieves a reference to the value stored under `key`, or `None` if the key doesn't exist. 222 | /// Also removes expired elements and updates the time. 223 | pub fn get(&mut self, key: &Q) -> Option<&Value> 224 | where 225 | Key: Borrow, 226 | Q: Ord, 227 | { 228 | self.remove_expired(); 229 | 230 | let list = &mut self.list; 231 | self.map.get_mut(key).map(|result| { 232 | Self::update_key(list, key); 233 | &result.0 234 | }) 235 | } 236 | 237 | /// Returns a reference to the value with the given `key`, if present and not expired, without 238 | /// updating the timestamp. 239 | pub fn peek(&self, key: &Q) -> Option<&Value> 240 | where 241 | Key: Borrow, 242 | Q: Ord, 243 | { 244 | self.map 245 | .get(key) 246 | .into_iter() 247 | .find(|&(_, t, _)| *t >= Instant::now()) 248 | .map(|&(ref value, _, _)| value) 249 | } 250 | 251 | /// Returns whether `key` exists in the cache or not. 252 | pub fn contains_key(&self, key: &Q) -> bool 253 | where 254 | Key: Borrow, 255 | Q: Ord, 256 | { 257 | self.peek(key).is_some() 258 | } 259 | 260 | /// Returns the size of the cache, i.e. the number of cached non-expired key-value pairs. 261 | pub fn len(&self) -> usize { 262 | self.map 263 | .iter() 264 | .filter(|&(_, (_, t, _))| *t >= Instant::now()) 265 | .count() 266 | } 267 | 268 | /// Returns `true` if there are no non-expired entries in the cache. 269 | pub fn is_empty(&self) -> bool { 270 | self.len() == 0 271 | } 272 | 273 | /// Returns an iterator over all entries that updates the timestamps as values are 274 | /// traversed. Also removes expired elements before creating the iterator. 275 | pub fn iter(&mut self) -> Iter { 276 | self.remove_expired(); 277 | 278 | Iter { 279 | map_iter_mut: self.map.iter_mut(), 280 | list: &mut self.list, 281 | } 282 | } 283 | 284 | /// Returns an iterator over all entries that does not modify the timestamps. 285 | pub fn peek_iter(&self) -> PeekIter { 286 | PeekIter { 287 | map_iter: self.map.iter(), 288 | } 289 | } 290 | 291 | // Move `key` in the ordered list to the last 292 | fn update_key(list: &mut VecDeque, key: &Q) 293 | where 294 | Key: Borrow, 295 | Q: Ord, 296 | { 297 | if let Some(pos) = list.iter().position(|k| k.borrow() == key) { 298 | let _ = list.remove(pos).map(|it| list.push_back(it)); 299 | } 300 | } 301 | 302 | fn remove_expired(&mut self) { 303 | // Because of the borrow checker we need to clone the keys to be removed 304 | // while accessing the map. Any better ideas how to simplify this? 305 | let remove_entries = self 306 | .map 307 | .iter() 308 | .filter(|(_, (_, t, _))| *t < Instant::now()) 309 | .map(|(key, _)| key.clone()) 310 | .collect::>(); 311 | for key in remove_entries { 312 | let _ = self.remove(&key); 313 | } 314 | } 315 | } 316 | 317 | impl Clone for LruCache 318 | where 319 | Key: Clone, 320 | Value: Clone, 321 | { 322 | fn clone(&self) -> LruCache { 323 | LruCache { 324 | map: self.map.clone(), 325 | list: self.list.clone(), 326 | max_memory_size: self.max_memory_size, 327 | current_memory_size: self.current_memory_size, 328 | } 329 | } 330 | } 331 | 332 | #[cfg(test)] 333 | mod test { 334 | use fake_clock::FakeClock as Instant; 335 | use std::mem::size_of; 336 | use std::time::Duration; 337 | 338 | fn sleep(time: u64) { 339 | use fake_clock::FakeClock; 340 | FakeClock::advance_time(time); 341 | } 342 | 343 | fn generate_random_vec(len: usize) -> Vec 344 | where 345 | rand::distributions::Standard: rand::distributions::Distribution, 346 | { 347 | let mut vec = Vec::::with_capacity(len); 348 | for _ in 0..len { 349 | vec.push(rand::random()); 350 | } 351 | vec 352 | } 353 | 354 | #[test] 355 | fn memory_size() { 356 | // 1x usize value, 1x usize memory size. 357 | let size = 10 * (size_of::() * 2 + size_of::()); 358 | let mut lru_cache = super::LruCache::::with_memory_size(size); 359 | 360 | for i in 0..10 { 361 | assert_eq!(lru_cache.len(), i); 362 | let _ = lru_cache.insert(i, i, Instant::now() + Duration::from_secs(1000)); 363 | assert_eq!(lru_cache.len(), i + 1); 364 | } 365 | 366 | for i in 10..1000 { 367 | let _ = lru_cache.insert(i, i, Instant::now() + Duration::from_secs(1000)); 368 | assert_eq!(lru_cache.current_memory_size, size); 369 | } 370 | 371 | for _ in (0..1000).rev() { 372 | assert!(lru_cache.contains_key(&(1000 - 1))); 373 | assert!(lru_cache.get(&(1000 - 1)).is_some()); 374 | assert_eq!(*lru_cache.get(&(1000 - 1)).unwrap(), 1000 - 1); 375 | } 376 | } 377 | 378 | #[test] 379 | fn expiration_time() { 380 | let time_to_live = Duration::from_millis(100); 381 | let mut lru_cache = super::LruCache::::with_memory_size(10000); 382 | 383 | for i in 0..10 { 384 | assert_eq!(lru_cache.len(), i); 385 | let _ = lru_cache.insert(i, i, Instant::now() + time_to_live); 386 | assert_eq!(lru_cache.len(), i + 1); 387 | } 388 | 389 | sleep(101); 390 | let _ = lru_cache.insert(11, 11, Instant::now() + time_to_live); 391 | 392 | assert_eq!(lru_cache.len(), 1); 393 | 394 | for i in 0..10 { 395 | assert!(!lru_cache.is_empty()); 396 | assert_eq!(lru_cache.len(), i + 1); 397 | let _ = lru_cache.insert(i, i, Instant::now() + time_to_live); 398 | assert_eq!(lru_cache.len(), i + 2); 399 | } 400 | 401 | sleep(101); 402 | assert_eq!(0, lru_cache.len()); 403 | assert!(lru_cache.is_empty()); 404 | } 405 | 406 | #[test] 407 | fn time_and_size() { 408 | let size = 10; 409 | // 1x usize value, 1x usize memory size. 410 | let memory_size = 10 * (size_of::() * 2 + size_of::()); 411 | let time_to_live = Duration::from_millis(100); 412 | let mut lru_cache = super::LruCache::::with_memory_size(memory_size); 413 | 414 | for i in 0..1000 { 415 | if i < size { 416 | assert_eq!(lru_cache.len(), i); 417 | } 418 | 419 | let _ = lru_cache.insert(i, i, Instant::now() + time_to_live); 420 | 421 | if i < size { 422 | assert_eq!(lru_cache.len(), i + 1); 423 | } else { 424 | assert_eq!(lru_cache.len(), size); 425 | } 426 | } 427 | 428 | sleep(101); 429 | let _ = lru_cache.insert(1, 1, Instant::now() + time_to_live); 430 | 431 | assert_eq!(lru_cache.len(), 1); 432 | } 433 | 434 | #[derive(PartialEq, PartialOrd, Ord, Clone, Eq)] 435 | struct Temp { 436 | id: Vec, 437 | } 438 | 439 | #[test] 440 | fn time_size_struct_value() { 441 | let size = 100usize; 442 | // 1x usize value, 1x usize memory size. 443 | let memory_size = 100 * (size_of::() * 2 + size_of::()); 444 | let time_to_live = Duration::from_millis(100); 445 | 446 | let mut lru_cache = super::LruCache::::with_memory_size(memory_size); 447 | 448 | for i in 0..1000 { 449 | if i < size { 450 | assert_eq!(lru_cache.len(), i); 451 | } 452 | 453 | let _ = lru_cache.insert( 454 | Temp { 455 | id: generate_random_vec::(64), 456 | }, 457 | i, 458 | Instant::now() + time_to_live, 459 | ); 460 | 461 | if i < size { 462 | assert_eq!(lru_cache.len(), i + 1); 463 | } else { 464 | assert_eq!(lru_cache.len(), size); 465 | } 466 | } 467 | 468 | sleep(101); 469 | let _ = lru_cache.insert( 470 | Temp { 471 | id: generate_random_vec::(64), 472 | }, 473 | 1, 474 | Instant::now() + time_to_live, 475 | ); 476 | 477 | assert_eq!(lru_cache.len(), 1); 478 | } 479 | 480 | #[test] 481 | fn peek_iter() { 482 | let time_to_live = Duration::from_millis(100); 483 | let mut lru_cache = super::LruCache::::with_memory_size(10000); 484 | 485 | let _ = lru_cache.insert(0, 0, Instant::now() + time_to_live); 486 | let _ = lru_cache.insert(2, 2, Instant::now() + time_to_live); 487 | let _ = lru_cache.insert(3, 3, Instant::now() + time_to_live); 488 | 489 | sleep(50); 490 | assert_eq!( 491 | vec![(&0, &0), (&2, &2), (&3, &3)], 492 | lru_cache.peek_iter().collect::>() 493 | ); 494 | assert_eq!(Some(&2), lru_cache.get(&2)); 495 | let _ = lru_cache.insert(1, 1, Instant::now() + time_to_live); 496 | let _ = lru_cache.insert(4, 4, Instant::now() + time_to_live); 497 | 498 | sleep(51); 499 | assert_eq!( 500 | vec![(&1, &1), (&4, &4)], 501 | lru_cache.peek_iter().collect::>() 502 | ); 503 | 504 | sleep(50); 505 | assert!(lru_cache.is_empty()); 506 | } 507 | 508 | #[test] 509 | fn peek_time_check() { 510 | let time_to_live = Duration::from_millis(100); 511 | let mut lru_cache = super::LruCache::::with_memory_size(10000); 512 | 513 | assert_eq!(lru_cache.len(), 0); 514 | let _ = lru_cache.insert(0, 0, Instant::now() + time_to_live); 515 | assert_eq!(lru_cache.len(), 1); 516 | 517 | sleep(50); 518 | assert_eq!(Some(&0), lru_cache.get(&0)); 519 | assert_eq!(Some(&0), lru_cache.peek(&0)); 520 | sleep(51); 521 | assert_eq!(None, lru_cache.peek(&0)); 522 | } 523 | 524 | #[test] 525 | fn deref_coercions() { 526 | let mut lru_cache = super::LruCache::::with_memory_size(100); 527 | let _ = lru_cache.insert( 528 | "foo".to_string(), 529 | 0, 530 | Instant::now() + Duration::from_secs(1000), 531 | ); 532 | assert_eq!(true, lru_cache.contains_key("foo")); 533 | assert_eq!(Some(&0), lru_cache.get("foo")); 534 | assert_eq!(Some(&0), lru_cache.peek("foo")); 535 | assert_eq!(Some(0), lru_cache.remove("foo")); 536 | } 537 | } 538 | -------------------------------------------------------------------------------- /src/lib.rs: -------------------------------------------------------------------------------- 1 | use crate::cache::LruCache; 2 | use crate::cache::MemorySizable; 3 | use crate::errors::ResultExt; 4 | use crate::errors::*; 5 | use error_chain::bail; 6 | #[cfg(test)] 7 | use fake_clock::FakeClock as Instant; 8 | use futures::{Future, Stream}; 9 | use http::Method; 10 | use hyper::client::HttpConnector; 11 | use hyper::header::HeaderName; 12 | use hyper::header::{HeaderValue, CACHE_CONTROL, COOKIE, SERVER, VIA}; 13 | use hyper::server::conn::AddrStream; 14 | use hyper::service::{make_service_fn, service_fn}; 15 | use hyper::Client; 16 | use hyper::StatusCode; 17 | use hyper::Version; 18 | use hyper::{Body, HeaderMap, Request, Response, Server}; 19 | use regex::Regex; 20 | use std::mem::size_of_val; 21 | use std::net::SocketAddr; 22 | use std::sync::{Arc, Mutex}; 23 | use std::time::Duration; 24 | #[cfg(not(test))] 25 | use std::time::Instant; 26 | use tokio::runtime::Runtime; 27 | 28 | mod cache; 29 | 30 | mod errors { 31 | use error_chain::*; 32 | 33 | // Create the Error, ErrorKind, ResultExt, and Result types 34 | error_chain! {} 35 | } 36 | 37 | fn proxy_request( 38 | mut request: Request, 39 | source_address: SocketAddr, 40 | port: u16, 41 | upstream_port: u16, 42 | client: &Client, 43 | mut cache: Cache, 44 | ) -> Box, Error = hyper::Error> + Send> { 45 | let cache_key = cache.cache_key(&request); 46 | 47 | if let Some(response) = cache.lookup(&cache_key) { 48 | return Box::new(futures::future::ok(response)); 49 | } 50 | 51 | let upstream_uri = { 52 | // 127.0.0.1 is hard coded here for now because we assume that upstream 53 | // is on the same host. Should be made configurable later. 54 | let mut upstream_uri = 55 | format!("http://127.0.0.1:{}{}", upstream_port, request.uri().path()); 56 | if let Some(query) = request.uri().query() { 57 | upstream_uri.push('?'); 58 | upstream_uri.push_str(query); 59 | } 60 | match upstream_uri.parse() { 61 | Ok(u) => u, 62 | _ => { 63 | // We can't actually test this because parsing the URI never 64 | // fails. However, should that change at any point this is the 65 | // right thing to do. 66 | return Box::new(futures::future::ok( 67 | Response::builder() 68 | .status(StatusCode::BAD_REQUEST) 69 | .body("Invalid upstream URI".into()) 70 | .unwrap(), 71 | )); 72 | } 73 | } 74 | }; 75 | 76 | *request.uri_mut() = upstream_uri; 77 | 78 | { 79 | let headers = request.headers_mut(); 80 | headers.append( 81 | HeaderName::from_static("x-forwarded-for"), 82 | source_address.ip().to_string().parse().unwrap(), 83 | ); 84 | headers.append( 85 | HeaderName::from_static("x-forwarded-port"), 86 | port.to_string().parse().unwrap(), 87 | ); 88 | } 89 | 90 | let mut cloned_cache = cache.clone(); 91 | 92 | Box::new(client.request(request).then(move |result| { 93 | let our_response = match result { 94 | Ok(mut response) => { 95 | let version = match response.version() { 96 | Version::HTTP_09 => "0.9", 97 | Version::HTTP_10 => "1.0", 98 | Version::HTTP_11 => "1.1", 99 | Version::HTTP_2 => "2.0", 100 | }; 101 | { 102 | let headers = response.headers_mut(); 103 | 104 | headers.append(VIA, format!("{} rustnish-0.0.1", version).parse().unwrap()); 105 | 106 | // Append a "Server" header if not already present. 107 | if !headers.contains_key(SERVER) { 108 | headers.insert(SERVER, "rustnish".parse().unwrap()); 109 | } 110 | } 111 | 112 | // Put the response into the cache if possible. 113 | cloned_cache.store(cache_key, response) 114 | } 115 | Err(_) => { 116 | // For security reasons do not show the exact error to end users. 117 | // @todo Log the error. 118 | Response::builder() 119 | .status(StatusCode::BAD_GATEWAY) 120 | .body("Something went wrong, please try again later.".into()) 121 | .unwrap() 122 | } 123 | }; 124 | futures::future::ok(our_response) 125 | })) 126 | } 127 | 128 | struct CachedResponse { 129 | status: StatusCode, 130 | version: Version, 131 | headers: HeaderMap, 132 | body: Vec, 133 | } 134 | 135 | /// Calculates the memory space that is used up by a cached HTTP response. 136 | /// This is an imprecise approximation. 137 | impl MemorySizable for CachedResponse { 138 | fn get_memory_size(&self) -> usize { 139 | // Memory usage of the struct itself. 140 | let mut memory_size = size_of_val(self); 141 | 142 | // Memory usage of the header key value pairs. 143 | for (key, value) in self.headers.iter() { 144 | memory_size += key.as_str().as_bytes().len() + value.len(); 145 | } 146 | // Memory usage of the body bytes. 147 | memory_size += self.body.capacity(); 148 | 149 | memory_size 150 | } 151 | } 152 | 153 | #[derive(Clone)] 154 | struct Cache { 155 | lru_cache: Arc>>, 156 | } 157 | 158 | impl Cache { 159 | /// Convert an incoming request into a cache key that we can then lookup. 160 | fn cache_key(&self, request: &Request) -> Option { 161 | // Only GET requests are cachable. 162 | if request.method() != Method::GET { 163 | return None; 164 | } 165 | // Requests with a session cookie cannot be cached. 166 | if let Some(cookie_header) = request.headers().get(COOKIE) { 167 | if let Ok(cookie_string) = cookie_header.to_str() { 168 | let regex = Regex::new(r"SESS[A-Za-z0-9_]+=").unwrap(); 169 | if regex.is_match(cookie_string) { 170 | return None; 171 | } 172 | } 173 | } 174 | Some(request.uri().to_string()) 175 | } 176 | 177 | /// Check if we have a response for this request in memory. 178 | fn lookup(&mut self, cache_key: &Option) -> Option> { 179 | match cache_key { 180 | None => None, 181 | Some(cache_key) => { 182 | let mut inner_cache = self.lru_cache.lock().unwrap(); 183 | match inner_cache.get(cache_key) { 184 | Some(entry) => { 185 | let mut response = Response::builder() 186 | .status(entry.status) 187 | .version(entry.version) 188 | .body(Body::from(entry.body.clone())) 189 | .unwrap(); 190 | *response.headers_mut() = entry.headers.clone(); 191 | Some(response) 192 | } 193 | None => None, 194 | } 195 | } 196 | } 197 | } 198 | 199 | // @todo should we take the cache key as option or not? 200 | fn store(&mut self, cache_key: Option, response: Response) -> Response { 201 | match cache_key { 202 | None => response, 203 | Some(key) => { 204 | // Only cache the response if it has a max-age. 205 | match self.get_max_age(&response) { 206 | None => response, 207 | Some(max_age) => { 208 | // In order to be able to cache the response we have to fully 209 | // consume it, clone it and rebuild it. Super ugly, any better 210 | // ideas? 211 | let (header_part, body) = response.into_parts(); 212 | let body_bytes = body.concat2().wait().unwrap().to_vec(); 213 | 214 | let mut inner_cache = self.lru_cache.lock().unwrap(); 215 | let entry = CachedResponse { 216 | status: header_part.status, 217 | version: header_part.version, 218 | headers: header_part.headers.clone(), 219 | body: body_bytes.clone(), 220 | }; 221 | // Store an expiry date for this repsponse. After 222 | // that point in time we need to discard it. 223 | inner_cache.insert( 224 | key, 225 | entry, 226 | Instant::now() + Duration::from_secs(max_age), 227 | ); 228 | 229 | Response::from_parts(header_part, Body::from(body_bytes)) 230 | } 231 | } 232 | } 233 | } 234 | } 235 | 236 | fn get_max_age(&self, response: &Response) -> Option { 237 | let mut public = false; 238 | let mut max_age: u64 = 0; 239 | { 240 | // Make sure that the response is cachable. 241 | let cache_control = response.headers().get_all(CACHE_CONTROL); 242 | for header_value in cache_control { 243 | if let Ok(header_string) = header_value.to_str() { 244 | let comma_values = header_string.split(','); 245 | for comma_value in comma_values { 246 | if comma_value == "public" { 247 | public = true; 248 | continue; 249 | } 250 | let equal_value: Vec<&str> = comma_value.split('=').collect(); 251 | if equal_value.len() == 2 && equal_value[0] == "max-age" { 252 | max_age = match equal_value[1].parse() { 253 | Ok(value) => value, 254 | Err(_) => 0, 255 | }; 256 | } 257 | } 258 | } 259 | } 260 | } 261 | 262 | if public && max_age > 0 { 263 | return Some(max_age); 264 | } 265 | None 266 | } 267 | } 268 | 269 | pub fn start_server_blocking(port: u16, upstream_port: u16) -> Result<()> { 270 | let runtime = start_server_background(port, upstream_port) 271 | .chain_err(|| "Spawning server thread failed")?; 272 | 273 | runtime.shutdown_on_idle().wait().unwrap(); 274 | 275 | bail!("The server thread finished unexpectedly"); 276 | } 277 | 278 | pub fn start_server_background(port: u16, upstream_port: u16) -> Result { 279 | // 256 MB memory cache as a default. 280 | start_server_background_memory(port, upstream_port, 256 * 1024 * 1024) 281 | } 282 | 283 | pub fn start_server_background_memory( 284 | port: u16, 285 | upstream_port: u16, 286 | memory_size: usize, 287 | ) -> Result { 288 | let address: SocketAddr = ([127, 0, 0, 1], port).into(); 289 | let mut runtime = Runtime::new().unwrap(); 290 | 291 | let client = Client::new(); 292 | 293 | let inner_cache = LruCache::::with_memory_size(memory_size); 294 | let cache = Cache { 295 | lru_cache: Arc::new(Mutex::new(inner_cache)), 296 | }; 297 | 298 | let make_service = make_service_fn(move |socket: &AddrStream| { 299 | let source_address = socket.remote_addr(); 300 | let client = client.clone(); 301 | let cache = cache.clone(); 302 | 303 | service_fn(move |request| { 304 | proxy_request( 305 | request, 306 | source_address, 307 | port, 308 | upstream_port, 309 | &client, 310 | cache.clone(), 311 | ) 312 | }) 313 | }); 314 | 315 | let server = Server::try_bind(&address) 316 | .chain_err(|| format!("Failed to bind server to address {}", address))? 317 | .serve(make_service) 318 | .map_err(|e| eprintln!("server error: {}", e)); 319 | 320 | println!("Listening on http://{}", address); 321 | runtime.spawn(server); 322 | 323 | Ok(runtime) 324 | } 325 | 326 | #[cfg(test)] 327 | mod tests { 328 | 329 | use crate::cache::MemorySizable; 330 | use crate::CachedResponse; 331 | use hyper::header::HeaderValue; 332 | use hyper::{HeaderMap, StatusCode, Version}; 333 | 334 | fn example_cache_entry() -> CachedResponse { 335 | CachedResponse { 336 | status: StatusCode::OK, 337 | version: Version::HTTP_11, 338 | headers: HeaderMap::new(), 339 | body: "a".into(), 340 | } 341 | } 342 | 343 | #[test] 344 | fn cache_memory_size() { 345 | let cache_entry = example_cache_entry(); 346 | assert_eq!(129, cache_entry.get_memory_size()); 347 | } 348 | 349 | #[test] 350 | fn body_100_bytes() { 351 | let mut cache_entry = example_cache_entry(); 352 | cache_entry.body = vec![b'a'; 100]; 353 | assert_eq!(228, cache_entry.get_memory_size()); 354 | } 355 | 356 | #[test] 357 | fn one_header_size() { 358 | let mut cache_entry = example_cache_entry(); 359 | cache_entry 360 | .headers 361 | .insert("a", HeaderValue::from_static("b")); 362 | assert_eq!(131, cache_entry.get_memory_size()); 363 | } 364 | } 365 | -------------------------------------------------------------------------------- /src/main.rs: -------------------------------------------------------------------------------- 1 | #![deny(warnings)] 2 | 3 | extern crate error_chain; 4 | extern crate rustnish; 5 | 6 | fn main() { 7 | let port: u16 = 9090; 8 | let upstream_port: u16 = 80; 9 | 10 | if let Err(ref e) = rustnish::start_server_blocking(port, upstream_port) { 11 | use error_chain::ChainedError; 12 | use std::io::Write; // trait which holds `display` 13 | let stderr = &mut ::std::io::stderr(); 14 | 15 | writeln!(stderr, "{}", e.display_chain()).expect("Error writing to stderr"); 16 | ::std::process::exit(1); 17 | }; 18 | } 19 | -------------------------------------------------------------------------------- /tests/cache.rs: -------------------------------------------------------------------------------- 1 | use crate::common::echo_request; 2 | use futures::Future; 3 | use hyper::header::{CACHE_CONTROL, COOKIE}; 4 | use hyper::Uri; 5 | use hyper::{Body, Request, StatusCode}; 6 | use std::thread; 7 | use std::time::Duration; 8 | 9 | mod common; 10 | 11 | // Test that a GET request is cached and works even if the upstream source is 12 | // down. 13 | #[test] 14 | fn upstream_down_cache() { 15 | let port = common::get_free_port(); 16 | let upstream_port = common::get_free_port(); 17 | 18 | let upstream_server = common::start_dummy_server(upstream_port, |request| { 19 | let mut response = echo_request(request); 20 | { 21 | let headers = response.headers_mut(); 22 | headers.append(CACHE_CONTROL, "public,max-age=1800".parse().unwrap()); 23 | } 24 | response 25 | }); 26 | let _proxy = rustnish::start_server_background(port, upstream_port); 27 | 28 | let url: Uri = ("http://127.0.0.1:".to_string() + &port.to_string()) 29 | .parse() 30 | .unwrap(); 31 | // This request should populate the cache. 32 | common::client_get(url.clone()); 33 | 34 | upstream_server.shutdown_now().wait().unwrap(); 35 | 36 | // We should still get a valid cached response. 37 | let response2 = common::client_get(url); 38 | assert_eq!(response2.status(), StatusCode::OK); 39 | 40 | // Any other path is not cached and should return a 502 because the 41 | // upstream server is down. 42 | let test_url: Uri = ("http://127.0.0.1:".to_string() + &port.to_string() + "/test") 43 | .parse() 44 | .unwrap(); 45 | let response3 = common::client_get(test_url); 46 | assert_eq!(response3.status(), StatusCode::BAD_GATEWAY); 47 | } 48 | 49 | // If a response does not have a max age header then it must not be cached. 50 | #[test] 51 | fn no_max_age_means_uncachable() { 52 | let port = common::get_free_port(); 53 | let upstream_port = common::get_free_port(); 54 | 55 | let upstream_server = common::start_dummy_server(upstream_port, echo_request); 56 | let _proxy = rustnish::start_server_background(port, upstream_port); 57 | 58 | let url: Uri = ("http://127.0.0.1:".to_string() + &port.to_string()) 59 | .parse() 60 | .unwrap(); 61 | // This request should not populate the cache. 62 | common::client_get(url.clone()); 63 | 64 | upstream_server.shutdown_now().wait().unwrap(); 65 | 66 | // We must not get a cached response. 67 | let response2 = common::client_get(url); 68 | assert_eq!(response2.status(), StatusCode::BAD_GATEWAY); 69 | } 70 | 71 | // A response must not be cached longer than the max-age cache-control headers 72 | // says. 73 | #[test] 74 | fn max_age_expired() { 75 | let port = common::get_free_port(); 76 | let upstream_port = common::get_free_port(); 77 | 78 | let upstream_server = common::start_dummy_server(upstream_port, |request| { 79 | let mut response = echo_request(request); 80 | { 81 | let headers = response.headers_mut(); 82 | headers.append(CACHE_CONTROL, "public,max-age=1".parse().unwrap()); 83 | } 84 | response 85 | }); 86 | let _proxy = rustnish::start_server_background(port, upstream_port); 87 | 88 | let url: Uri = ("http://127.0.0.1:".to_string() + &port.to_string()) 89 | .parse() 90 | .unwrap(); 91 | // This request should populate the cache. 92 | common::client_get(url.clone()); 93 | 94 | upstream_server.shutdown_now().wait().unwrap(); 95 | 96 | // Wait 1 second, then the cache must have expired this response. 97 | thread::sleep(Duration::from_secs(1)); 98 | 99 | // We must not get a cached response. 100 | let response2 = common::client_get(url); 101 | assert_eq!(response2.status(), StatusCode::BAD_GATEWAY); 102 | } 103 | 104 | // If a request contains a session cookie then it should bypass the cache. 105 | #[test] 106 | fn session_cookie_bypass() { 107 | let port = common::get_free_port(); 108 | let upstream_port = common::get_free_port(); 109 | 110 | let upstream_server = common::start_dummy_server(upstream_port, |request| { 111 | let mut response = echo_request(request); 112 | { 113 | let headers = response.headers_mut(); 114 | headers.append(CACHE_CONTROL, "public,max-age=1800".parse().unwrap()); 115 | } 116 | response 117 | }); 118 | let _proxy = rustnish::start_server_background(port, upstream_port); 119 | 120 | let url: Uri = ("http://127.0.0.1:".to_string() + &port.to_string()) 121 | .parse() 122 | .unwrap(); 123 | // This request should populate the cache. 124 | common::client_get(url.clone()); 125 | 126 | upstream_server.shutdown_now().wait().unwrap(); 127 | 128 | // We must not get a cached response when we set a session cookie. 129 | let mut request = Request::builder(); 130 | request.uri(url).header(COOKIE, "SESS1234567=xyz"); 131 | 132 | let response2 = common::client_request(request.body(Body::empty()).unwrap()); 133 | assert_eq!(response2.status(), StatusCode::BAD_GATEWAY); 134 | } 135 | 136 | // Tests that a very small cache of 10 bytes can never hold an HTTP response. 137 | #[test] 138 | fn insufficient_cache_size() { 139 | let port = common::get_free_port(); 140 | let upstream_port = common::get_free_port(); 141 | 142 | let upstream_server = common::start_dummy_server(upstream_port, |request| { 143 | let mut response = echo_request(request); 144 | { 145 | let headers = response.headers_mut(); 146 | headers.append(CACHE_CONTROL, "public,max-age=1800".parse().unwrap()); 147 | } 148 | response 149 | }); 150 | let _proxy = rustnish::start_server_background_memory(port, upstream_port, 10); 151 | 152 | let url: Uri = ("http://127.0.0.1:".to_string() + &port.to_string()) 153 | .parse() 154 | .unwrap(); 155 | // This request should not populate the cache. 156 | common::client_get(url.clone()); 157 | 158 | upstream_server.shutdown_now().wait().unwrap(); 159 | 160 | // We must not get a cached response because the cache is too small. 161 | let response2 = common::client_get(url); 162 | assert_eq!(response2.status(), StatusCode::BAD_GATEWAY); 163 | } 164 | -------------------------------------------------------------------------------- /tests/common/mod.rs: -------------------------------------------------------------------------------- 1 | use futures::Future; 2 | use hyper::service::service_fn_ok; 3 | use hyper::{Body, Request, Response}; 4 | use hyper::{Client, Server, Uri}; 5 | use std::str; 6 | use std::sync::atomic::{AtomicUsize, Ordering}; 7 | use tokio::runtime::Runtime; 8 | 9 | // Return the received request in the response body for testing purposes. 10 | pub fn echo_request(request: Request) -> Response { 11 | Response::builder() 12 | .body(Body::from(format!("{:?}", request))) 13 | .unwrap() 14 | } 15 | 16 | // Starts a dummy server in a separate thread. 17 | pub fn start_dummy_server( 18 | port: u16, 19 | response_function: fn(Request) -> Response, 20 | ) -> Runtime { 21 | let address = "127.0.0.1:".to_owned() + &port.to_string(); 22 | let addr = address.parse().unwrap(); 23 | 24 | let new_svc = move || service_fn_ok(response_function); 25 | 26 | let server = Server::bind(&addr).serve(new_svc).map_err(|_| ()); 27 | 28 | let mut runtime = Runtime::new().unwrap(); 29 | runtime.spawn(server); 30 | runtime 31 | } 32 | 33 | // Since it so complicated to make a client request with a Hyper runtime we have 34 | // this helper function. 35 | #[allow(dead_code)] 36 | pub fn client_get(url: Uri) -> Response { 37 | let client = Client::new(); 38 | let work = client.get(url).and_then(Ok); 39 | 40 | let mut rt = Runtime::new().unwrap(); 41 | rt.block_on(work).unwrap() 42 | } 43 | 44 | #[allow(dead_code)] 45 | pub fn client_post(url: Uri, body: &'static str) -> Response { 46 | let client = Client::new(); 47 | 48 | let req = Request::builder() 49 | .method("POST") 50 | .uri(url) 51 | .body(Body::from(body)) 52 | .unwrap(); 53 | 54 | let work = client.request(req).and_then(Ok); 55 | let mut rt = Runtime::new().unwrap(); 56 | rt.block_on(work).unwrap() 57 | } 58 | 59 | // Since it so complicated to make a client request with a Tokio runtime we have 60 | // this helper function. 61 | #[allow(dead_code)] 62 | pub fn client_request(request: Request) -> Response { 63 | let client = Client::new(); 64 | let work = client.request(request).and_then(Ok); 65 | let mut rt = Runtime::new().unwrap(); 66 | rt.block_on(work).unwrap() 67 | } 68 | 69 | // Returns a local port number that has not been used yet in parallel test 70 | // threads. 71 | pub fn get_free_port() -> u16 { 72 | static PORT_NR: AtomicUsize = AtomicUsize::new(0); 73 | 74 | PORT_NR.fetch_add(1, Ordering::SeqCst) as u16 + 9090 75 | } 76 | -------------------------------------------------------------------------------- /tests/response_and_headers.rs: -------------------------------------------------------------------------------- 1 | use crate::common::echo_request; 2 | use futures::{Future, Stream}; 3 | use hyper::header::{HOST, SERVER, VIA}; 4 | use hyper::StatusCode; 5 | use hyper::{Body, Request}; 6 | use std::str; 7 | 8 | mod common; 9 | 10 | #[test] 11 | fn pass_through() { 12 | let port = common::get_free_port(); 13 | let upstream_port = common::get_free_port(); 14 | 15 | // Start a dummy server that just echoes the request. 16 | let _dummy_server = common::start_dummy_server(upstream_port, echo_request); 17 | 18 | // Start our reverse proxy which forwards to the dummy server. 19 | let _proxy = rustnish::start_server_background(port, upstream_port); 20 | 21 | // Make a request to the proxy and check if we get the echo back. 22 | let url = ("http://127.0.0.1:".to_string() + &port.to_string()) 23 | .parse() 24 | .unwrap(); 25 | let response = common::client_get(url); 26 | 27 | assert_eq!(response.headers().get(VIA).unwrap(), "1.1 rustnish-0.0.1"); 28 | 29 | assert_eq!(response.headers().get(SERVER).unwrap(), "rustnish"); 30 | 31 | let body = response.into_body().concat2().wait().unwrap(); 32 | let result = str::from_utf8(&body).unwrap(); 33 | 34 | // Check that the request method was GET. 35 | assert_eq!( 36 | "Request { method: GET, uri: /, version: HTTP/1.1, headers: {\"h", 37 | &result[..62] 38 | ); 39 | 40 | // Check that an X-Forwarded-For header was added on the request. 41 | assert!(result.contains("\"x-forwarded-for\": \"127.0.0.1\"")); 42 | 43 | assert!(result.contains(&format!("\"x-forwarded-port\": \"{}\"", port),)); 44 | } 45 | 46 | // Tests that if the proxy cannot connect to upstream it returns a 502 response. 47 | #[test] 48 | fn upstream_down() { 49 | let port = common::get_free_port(); 50 | let upstream_port = common::get_free_port(); 51 | 52 | let _proxy = rustnish::start_server_background(port, upstream_port); 53 | 54 | // Make a request to the proxy and check the response. 55 | let url = ("http://127.0.0.1:".to_string() + &port.to_string()) 56 | .parse() 57 | .unwrap(); 58 | let response = common::client_get(url); 59 | 60 | assert_eq!(StatusCode::BAD_GATEWAY, response.status()); 61 | assert_eq!( 62 | Ok("Something went wrong, please try again later."), 63 | str::from_utf8(&response.into_body().concat2().wait().unwrap()) 64 | ); 65 | } 66 | 67 | // Tests that an invalid HTTP host header does not cause a panic. 68 | #[test] 69 | fn invalid_host() { 70 | let port = common::get_free_port(); 71 | let upstream_port = common::get_free_port(); 72 | 73 | let _proxy = rustnish::start_server_background(port, upstream_port); 74 | 75 | let url = "http://127.0.0.1:".to_string() + &port.to_string(); 76 | let mut request = Request::builder(); 77 | request.uri(url).header(HOST, "$$$"); 78 | 79 | let response = common::client_request(request.body(Body::empty()).unwrap()); 80 | 81 | // The proxy just tries to forward that as is, but no one is listening. 82 | assert_eq!(StatusCode::BAD_GATEWAY, response.status()); 83 | assert_eq!( 84 | Ok("Something went wrong, please try again later."), 85 | str::from_utf8(&response.into_body().concat2().wait().unwrap()) 86 | ); 87 | } 88 | 89 | // Tests the error result if a port is already occupied on this host. 90 | #[test] 91 | fn port_occupied() { 92 | // Use the same port for upstream server and proxy, which will cause an 93 | // error. 94 | let port = common::get_free_port(); 95 | 96 | let _dummy_server = common::start_dummy_server(port, echo_request); 97 | let error_chain = rustnish::start_server_blocking(port, port).unwrap_err(); 98 | assert_eq!(error_chain.description(), "Spawning server thread failed"); 99 | let mut iter = error_chain.iter(); 100 | let _first = iter.next(); 101 | let second = iter.next().unwrap(); 102 | assert_eq!( 103 | second.to_string(), 104 | format!("Failed to bind server to address 127.0.0.1:{}", port) 105 | ); 106 | let _third = iter.next(); 107 | let fourth = iter.next().unwrap(); 108 | // The exact error code is different on Linux and MacOS, so we test just for 109 | // the beginning of the error message. 110 | assert_eq!( 111 | &fourth.to_string()[..32], 112 | "Address already in use (os error" 113 | ); 114 | } 115 | 116 | // Tests that POST requests are also passed through. 117 | #[test] 118 | fn post_request() { 119 | let port = common::get_free_port(); 120 | let upstream_port = common::get_free_port(); 121 | 122 | let _post_server = common::start_dummy_server(upstream_port, echo_request); 123 | 124 | // Start our reverse proxy which forwards to the post server. 125 | let _proxy = rustnish::start_server_background(port, upstream_port); 126 | 127 | // Make a request to the proxy and check if we get the correct result back. 128 | let url = ("http://127.0.0.1:".to_string() + &port.to_string()) 129 | .parse() 130 | .unwrap(); 131 | let response = common::client_post(url, "abc"); 132 | 133 | let body = response.into_body().concat2().wait().unwrap(); 134 | let result = str::from_utf8(&body).unwrap(); 135 | 136 | assert_eq!( 137 | "Request { method: POST, uri: /, version: HTTP/1.1, headers: {\"h", 138 | &result[..63] 139 | ); 140 | 141 | // Check that an X-Forwarded-For header was added on the request. 142 | assert!(result.contains("\"x-forwarded-for\": \"127.0.0.1\"")); 143 | 144 | assert!(result.contains(&format!("\"x-forwarded-port\": \"{}\"", port),)); 145 | } 146 | 147 | // Tests that if an X-Forwarded-For header already exists on the request then 148 | // the proxy adds another value. 149 | #[test] 150 | fn x_forwarded_for_added() { 151 | let port = common::get_free_port(); 152 | let upstream_port = common::get_free_port(); 153 | 154 | let _dummy_server = common::start_dummy_server(upstream_port, echo_request); 155 | let _proxy = rustnish::start_server_background(port, upstream_port); 156 | 157 | let request = Request::builder() 158 | .uri("http://127.0.0.1:".to_string() + &port.to_string()) 159 | .header("X-Forwarded-For", "1.2.3.4") 160 | .body(Body::empty()) 161 | .unwrap(); 162 | 163 | let response = common::client_request(request); 164 | 165 | let body = response.into_body().concat2().wait().unwrap(); 166 | let result = str::from_utf8(&body).unwrap(); 167 | 168 | // Check that the request method was GET. 169 | assert_eq!( 170 | "Request { method: GET, uri: /, version: HTTP/1.1, headers: {\"x", 171 | &result[..62] 172 | ); 173 | 174 | // Check that an X-Forwarded-For header was added on the request. 175 | assert!(result.contains("\"x-forwarded-for\": \"1.2.3.4\"",)); 176 | assert!(result.contains("\"x-forwarded-for\": \"127.0.0.1\"",)); 177 | } 178 | 179 | // Tests that if a Via header already exists on the request then the proxy adds 180 | // another value. 181 | #[test] 182 | fn via_header_added() { 183 | let port = common::get_free_port(); 184 | let upstream_port = common::get_free_port(); 185 | 186 | let _dummy_server = common::start_dummy_server(upstream_port, |request| { 187 | let mut response = echo_request(request); 188 | { 189 | let headers = response.headers_mut(); 190 | headers.append(VIA, "1.1 test".parse().unwrap()); 191 | } 192 | response 193 | }); 194 | let _proxy = rustnish::start_server_background(port, upstream_port); 195 | 196 | let url = ("http://127.0.0.1:".to_string() + &port.to_string()) 197 | .parse() 198 | .unwrap(); 199 | let response = common::client_get(url); 200 | 201 | let mut via_headers = response.headers().get_all(VIA).iter(); 202 | assert_eq!(&"1.1 test", via_headers.next().unwrap()); 203 | assert_eq!(&"1.1 rustnish-0.0.1", via_headers.next().unwrap()); 204 | } 205 | 206 | // Tests that if a Server HTTP header is present from upstream it is not 207 | // overwritten. 208 | #[test] 209 | fn server_header_present() { 210 | let port = common::get_free_port(); 211 | let upstream_port = common::get_free_port(); 212 | 213 | let _dummy_server = common::start_dummy_server(upstream_port, |request| { 214 | let mut response = echo_request(request); 215 | { 216 | response 217 | .headers_mut() 218 | .insert(SERVER, "dummy-server".parse().unwrap()); 219 | } 220 | response 221 | }); 222 | let _proxy = rustnish::start_server_background(port, upstream_port); 223 | 224 | let url = ("http://127.0.0.1:".to_string() + &port.to_string()) 225 | .parse() 226 | .unwrap(); 227 | let response = common::client_get(url); 228 | 229 | let server_header = response.headers().get(SERVER).unwrap(); 230 | assert_eq!(server_header, "dummy-server"); 231 | } 232 | 233 | // Tests that URL query parameters are passed through. 234 | #[test] 235 | fn query_parameters() { 236 | let port = common::get_free_port(); 237 | let upstream_port = common::get_free_port(); 238 | 239 | let _post_server = common::start_dummy_server(upstream_port, echo_request); 240 | 241 | let _proxy = rustnish::start_server_background(port, upstream_port); 242 | 243 | // Make a request to the proxy and check if we get the correct result back. 244 | let url = ("http://127.0.0.1:".to_string() + &port.to_string() + "/test?key=value") 245 | .parse() 246 | .unwrap(); 247 | let response = common::client_get(url); 248 | 249 | let body = response.into_body().concat2().wait().unwrap(); 250 | let result = str::from_utf8(&body).unwrap(); 251 | 252 | assert_eq!( 253 | "Request { method: GET, uri: /test?key=value, version: HTTP/1.1, headers: {\"h", 254 | &result[..76] 255 | ); 256 | } 257 | --------------------------------------------------------------------------------