girassol-rb / girassol

A non-opnionated HTTP server in ruby
MIT License
14 stars 3 forks source link

Socket programming #2

Open jeffque opened 1 year ago

jeffque commented 1 year ago

Each requisition must be handled in a fiber/thread

also, must check if expect: 100-continue and pass it for a expectation_handler function

jeffque commented 1 year ago

Accetance test for requisition being handled in different threads or the like:

payload_size=1024
payload1=`tr -dc A-Za-z0-9 </dev/urandom | head -c 1024; echo ''`
payload2=`tr -dc A-Za-z0-9 </dev/urandom | head -c 1024; echo ''`

rm .req1 .req2

# assuming socker in port 3000 and locale using . as decimal separator

curl localhost:3000 --connect-timeout 0.05 -d "$payload1" --silent && touch .req1 &
curl localhost:3000 --connect-timeout 0.05 -d "$payload2" --silent && touch .req2

if [ -f .req1 ] && [ -f .req1 ]; then
  echo ok
else
  echo fail
fi

Also, server must be running after these commands

EronAlves1996 commented 1 year ago

Adding here the RFC reference for the correct expected behavior in this situation:

RFC 4231

It requires #3 as a rudimentar parsing.

We should observe this particular snippet from the RFC on 5.1.1 section:

A 100-continue expectation informs recipients that the client is about to send a (presumably large) message body in this request and wishes to receive a 100 (Continue) interim response if the request-line and header fields are not sufficient to cause an immediate success, redirect, or error response.

That way, I think it fills most suitably for data upload.

jeffque commented 1 year ago

@EronAlves1996 , so, we can add a handler to be fired when meeting said header. It will receive method, path , qry and partial headers.

If no handler supplied, default would be to just write 100 continue in socket.

Makes sense?

jeffque commented 1 year ago

If such interception is possible, shall we add more interceptors possibility ?

Like, given this header, fire this action? As koa, the handler shall receive a context.

EronAlves1996 commented 1 year ago

@EronAlves1996 , so, we can add a handler to be fired when meeting said header. It will receive method, path , qry and partial headers.

If no handler supplied, default would be to just write 100 continue in socket.

Makes sense?

Yep, I think it makes sense,

I think the interceptors can be added incrementally. Control them with issues maybe?