Maybe this will be helpful? https://github.com/erlyvideo/erlyvideo/blob/master/apps/erlyvideo/src/http/ems_http_file.erl