Serving big files through HTTP

Hi Forum,
I have developed a custom module for serving static files through HTTP. I have seen how mod_http_fileserver and mod_http_upload deal with files but I'm not happy about their solutions. I mean modules are excellent and really well written but in my case I need to deal with few and bigger files. Basically the process/2 function is fine but for every source code I see something like file:read_file(NameOfTheFile). I'm still a newbie but I know I can use file:open/2 and file:close/1 to deal with a file and file:pread/3 inside a loop function to read a file in chunks.
But from what I can see the process/2 function needs to return a tuple like: { HTTPStatus, Headers, Body } . I cannot output http results directly from there by passing pieces of chunk to the output (there's no output at all). Can someone drive me in the right direction for pushing out a big file (example: 200Mb) through HTTP without wasting 200Mb in a Variable?
I cannot use an external HTTP server for it because I need integration between XMPP (for signaling) and HTTP (for outputting data). I'd like to develop something inside the process/2 function but I don't know the right approach to it with ejabberd (and erlang)

Kind Regards
Ben

Your problem is more related

Your problem is more related to the erlang language, and the OTP libraries than ejabberd. Look at HTTP servers written in erlang, starting with Yaws, maybe they give you some hint?

It's related to Erlang (I'm a

It's related to Erlang (I'm a pool imperative programmer sorry :) ), you're right, but I'd like to explain you why ejabberd matters.
In these days I have spent some time on it and I figured out how to avoid this problem with gen_tcp. I have seen yaws and other projects and those pointed me on serving http content as multipart/form data. I have built something from scratch without ejabberd and I have had quite good results, now the problem seems to be related to process/2 in my module, I'm under ejabberd_http in my config file, something like:

-
  port: 5280
    module: ejabberd_http
    request_handlers:
      "/files": modfileupload  ## Here I am
    http_bind: true
    register: false
    captcha: false

and when something like http://localhost:5280/files/somethingelse is called I receive a request on process/2. process/2 needs to return back some data with a tuple like {HTTPCode, Headers, PageContent}. If PageContent is huge everything crashes.
I wish to reply back to the client directly (on a socket) without passing the content inside a tuple/variable to someone else function. I'd like to manage directly the headers and output data as multipart to the client, I guess I could obtain better results. It seems ejabberd_http.erl calls socket_handoff/6 in my module (when available) but I don't know how to use it or if there're usage examples.
Any hints ? Am I following the right path ?

Thanks again
Ben

Well, if you found that

Well, if you found that ejabberd's listener is slowing you, you can avoid it. In the same Erlang node where ejabberd is running, you can start other applications, Yaws for instance, and serve HTTP queries from there. See https://www.ejabberd.im/yawspack for example

Thanks Badlop, I've looked at

Thanks Badlop, I've looked at yaws but I wasn't aware of that kind of integration with ejabberd, I'll definitively look at it. These are simple questions but I'm still a beginner with ejabberd (and erlang as well..)

Syndicate content