Skip to content

itsjoeoui/httpfromtcp

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

54 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

httpfromtcp

A simple HTTP server implementing the HTTP/1.1 spec

Setup

Make sure you have Go and just installed.

Then, run the following command in the project's root folder to set things up:

just setup

You can find some example handlers in cmd/httpserver/handlers, and they are wired up in cmd/httpserver/main.go (all the routes are here!).

To run it, simply execute:

just run

Then try sending a request to http://127.0.0.1:42069/!

More routes are available, such as:

func handler(w *response.Writer, r *request.Request) {
  switch {
  case strings.HasPrefix(r.RequestLine.RequestTarget, "/yourproblem"):
    handlers.Handler400(w, r)
  case strings.HasPrefix(r.RequestLine.RequestTarget, "/myproblem"):
    handlers.Handler500(w, r)
  case strings.HasPrefix(r.RequestLine.RequestTarget, "/video"):
    handlers.HandlerVideo(w, r)
  case strings.HasPrefix(r.RequestLine.RequestTarget, "/httpbin"):
    handlers.HandlerHTTPBin(w, r)
  default:
    handlers.Handler200(w, r)
  }
}

References

About

A simple HTTP server implementing the HTTP/1.1 spec

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published