Skip to content

Commit

Permalink
Setup redirect server; enable tests for fetch_sync_string
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinkassimo committed Oct 10, 2018
1 parent 359a762 commit d2f27eb
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/http.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,3 +83,13 @@ fn test_fetch_sync_string() {
assert!(p.len() > 1);
});
}

#[test]
fn test_fetch_sync_string_with_redirect() {
// Relies on external http server. See tools/http_server.py
tokio_util::init(|| {
let p = fetch_sync_string("https://127.0.0.1:4546/package.json").unwrap();
println!("package.json len {}", p.len());
assert!(p.len() > 1);
});
}
25 changes: 25 additions & 0 deletions tools/http_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from time import sleep

PORT = 4545
REDIRECT_PORT = 4546


def server():
Expand All @@ -20,11 +21,35 @@ def server():
return s


def redirect_server():
os.chdir(root_path)
target_host = "https://localhost:%d" % PORT

class RedirectHandler(SimpleHTTPServer.SimpleHTTPRequestHandler):
def do_GET(self):
self.send_response(301)
self.send_header('Location', target_host + self.path)
self.end_headers()

Handler = RedirectHandler
SocketServer.TCPServer.allow_reuse_address = True
s = SocketServer.TCPServer(("", REDIRECT_PORT), Handler)
print "Deno redirect server https://localhost:%d/ -> https://localhost:%d/" % (
REDIRECT_PORT, PORT)
return s


def spawn():
# Main http server
s = server()
thread = Thread(target=s.serve_forever)
thread.daemon = True
thread.start()
# Redirect server
rs = redirect_server()
r_thread = Thread(target=rs.serve_forever)
r_thread.daemon = True
r_thread.start()
sleep(1) # TODO I'm too lazy to figure out how to do this properly.
return thread

Expand Down

0 comments on commit d2f27eb

Please sign in to comment.