ceylon-sdk
ceylon-sdk copied to clipboard
serveStaticFile() only works sometimes
Maybe I'm doing something wrong, but using this code
import ceylon.http.server {
newServer,
AsynchronousEndpoint,
isRoot
}
import ceylon.io {
SocketAddress
}
import ceylon.http.server.endpoints {
serveStaticFile
}
shared void bug() {
value server = newServer {
AsynchronousEndpoint {
path = isRoot();
service = serveStaticFile {
externalPath = "README.txt";
};
}
};
server.start(SocketAddress("127.0.0.1",8080));
}
A get request to http://localhost:8080/
only seems to work about 50% of the time (often alternating working and not). When it doesn't work I see an empty 200 response.
Looking at the test case [1], the only difference is that test uses a fat arrow "=>" to assign service.
p.s.: did you try to run the sdk tests, do they always pass ?
1: https://github.com/ceylon/ceylon-sdk/blob/master/test-source/test/ceylon/http/server/server.ceylon#L188
The tests don't pass at all. The reason seems to be that the failing assertions are being executed on worker threads, so never propagate out of the test
function being run on the main thread. :-(
0b92c898f9fa50f4b0f05fd662169bf49e882c29 fixes the tests so that exceptions throw in the worker threads get rethrown from the main thread, resulting in the testServer
test failing. I suspect a similar fix may be necessary for other tests.
I tried your code and it worked in Chrome, Safari and Opera. Can you try again to see if it really doesn't work?