How does klipper set up the web server?

I have seen the code of the klipper. But I still don't understand how klipper makes use of octoprint to set up a web server.

I don't think it does inherently. There is a klipper plugin for octoprint, and seems someone has created a web interface that mimics the duet wifi interface.

You may have a look on this: