Skip to content

Anita-Mul/HTTP-Server

Repository files navigation

HTTPServer

使用 Nodejs 编写,基于RESTful约定的 HTTPServer,目前支持:

  • 请求:GET、POST、PUT、DELETE、OPTIONS ✨
  • 状态码:200 201 206 304 400 401 403 404 500 ✨
  • 头部:If-None-Match、Content-Length、Range、Cookie、Authorization、Cache-Control、If-None-Match、Content-Range、WWW-Authenticate、Last-Modified、Access-Control-Allow-Origin、Access-Control-Allow-Method、Access-Control-Allow-Credential ✨
  • HTTP 鉴权(Session 和 Cookie)✨
  • 浏览器跨域访问 ✨
  • 浏览器缓存控制 ✨

Usage

启动

node main.js

测试用户身份验证

  • 用户名:admin
  • 密码:123456

在这里插入图片描述

测试 CORS 请求

  • 💙 在本地配置主机和IP地址的映射

在这里插入图片描述

  • 💛 修改 www/a.html 文件中请求方法为 GET
    xhr.open('GET', 'http://b.com/test.txt', true);
  • 💜 打开 http://a.com/a.html

在这里插入图片描述

测试 CORS 预检请求

  • 💙 修改 www/a.html 文件中请求方法为 PUT

    xhr.open('PUT', 'http://b.com/test.txt', true);
  • 💚 打开 http://a.com/a.html

    在这里插入图片描述

测试 GET 请求

  • 💚 访问 http://localhost/

在这里插入图片描述

  • 💛 访问 http://localhost/test.txt

    在这里插入图片描述

  • 💜 访问 http://localhost/test.txt,添加头部Range: bytes=1-2

    在这里插入图片描述

  • 💙 访问 http://localhost/hello.txt

在这里插入图片描述

测试 POST 请求

  • 💛 创建一个文件 http://localhost:80/Cat.txt

在这里插入图片描述

  • 💚 若再次创建相同文件 http://localhost:80/Cat.txt

在这里插入图片描述

  • 💙 如果存在相对路径

在这里插入图片描述

测试 PUT 请求

  • 💛 修改 Cat.txt 文件内容 http://localhost:80/Cat.txt

测试 DELETE 请求

  • 💜 删除 Cat.txt 文件 http://localhost:80/Cat.txt

测试缓存控制

  • 💚 第一次访问http://localhost/test.txt

在这里插入图片描述

  • 💙 第二次访问http://localhost/test.txt

在这里插入图片描述

About

【HTTP Server】Nodejs

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published