Coder Social home page Coder Social logo

impl-http-protocol's Introduction

实现 http 服务

总结

这个项目使用 Node.js 的 net 模块中的 tcp 服务器,实现了一个可以处理 http 协议的服务器。

为了实现该服务需要构建一个 tcp 服务,使其能够按照 http 协议理解报文。

请求报文格式

响应报文格式

所以我们需要按照上边的报文格式去理解请求什么以及我该如何给他返回数据。

在我们收到 http 请求报文时,需要把他解析成人类友好的格式,并将原始 socket 保留,以便向他返回响应报文,浏览器收到响应后,也需要按照Http响应报文的格式去解读.

缺点:Ts 类型还不太会写,在请求对象和响应对象上的各函数做了简化

额外补充:

在 Node.js 中,各服务有以下的对应

  • net -> tcp 服务
  • dgram -> udp 服务
  • http -> http 服务
  • https -> https 服务

impl-http-protocol's People

Contributors

liumingxun avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.