Skip to content

Instantly share code, notes, and snippets.

@HeinrichApfelmus
Last active December 17, 2015 09:59
Show Gist options
  • Save HeinrichApfelmus/5591688 to your computer and use it in GitHub Desktop.
Save HeinrichApfelmus/5591688 to your computer and use it in GitHub Desktop.
Web servers fail to serve large files on MacOS X.
-- debug log for querying http://localhost:100000/video.mp4 with Chrome
Listening on http://0.0.0.0:10000/
Can't open log file "log/access.log".
Exception: log/access.log: openFile: does not exist (No such file or directory)
Logging to stderr instead. **THIS IS BAD, YOU OUGHT TO FIX THIS**
Can't open log file "log/error.log".
Exception: log/error.log: openFile: does not exist (No such file or directory)
Logging to stderr instead. **THIS IS BAD, YOU OUGHT TO FIX THIS**
[ 70] Server: Server.httpServe: START, binding to [http://0.0.0.0:10000/]
[22/May/2013:16:59:59 +0200] Server.httpServe: START, binding to [http://0.0.0.0:10000/]
[ 70] bindHttp: binding port 0.0.0.0:10000
[ 70] bindHttp: bound socket <socket: 9>
[ 70] simpleEventLoop: waiting for mvars
[ 74] acceptThread: calling accept() on socket ListenHttp (<socket: 9>)
[ 74] acceptThread: accepted connection from remote: 127.0.0.1:50985
[ 74] acceptThread: calling accept() on socket ListenHttp (<socket: 9>)
[ 75] Backend.withConnection: running session: 127.0.0.1:50985
[ 75] runHTTP/go: prepping iteratee for start
[ 75] httpSession iteratee: BEGIN
[ 75] Server.httpSession: entered
[ 75] receiveRequest: entered
[ 75] parseRequest: BEGIN
[ 75] parseRequest: continue
[ 75] httpSession iteratee: continue
[ 75] runHTTP/go: running...
[ 75] SimpleBackend.enumerate(10): reading from socket
[ 75] SimpleBackend.enumerate(10): got 370 bytes from read end
[ 75] SimpleBackend.enumerate(10): sending "GET /video.mp4 HTTP/1.1\r\nHost: localhost:10000\r\nConnection: keep-alive\r\nAccept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8\r\nUser-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_6_8) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/27.0.1453.93 Safari/537.36\r\nAccept-Encoding: gzip,deflate,sdch\r\nAccept-Language: de-DE,de;q=0.8,en-US;q=0.6,en;q=0.4\r\n\r\n" to continuation
[ 75] httpSession iteratee: got chunk: ["\"GET /video.mp4 HTTP/1.1\\r\\nHost: localhost:10000\\r\\nConnection: keep-alive\\r\\nAccept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8\\r\\nUser-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_6_8) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/27.0.1453.93 Safari/537.36\\r\\nAccept-Encoding: gzip,deflate,sdch\\r\\nAccept-Language: de-DE,de;q=0.8,en-US;q=0.6,en;q=0.4\\r\\n\\r\\n\""]
[ 75] parseRequest: got chunk: ["\"GET /video.mp4 HTTP/1.1\\r\\nHost: localhost:10000\\r\\nConnection: keep-alive\\r\\nAccept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8\\r\\nUser-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_6_8) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/27.0.1453.93 Safari/537.36\\r\\nAccept-Encoding: gzip,deflate,sdch\\r\\nAccept-Language: de-DE,de;q=0.8,en-US;q=0.6,en;q=0.4\\r\\n\\r\\n\""]
[ 75] parseRequest: yield, with remainder Chunks ["\"\""]
[ 75] receiveRequest: parseRequest returned
[ 75] receiveRequest/setEnumerator: request did NOT have content-length
[ 75] receiveRequest/setEnumerator: body enumerator set
[ 75] Server.httpSession: receiveRequest finished
[ 75] Server.httpSession: got request: GET /video.mp4 (1,1)
[ 75] FileServe:mbIfModified: Nothing
[ 75] FileServe:mbIfRange: Nothing
[ 75] FileServe:checkRangeReq, fp=/Users/hgz/Downloads/Pachelbel_Rant.mp4, sz=15598009
[ 75] FileServe:was this a range request? False
[ 75] withCompression', content-type is Just "application/octet-stream"
[ 75] Server.httpSession: finished running user handler
[ 75] Server.httpSession: handled, skipping request body
[ 75] httpSession/skipToEof: BEGIN
[ 75] httpSession/skipToEof: continue
[ 75] noContentLength: BEGIN
[ 75] httpSession/skipToEof: got EOF
[ 75] noContentLength: yield, with remainder Chunks []
[ 75] Server.httpSession: request body skipped, sending response
[ 75] writeEnd: BEGIN
[ 75] writeEnd: continue
[ 75] writeEnd: got chunk: ["\"HTTP/1.1 200 OK\\r\\nLast-Modified: Tue, 14 May 2013 14:07:09 GMT\\r\\nContent-Length: 15598009\\r\\nDate: Wed, 22 May 2013 15:00:06 GMT\\r\\nContent-Type: application/octet-stream\\r\\nAccept-Ranges: bytes\\r\\nServer: Snap/0.9.3.3\\r\\n\\r\\n\""]
[ 75] SimpleBackend.writeOut(10): got chunk with 212 bytes
[ 75] SimpleBackend.writeOut(10): wrote 212 bytes, last 10=".9.3.3\r\n\r\n"
[ 75] writeEnd: continue
[ 75] Server: httpSession caught an exception during sending response phase:
During processing of request from 127.0.0.1:50985
request:
"Request <\n server-name: localhost\n remote: 127.0.0.1:50985\n local: 127.0.0.1:10000\n Headers:\n ========================================\n Connection: keep-alive\n Accept-Encoding: gzip,deflate,sdch\n Accept-Language: de-DE,de;q=0.8,en-US;q=0.6,en;q=0.4\n Host: localhost:10000\n User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_6_8) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/27.0.1453.93 Safari/537.36\n Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8\n ========================================\n content-length: Nothing\n method: GET\n version: (1,1)\n cookies:\n ========================================\n \n ========================================\n pathinfo: video.mp4\n contextpath: /\n URI: /video.mp4\n params:\n ========================================\n \n ========================================\n>"
A web handler threw an exception. Details:
System.SendFile.Darwin: invalid argument (Socket is not connected)
[ 75] thread killed, closing socket
[22/May/2013:17:00:06 +0200] httpSession caught an exception during sending response phase:
During processing of request from 127.0.0.1:50985
request:
"Request <\n server-name: localhost\n remote: 127.0.0.1:50985\n local: 127.0.0.1:10000\n Headers:\n ========================================\n Connection: keep-alive\n Accept-Encoding: gzip,deflate,sdch\n Accept-Language: de-DE,de;q=0.8,en-US;q=0.6,en;q=0.4\n Host: localhost:10000\n User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_6_8) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/27.0.1453.93 Safari/537.36\n Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8\n ========================================\n content-length: Nothing\n method: GET\n version: (1,1)\n cookies:\n ========================================\n \n ========================================\n pathinfo: video.mp4\n contextpath: /\n URI: /video.mp4\n params:\n ========================================\n \n ========================================\n>"
A web handler threw an exception. Details:
System.SendFile.Darwin: invalid argument (Socket is not connected)
^C[ 70] simpleEventLoop: killing all threads
[ 70] Server: Server.httpServe: SHUTDOWN
[ 70] Server: Server.httpServe: BACKEND STOPPED
[22/May/2013:17:01:11 +0200] Server.httpServe: SHUTDOWN
[22/May/2013:17:01:11 +0200] Server.httpServe: BACKEND STOPPED
Shutting down...
*Main> snap
Listening on http://0.0.0.0:10000/
[Can't open log file "log/error.log".
Exception: log/error.log: openFile: does not exist (No such file or directory)
Logging to stderr instead. **THIS IS BAD, YOU OUGHT TO FIX THIS**
93] Server: Server.httpServe: START, binding to [http://0.0.0.0:10000/]
[ 93] bindHttp: binding port 0.0.0.0:10000
[ 93] bindHttp: bound socket <socket: 9>
[Can't open log file "log/access.log".
[22/May/2013:17:02:59 +0200] Server.httpServe: START, binding to [http://0.0.0.0:10000/]
Exception: log/access.log: openFile: does not exist (No such file or directory)
Logging to stderr instead. **THIS IS BAD, YOU OUGHT TO FIX THIS**
93] simpleEventLoop: waiting for mvars
[ 97] acceptThread: calling accept() on socket ListenHttp (<socket: 9>)
[ 97] acceptThread: accepted connection from remote: 127.0.0.1:50996
[ 97] acceptThread: calling accept() on socket ListenHttp (<socket: 9>)
[ 99] Backend.withConnection: running session: 127.0.0.1:50996
[ 99] runHTTP/go: prepping iteratee for start
[ 99] httpSession iteratee: BEGIN
[ 99] Server.httpSession: entered
[ 99] receiveRequest: entered
[ 99] parseRequest: BEGIN
[ 99] parseRequest: continue
[ 99] httpSession iteratee: continue
[ 99] runHTTP/go: running...
[ 99] SimpleBackend.enumerate(10): reading from socket
[ 99] SimpleBackend.enumerate(10): got 307 bytes from read end
[ 99] SimpleBackend.enumerate(10): sending "GET /video.mp4 HTTP/1.1\r\nHost: localhost:10000\r\nUser-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.6; rv:19.0) Gecko/20100101 Firefox/19.0\r\nAccept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8\r\nAccept-Language: en-US,en;q=0.5\r\nAccept-Encoding: gzip, deflate\r\nConnection: keep-alive\r\n\r\n" to continuation
[ 99] httpSession iteratee: got chunk: ["\"GET /video.mp4 HTTP/1.1\\r\\nHost: localhost:10000\\r\\nUser-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.6; rv:19.0) Gecko/20100101 Firefox/19.0\\r\\nAccept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8\\r\\nAccept-Language: en-US,en;q=0.5\\r\\nAccept-Encoding: gzip, deflate\\r\\nConnection: keep-alive\\r\\n\\r\\n\""]
[ 99] parseRequest: got chunk: ["\"GET /video.mp4 HTTP/1.1\\r\\nHost: localhost:10000\\r\\nUser-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.6; rv:19.0) Gecko/20100101 Firefox/19.0\\r\\nAccept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8\\r\\nAccept-Language: en-US,en;q=0.5\\r\\nAccept-Encoding: gzip, deflate\\r\\nConnection: keep-alive\\r\\n\\r\\n\""]
[ 99] parseRequest: yield, with remainder Chunks ["\"\""]
[ 99] receiveRequest: parseRequest returned
[ 99] receiveRequest/setEnumerator: request did NOT have content-length
[ 99] receiveRequest/setEnumerator: body enumerator set
[ 99] Server.httpSession: receiveRequest finished
[ 99] Server.httpSession: got request: GET /video.mp4 (1,1)
[ 99] FileServe:mbIfModified: Nothing
[ 99] FileServe:mbIfRange: Nothing
[ 99] FileServe:checkRangeReq, fp=/Users/hgz/Downloads/Pachelbel_Rant.mp4, sz=15598009
[ 99] FileServe:was this a range request? False
[ 99] withCompression', content-type is Just "application/octet-stream"
[ 99] Server.httpSession: finished running user handler
[ 99] Server.httpSession: handled, skipping request body
[ 99] httpSession/skipToEof: BEGIN
[ 99] httpSession/skipToEof: continue
[ 99] noContentLength: BEGIN
[ 99] httpSession/skipToEof: got EOF
[ 99] noContentLength: yield, with remainder Chunks []
[ 99] Server.httpSession: request body skipped, sending response
[ 99] writeEnd: BEGIN
[ 99] writeEnd: continue
[ 99] writeEnd: got chunk: ["\"HTTP/1.1 200 OK\\r\\nLast-Modified: Tue, 14 May 2013 14:07:09 GMT\\r\\nContent-Length: 15598009\\r\\nDate: Wed, 22 May 2013 15:03:14 GMT\\r\\nContent-Type: application/octet-stream\\r\\nAccept-Ranges: bytes\\r\\nServer: Snap/0.9.3.3\\r\\n\\r\\n\""]
[ 99] SimpleBackend.writeOut(10): got chunk with 212 bytes
[ 99] SimpleBackend.writeOut(10): wrote 212 bytes, last 10=".9.3.3\r\n\r\n"
[ 99] writeEnd: continue
[ 99] sendResponse: response sent
[ 99] Server.httpSession: sent 15598009 bytes
[ 99] Server.httpSession: entered
[ 99] receiveRequest: entered
[ 99] parseRequest: BEGIN
[ 99] parseRequest: continue
[ 99] parseRequest: got chunk: ["\"\""]
[ 99] parseRequest: continue
[ 99] httpSession iteratee: continue
[ 99] SimpleBackend.enumerate(10): got continue
[ 99] SimpleBackend.enumerate(10): reading from socket
127.0.0.1 - - [22/May/2013:17:03:20 +0200] "GET /video.mp4 HTTP/1.1" 200 15598009 - "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.6; rv:19.0) Gecko/20100101 Firefox/19.0"
[ 99] SimpleBackend.enumerate(10): got 279 bytes from read end
[ 99] SimpleBackend.enumerate(10): sending "GET /favicon.ico HTTP/1.1\r\nHost: localhost:10000\r\nUser-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.6; rv:19.0) Gecko/20100101 Firefox/19.0\r\nAccept: image/png,image/*;q=0.8,*/*;q=0.5\r\nAccept-Language: en-US,en;q=0.5\r\nAccept-Encoding: gzip, deflate\r\nConnection: keep-alive\r\n\r\n" to continuation
[ 99] httpSession iteratee: got chunk: ["\"GET /favicon.ico HTTP/1.1\\r\\nHost: localhost:10000\\r\\nUser-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.6; rv:19.0) Gecko/20100101 Firefox/19.0\\r\\nAccept: image/png,image/*;q=0.8,*/*;q=0.5\\r\\nAccept-Language: en-US,en;q=0.5\\r\\nAccept-Encoding: gzip, deflate\\r\\nConnection: keep-alive\\r\\n\\r\\n\""]
[ 99] parseRequest: got chunk: ["\"GET /favicon.ico HTTP/1.1\\r\\nHost: localhost:10000\\r\\nUser-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.6; rv:19.0) Gecko/20100101 Firefox/19.0\\r\\nAccept: image/png,image/*;q=0.8,*/*;q=0.5\\r\\nAccept-Language: en-US,en;q=0.5\\r\\nAccept-Encoding: gzip, deflate\\r\\nConnection: keep-alive\\r\\n\\r\\n\""]
[ 99] parseRequest: yield, with remainder Chunks ["\"\""]
[ 99] receiveRequest: parseRequest returned
[ 99] receiveRequest/setEnumerator: request did NOT have content-length
[ 99] receiveRequest/setEnumerator: body enumerator set
[ 99] Server.httpSession: receiveRequest finished
[ 99] Server.httpSession: got request: GET /favicon.ico (1,1)
[ 99] Server.httpSession: finished running user handler
[ 99] Server.httpSession: handled, skipping request body
[ 99] httpSession/skipToEof: BEGIN
[ 99] httpSession/skipToEof: continue
[ 99] noContentLength: BEGIN
[ 99] httpSession/skipToEof: got EOF
[ 99] noContentLength: yield, with remainder Chunks []
[ 99] Server.httpSession: request body skipped, sending response
[ 99] sendResponse: whenEnum: enumerating bytes
[ 99] countBytes writeEnd: BEGIN
[ 99] writeEnd: BEGIN
[ 99] writeEnd: continue
[ 99] countBytes writeEnd: continue
[ 99] countBytes writeEnd: got chunk: ["\"HTTP/1.1 404 Not Found\\r\\nTransfer-Encoding: chunked\\r\\nDate: Wed, 22 May 2013 15:03:21 GMT\\r\\nServer: Snap/0.9.3.3\\r\\n\\r\\n0084\\r\\n<!DOCTYPE html>\\n<html>\\n<head>\\n<title>Not found</title>\\n</head>\\n<body>\\n<code>No handler accepted \\\"/favicon.ico\\\"</code>\\n</body></html>\\r\\n0\\r\\n\\r\\n\""]
[ 99] writeEnd: got chunk: ["\"HTTP/1.1 404 Not Found\\r\\nTransfer-Encoding: chunked\\r\\nDate: Wed, 22 May 2013 15:03:21 GMT\\r\\nServer: Snap/0.9.3.3\\r\\n\\r\\n0084\\r\\n<!DOCTYPE html>\\n<html>\\n<head>\\n<title>Not found</title>\\n</head>\\n<body>\\n<code>No handler accepted \\\"/favicon.ico\\\"</code>\\n</body></html>\\r\\n0\\r\\n\\r\\n\""]
[ 99] SimpleBackend.writeOut(10): got chunk with 258 bytes
[ 99] SimpleBackend.writeOut(10): wrote 258 bytes, last 10="ml>\r\n0\r\n\r\n"
[ 99] writeEnd: continue
[ 99] countBytes writeEnd: continue
[ 99] countBytes writeEnd: got EOF
[ 99] writeEnd: got EOF
[ 99] sendResponse: whenEnum: 258 bytes enumerated
[ 99] sendResponse: response sent
[ 99] Server.httpSession: sent 145 bytes
[ 99] Server.httpSession: entered
[ 99] receiveRequest: entered
[ 99] parseRequest: BEGIN
[ 99] parseRequest: continue
[ 99] parseRequest: got chunk: ["\"\""]
[ 99] parseRequest: continue
[ 99] httpSession iteratee: continue
[ 99] SimpleBackend.enumerate(10): got continue
[ 99] SimpleBackend.enumerate(10): reading from socket
[ 99] SimpleBackend.enumerate(10): got 309 bytes from read end
[ 99] SimpleBackend.enumerate(10): sending "GET /favicon.ico HTTP/1.1\r\nHost: localhost:10000\r\nUser-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.6; rv:19.0) Gecko/20100101 Firefox/19.0\r\nAccept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8\r\nAccept-Language: en-US,en;q=0.5\r\nAccept-Encoding: gzip, deflate\r\nConnection: keep-alive\r\n\r\n" to continuation
[ 99] httpSession iteratee: got chunk: ["\"GET /favicon.ico HTTP/1.1\\r\\nHost: localhost:10000\\r\\nUser-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.6; rv:19.0) Gecko/20100101 Firefox/19.0\\r\\nAccept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8\\r\\nAccept-Language: en-US,en;q=0.5\\r\\nAccept-Encoding: gzip, deflate\\r\\nConnection: keep-alive\\r\\n\\r\\n\""]
[ 99] parseRequest: got chunk: ["\"GET /favicon.ico HTTP/1.1\\r\\nHost: localhost:10000\\r\\nUser-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.6; rv:19.0) Gecko/20100101 Firefox/19.0\\r\\nAccept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8\\r\\nAccept-Language: en-US,en;q=0.5\\r\\nAccept-Encoding: gzip, deflate\\r\\nConnection: keep-alive\\r\\n\\r\\n\""]
[ 99] parseRequest: yield, with remainder Chunks ["\"\""]
[ 99] receiveRequest: parseRequest returned
[ 99] receiveRequest/setEnumerator: request did NOT have content-length
[ 99] receiveRequest/setEnumerator: body enumerator set
[ 99] Server.httpSession: receiveRequest finished
[ 99] Server.httpSession: got request: GET /favicon.ico (1,1)
[ 99] Server.httpSession: finished running user handler
[ 99] Server.httpSession: handled, skipping request body
[ 99] httpSession/skipToEof: BEGIN
[ 99] httpSession/skipToEof: continue
[ 99] noContentLength: BEGIN
[ 99] httpSession/skipToEof: got EOF
[ 99] noContentLength: yield, with remainder Chunks []
[ 99] Server.httpSession: request body skipped, sending response
[ 99] sendResponse: whenEnum: enumerating bytes
[ 99] countBytes writeEnd: BEGIN
[ 99] writeEnd: BEGIN
[ 99] writeEnd: continue
[ 99] countBytes writeEnd: continue
[ 99] countBytes writeEnd: got chunk: ["\"HTTP/1.1 404 Not Found\\r\\nTransfer-Encoding: chunked\\r\\nDate: Wed, 22 May 2013 15:03:21 GMT\\r\\nServer: Snap/0.9.3.3\\r\\n\\r\\n0084\\r\\n<!DOCTYPE html>\\n<html>\\n<head>\\n<title>Not found</title>\\n</head>\\n<body>\\n<code>No handler accepted \\\"/favicon.ico\\\"</code>\\n</body></html>\\r\\n0\\r\\n\\r\\n\""]
[ 99] writeEnd: got chunk: ["\"HTTP/1.1 404 Not Found\\r\\nTransfer-Encoding: chunked\\r\\nDate: Wed, 22 May 2013 15:03:21 GMT\\r\\nServer: Snap/0.9.3.3\\r\\n\\r\\n0084\\r\\n<!DOCTYPE html>\\n<html>\\n<head>\\n<title>Not found</title>\\n</head>\\n<body>\\n<code>No handler accepted \\\"/favicon.ico\\\"</code>\\n</body></html>\\r\\n0\\r\\n\\r\\n\""]
[ 99] SimpleBackend.writeOut(10): got chunk with 258 bytes
[ 99] SimpleBackend.writeOut(10): wrote 258 bytes, last 10="ml>\r\n0\r\n\r\n"
[ 99] writeEnd: continue
[ 99] countBytes writeEnd: continue
[ 99] countBytes writeEnd: got EOF
[ 99] writeEnd: got EOF
[ 99] sendResponse: whenEnum: 258 bytes enumerated
[ 99] sendResponse: response sent
[ 99] Server.httpSession: sent 145 bytes
[ 99] Server.httpSession: entered
[ 99] receiveRequest: entered
[ 99] parseRequest: BEGIN
[ 99] parseRequest: continue
[ 99] parseRequest: got chunk: ["\"\""]
[ 99] parseRequest: continue
[ 99] httpSession iteratee: continue
[ 99] SimpleBackend.enumerate(10): got continue
[ 99] SimpleBackend.enumerate(10): reading from socket
127.0.0.1 - - [22/May/2013:17:03:21 +0200] "GET /favicon.ico HTTP/1.1" 404 - - "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.6; rv:19.0) Gecko/20100101 Firefox/19.0"
127.0.0.1 - - [22/May/2013:17:03:21 +0200] "GET /favicon.ico HTTP/1.1" 404 - - "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.6; rv:19.0) Gecko/20100101 Firefox/19.0"
^C[ 93] simpleEventLoop: killing all threads
[ 93] Server: Server.httpServe: SHUTDOWN
[ 93] Server: Server.httpServe: BACKEND STOPPED
[22/May/2013:17:03:46 +0200] Server.httpServe: SHUTDOWN
[22/May/2013:17:03:46 +0200] Server.httpServe: BACKEND STOPPED
[ 99] thread killed, closing socket
Shutting down...
*Main>
{- Console output when requesting http://localhost:10000/video.mp4
File size is 15598009
error: System.SendFile.Darwin: invalid argument (Socket is not connected)
-}
{-# LANGUAGE OverloadedStrings #-}
import Data.Functor
import System.Posix.Files
import Snap.Core
import Snap.Http.Server hiding (Config)
import Snap.Util.FileServe
main = do
let path = "/Users/apfelmus/Downloads/Example_Video.mp4"
putStrLn . ("File size is " ++) . show . fileSize =<< getFileStatus path
httpServe (setPort 10000 defaultConfig) $ route
[("/video.mp4", serveFile path)]
{- Console output when requesting http://localhost:10000/video.mp4
File size is 15598009
["video.mp4"]
Network.SendFile.MacOS.sendloop: invalid argument (Socket is not connected)
-}
{-# LANGUAGE OverloadedStrings #-}
import System.Posix.Files
import Control.Monad.IO.Class
import Blaze.ByteString.Builder
import Blaze.ByteString.Builder.ByteString
import Network.HTTP.Types
import Network.Wai
import Network.Wai.Handler.Warp
main = wai "/Users/apfelmus/Downloads/ExampleVideo.mp4"
wai path = do
putStrLn . ("File size is " ++) . show . fileSize =<< getFileStatus path
run 10000 $ \request -> do
liftIO $ print $ pathInfo request
return $ case pathInfo request of
["video.mp4"] -> ResponseFile ok200 [] path Nothing
_ -> ResponseBuilder notFound404 [] $ fromByteString "File not found"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment