Let's build a simple HTTP server with Ruby
summary
Code builds a working but minimal HTTP server in Ruby using the stdlib Socket class it binds to port 5000 accepts connections with TCPServer reads full requests via readpartial parses the request line and headers into a hash serves files from a server root and even executes an executable .rb file the implementation returns 200 or 404 as plain HTTP strings is explicitly non spec compliant and remains vulnerable to path traversal attack so use Socket class for learning and Rack for production.
AI-written summary · about
chapters (16)
- 0:00Introduction
- 0:48About me
- 2:00What is the Internet
- 3:30What is HTTP
- 4:27HTTP specification
- 5:30URL syntax
- 9:40Socket
- 11:54Server
- 18:15Send response
- 19:24Respond with
- 21:36Response class
- 27:14Demo
- 28:10Execute a Ruby file
- 28:43Modify the response parser
- 30:43Missing features
- 31:18Path traversal attack
related talks
36mThe Little Server That Could
35mThe little server that could
26mTCP Sockets Programming in Ruby
18mThere is no Magic: Write your own HTTP server, and then stop
36mBuilding a Ruby web app using the Ruby Standard Library
31mFrom Rails to the Web Server to the Browser
29mRuby Systems Programming
44mOutside the Web Box: Using Ruby for Other Protocols
