DEV Community

Cover image for Building a Web server in Bash, part III - Login

Building a Web server in Bash, part III - Login

Leandro Proença on August 01, 2022

In the previous posts we've seen how to manipulate sockets using netcat. Moreover, we learned how to start reading and parsing an HTTP message usin...
Collapse
 
learnitmyway profile image
David

Thanks for the great article. One thing I didn't understand is: Where does home.html parse {{name}} from?

Collapse
 
leandronsp profile image
Leandro Proença

Using sed:

  RESPONSE=$(cat home.html | \
    sed "s/{{$COOKIE_NAME}}/$COOKIE_VALUE/")
Enter fullscreen mode Exit fullscreen mode

Did I answer your question?

Collapse
 
learnitmyway profile image
David • Edited

Thanks for the reply. Not quite. shouldn't there be a name= somewhere?

Collapse
 
maclong profile image
Mac

Informative post!

I will let you know, you define the function as handleRequest however in one call of it you misname it: cat response | nc -lN 3000 | processRequest

Collapse
 
t0mas profile image
Tomas

Seems Part III is broken. Page shows "Liquid syntax error: Unknown tag 'endraw' "

Collapse
 
leandronsp profile image
Leandro Proença

thanks, it might be a platform issue, I edited then just saved the post. seems working now

Collapse
 
mhotwagner profile image
Michael Hotwagner

Just want to give big thanks for this awesome post. Seriously great stuff!

Collapse
 
64j0 profile image
Vinícius Gajo

The cat trick does not work for me. When I try to understand what is happening in Chrome DevTools it shows me this:

Image description

Apparently the server is not able to parse correctly the HTML file. Did you have this problem before?

Collapse
 
leandronsp profile image
Leandro Proença

never seen this before. maybe OS issue? netcat implementation issue?

anyway, try using \n instead of \r\n

Collapse
 
64j0 profile image
Vinícius Gajo

Maybe the problem is the OS or the IDE I'm using (Emacs). I tried setting explicitly the \r\n but it did not work either. But, it worked after I set the headers in the string, and just cat the HTML content, like this:

RESPONSE="HTTP/1.1 200 OK\r\nContent-Type: text/html\r\n\r\n$(cat html/home.html)"
Enter fullscreen mode Exit fullscreen mode
Thread Thread
 
leandronsp profile image
Leandro Proença

good catch! yes, unfortunately when dealing with stuff low-level we may face OS/tools implementations issues

Collapse
 
aaronngray profile image
Aaron Gray

Hi, can you wrap it all up in a github repo please if you have not done so already ?