tiny_httpd icon indicating copy to clipboard operation
tiny_httpd copied to clipboard

session and handling of body in post method

Open craff opened this issue 2 years ago • 6 comments

Two features which are almost always needed are not provided:

  • handling of body with Post method (the normal case is ok with Tiny_httpd_util.parse_query, but things like multipart should be supported)
  • handling of a notion of user session I could contribute as I am implementing those in my server ... but maybe I am missing something?

craff avatar Nov 28 '21 23:11 craff

You're not missing anything, this is really just the httpd part. I think it'd be interesting, maybe, to build a higher-level library on top of it to handle sessions, etc. but this might be scope creep (for a realistic full website you might be better using Dream directly). If you write API endpoints, otoh, this should be enough with maybe a thin session layer, but no multipart?

c-cube avatar Nov 28 '21 23:11 c-cube

I saw you are preparing a release ... I have some code both for parsing multipart post request and for session. Both are very light I think and would fit at this level of the library.

I could move the first code in Util where there is already a parser for GET request and add my code for session in a new module. But both needs some work.

Would you like me to submit pull request before or after the release ?

craff avatar Dec 08 '21 22:12 craff

It's already released, look on opam :).

  • I thought multipart was a nightmare to parse, but I'd be curious to see your code. I still think it belongs in a sub-library (tiny_httpd.multipart? or maybe a kind of small framework on top of tiny http, with sessions, etc.)
    • for sessions, what does it look like? I think in any case it's good to open a PR, no polish needed yet (maybe a draft PR) and then we can discuss :).

c-cube avatar Dec 09 '21 01:12 c-cube

The code is rather small and now in Tiny_httpd_util where there is parse_query. I push a PR, you will see, I actually cleaned the code and mover it in Tiny_httpd on my fork.

I used Str, via a thread safe interface (using mutex). It is much easier that way.

It would be better to use a real regexp library or maybe use pacomb for that. But I feel you want (and I wand) minimum dependency beside Ocaml Stdlib's

craff avatar Dec 09 '21 02:12 craff

For session. I am not sure what to do exactly. May be just function for cookies, and let the user manage session. That could be very simple.

craff avatar Dec 09 '21 02:12 craff

PR #38 should be enough for now

craff avatar Dec 20 '21 16:12 craff

You may close this too.

craff avatar Jan 18 '23 07:01 craff