benrady / shinatra

A simple web server in 5 lines of bash
811 stars 81 forks source link

Page is served when the server is stopped! #19

Open stupidly-logical opened 4 years ago

stupidly-logical commented 4 years ago

When I run it like:

./shinatra.sh 8080 index.html

the page keeps loading. As soon as I terminate it with Ctrl+C, the content is served. Is this the intended behaviour?

shrinidhi111 commented 4 years ago

Same issue here..

After I start the server and open the page in Firefox, it keeps loading forever. But as soon as I CTRL+C the server, the response loads.

benrady commented 4 years ago

I was able to reproduce this problem as well.

bendem commented 3 years ago

That would be the keepalive setting. You really want to close the connection after sending the response to have a consistent behavior in browsers:

     -N      shutdown(2) the network socket after EOF on the input.  Some servers require this to finish their work.
while nc -Nl 8082 <<< 'HTTP/1.1 200 OK
Connection: close
Content-Type: text/plain

OK'; do ; done

see #16

benrady commented 3 years ago

That makes sense, but removing the Connection: keep-alive does not seem to fix the issue (at least, in the browsers I've tried).

On Thu, Aug 20, 2020 at 8:12 AM bendem notifications@github.com wrote:

That would be the keepalive setting. You really want to close the connection after sending the response to have a consistent behavior in browsers:

while nc -Nl 8082 <<< 'HTTP/1.1 200 OKContent-Type: text/plainOK'; do ; done

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/benrady/shinatra/issues/19#issuecomment-677656208, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAAN4YHC4NLYKTJS7EKMF3TSBUOMJANCNFSM4I3RO3GA .

-- Ben

bendem commented 3 years ago

You should set it to close, not remove it. Otherwise it means you are accepting the browser's setting which is keep-alive.

bendem commented 3 years ago

Sorry, I realise I had removed it in my example, added it back.

janglapuk commented 2 years ago

Replace nc with ncat from NMAP package should work even in keep-alive or close connection mode.

JeremyLARDENOIS commented 2 years ago

like it #23 ?

janglapuk commented 2 years ago

like it #23 ?

ncat still needs p or --source-port argument to define the port.

JeremyLARDENOIS commented 2 years ago

No, you can give a port without the argument cause ncat take ports in parameter already