当前位置: 首页 > news >正文

做企业平台的网站有哪些内容代发百度关键词排名

做企业平台的网站有哪些内容,代发百度关键词排名,有没有做公务员题的网站,广告公司宣传册此模块将网络通信模块和业务处理模块进行了合并 网络通信通过httplib库搭建完成业务处理: 文件上传请求:备份客户端上传的文件,响应上传成功客户端列表请求:客户端请求备份文件的请求页面,服务器响应文件下载请求&…

此模块将网络通信模块和业务处理模块进行了合并

  1. 网络通信通过httplib库搭建完成
  2. 业务处理:
    • 文件上传请求:备份客户端上传的文件,响应上传成功
    • 客户端列表请求:客户端请求备份文件的请求页面,服务器响应
    • 文件下载请求:通过展示的文件列表,点击下载,服务器响应下载的文件数据

文章目录

  • 1. 网络通信模块设计
  • 2. 业务处理模块设计
    • 文件上传业务处理 /upload请求
    • 展示备份文件页面 / /listshow请求
    • 文件下载业务处理 /download
      • 断点续传原理:
  • 3. 服务器代码:
  • 4. 代码位置

1. 网络通信模块设计

文件下载Http请求部分如下:通过分隔符可以取到文件数据和文件的其他信息,文件信息和文件内容之间空行隔开。这个解析过程httplib库已经封装完毕
在这里插入图片描述

网络通信请求设计:

  1. 文件上传:服务器收到/upload 是为文件上传
  2. 展示页面:服务器收到/listshow是服务器所有备份文件展示
    响应 HTTP/1.1 200 OK + 构造html正文界面
  3. 文件下载:服务器收到/download/文件名 为文件下载请求
    响应 HTTP/1.1 200 OK +文件数据(正文)

2. 业务处理模块设计

文件上传业务处理 /upload请求

#pragma once
#include "backups.hpp"
#include "./httplib/httplib.h"
#include "./config/config.hpp"
extern CloudBackups::DataMange *dataMange;
namespace CloudBackups
{class Server{private:int port;std::string ip;std::string download_prefix;httplib::Server server;// 上传文件static void Upload(const httplib::Request &request, httplib::Response &response){LOG(INFO, "upload begin");// POST请求,文件数据在http正文中,分区存储bool ret = request.has_file("file"); // 判断有无上传文件字段if (ret == false){LOG(ERROR, "request error!");response.status = 400;return;}// 获取数据const auto &file = request.get_file_value("file");std::string backdir = Config::GetInstance()->GetBackDir();// 保存文件std::string filepath = backdir + FileUtil(file.filename).filename(); // 实际路径+文件名FileUtil stream(filepath);stream.setContent(file.content);// 更新文件信息Json文件BackupInfo info(filepath);dataMange->Insert(info);LOG(INFO, "upload success");}// 展示页面static void ListShow(const httplib::Request &request, httplib::Response &response){}// 下载文件static void Download(const httplib::Request &request, httplib::Response &response){}public:Server(){Config *config = Config::GetInstance();port = config->GetServerPort();ip = config->GetServerIp();download_prefix = config->GetDownloadPrefix();LOG(INFO, "init server success");}bool RunMoudle(){LOG(INFO, "server running");// 搭建Http服务器server.Post("/upload", Upload); // 文件上传server.Get("/list", ListShow);  // 展示页面server.Get("/", ListShow);      // 网页根目录也是展示页面std::string download_url = download_prefix + "(.*)";server.Get(download_url, Download); // 下载文件,正则表达式捕捉要下载的文件if (server.listen(ip, port) == false){LOG(FATAL, "server listen failed! ip=" + ip);return false;}return true;}};
}

单元测试运行截图

// #include "util/fileutil.hpp"
#include <vector>
#include "util/json.hpp"
#include "config/config.hpp"
#include "backups.hpp"
#include "hot.hpp"
#include "server.hpp"
CloudBackups::DataMange *dataMange;
void ServerUtilTest()
{CloudBackups::Server server;dataMange = new CloudBackups::DataMange();server.RunMoudle();
}
int main(int argc, char const *argv[])
{ServerUtilTest();return 0;
}

在这里插入图片描述
上传文件的信息Json如下:
在这里插入图片描述

展示备份文件页面 / /listshow请求

#pragma once
#include "backups.hpp"
#include "./httplib/httplib.h"
#include "./config/config.hpp"
extern CloudBackups::DataMange *dataMange;
namespace CloudBackups
{class Server{private:int port;std::string ip;std::string download_prefix;httplib::Server server;// 上传文件static void Upload(const httplib::Request &request, httplib::Response &response){}// 展示页面static void ListShow(const httplib::Request &request, httplib::Response &response){LOG(INFO, "list show begin");// 获取所有文件信息std::vector<BackupInfo> array;dataMange->GetAll(array);// 根据所有文件信息构建http响应std::stringstream ss;ss << R"(<!DOCTYPE html><html lang="cn"><head><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><title>download list</title></head><body>)";ss << R"(<h1 align="center">Download List</h1>)";for (auto &info : array){std::string filename = FileUtil(info.real_path).filename();ss << R"(<tr><td><a href=")" << info.url << R"(">)" << filename << "</a></td>";ss << R"(<td align="right"> )" << convertTimeStamp2TimeStr(info.mtime) << "  </td>";ss << R"(<td align="right">)" << info.size / 1024 << "Kb</td></tr>";ss << "<br>";}ss << "</body></html>";response.body = ss.str();response.set_header("Content-Type", "text/html");response.status = 200;LOG(INFO, "list show end");}// 下载文件static void Download(const httplib::Request &request, httplib::Response &response){}public:Server(){Config *config = Config::GetInstance();port = config->GetServerPort();ip = config->GetServerIp();download_prefix = config->GetDownloadPrefix();LOG(INFO, "init server success");}bool RunMoudle(){LOG(INFO, "server running");// 搭建Http服务器server.Post("/upload", Upload); // 文件上传server.Get("/list", ListShow);  // 展示页面server.Get("/", ListShow);      // 网页根目录也是展示页面std::string download_url = download_prefix + "(.*)";server.Get(download_url, Download); // 下载文件,正则表达式捕捉要下载的文件if (server.listen(ip, port) == false){LOG(FATAL, "server listen failed! ip=" + ip);return false;}return true;}};
}

在这里插入图片描述
在这里插入图片描述

文件下载业务处理 /download

http的ETag头部字段:存储了一个资源的唯一标识

客户端第一次请求文件时会收到响应信息。

客户端第二次下载时,客户端会把这个信息发送给服务器,让这个服务器根据这个标识判断这个资源有没有被修改锅。如果没修改过。客户端直接使用缓存区的资源。如果改过则重新修改

http对ETag字段没有定义,这里设定:
ETags:文件名称-文件大小-最后修改时间 构成

ETags字段也用于断点续传,断点续传也需要保证文件没有被修改

http协议的Accept-Ranges:bytes字段用于表示支持断点续传。数据以字节结尾

Content-Type:字段决定了浏览器如何处理响应正文,用来区分下载还是html显示。
Content-Type:application/octet-stream常用于文件下载

断点续传原理:

文件下载时由于异常而中断,如果从头下载效率较低,需要将之前传输过的数据效率太低。断点续传的目的为了提高上传效率

实现:客户端在下载时需要记录当前下载的位置。当下载中断时,下次断点续传时将下载起始位置发送给服务器。服务器收到后仅仅回传客户端需要的数据即可

如果下载文件后这个文件在服务器上被修改了,这时候需要将文件重新下载

http中断点续传关键点在于告诉服务器下载区间范围,服务器上要检测这个文件是否被修改。
http协议的Accept-Ranges:bytes字段用于表示支持断点续传
ETag文件唯一标识符,客户端收到响应会保存这个信息

请求:

GET /download/test.txt HTTP/1.1
If-Range:“服务端在下载时响应ETag字段搭配使用判断文件是否被修改,常用于恢复下载”
Range: bytes=100-200(区间范围) 这个字段用来告诉客户端需要的数据范围

响应:

HTTP/1.1 206(服务器处理部分get请求) Paritial Content
ETag:”xxxx“(响应资源的版本标识符,判断文件是否被修改)
Content-Range: bytes 100-200(范围)
Accept-Ranges: bytes 字段用于表示支持断点续传

正文就是对应区间的数据

真正实现时:cpp-httplib会自动根据请求Range字段对response.body进行切片返回,封装实现。直接把response.body全部设置为文件所有内容即可

#pragma once
#include "backups.hpp"
#include "../httplib/httplib.h"
#include "../config/config.hpp"
extern CloudBackups::DataMange *dataMange;
namespace CloudBackups
{class Server{private:int port;std::string ip;std::string download_prefix;httplib::Server server;// ETag为设计者自行指定 ETags:文件名称-文件大小-最后修改时间 构成static std::string GetETag(BackupInfo info){std::string etag = FileUtil(info.real_path).filename();etag += "-";etag += std::to_string(info.size);etag += "-";etag += std::to_string(info.mtime);return etag;}// 下载文件static void Download(const httplib::Request &request, httplib::Response &response){// 1. 获取客户端请求资源的路径 request.path// 2. 根据路径获取文件备份信息BackupInfo info;if (dataMange->GetByUrl(request.path, info) == false){LOG(WARNING, "file /download not found");response.status = 404;return;}// 3. 判断文件是否被压缩,被压缩的话需要先解压缩,删除压缩包,修改备份信息if (info.packflag == true){// 被压缩,解压到backdir目录浏览FileUtil tool(info.pack_path);tool.unzip(info.real_path);// 删除压缩包tool.removeFile();info.packflag = false;// 修改配置文件dataMange->UpDate(info);}//  4. 读取文件数据放入body中FileUtil tool(info.real_path);tool.getContent(response.body);// 判断断点续传bool retrans = false; // 标记断点续传std::string befetag;if (request.has_header("If-Range")){// 断点续传 服务端在下载时响应ETag字段搭配使用判断文件是否被修改befetag = request.get_header_value("If-Range");if (befetag == GetETag(info)){// 文件没修改过retrans = true;}}// 没有If-Range字段或者If-Range字段与ETag不匹配,重新下载if (retrans == false){// 正常下载//  5. 设置响应头部字段ETag Accept-Range字段response.set_header("ETag", GetETag(info));response.set_header("Accept-Ranges", "bytes");response.set_header("Content-Type", "application/octet-stream");response.status = 200;}else{// 断点续传,了解区间范围response.set_header("ETag", GetETag(info));response.set_header("Accept-Ranges", "bytes");response.status = 206; // cpp-httplib会自动根据请求Range字段对response.body进行切片返回,封装实现}LOG(INFO, "download success");}public:Server(){Config *config = Config::GetInstance();port = config->GetServerPort();ip = config->GetServerIp();download_prefix = config->GetDownloadPrefix();// 创建文件夹FileUtil tool;tool.mkdir(Config::GetInstance()->GetBackDir());tool.mkdir(Config::GetInstance()->GetPackfileDir());LOG(INFO, "init server success");}bool RunMoudle(){LOG(INFO, "server running");// 搭建Http服务器server.Post("/upload", Upload); // 文件上传server.Get("/list", ListShow);  // 展示页面server.Get("/", ListShow);      // 网页根目录也是展示页面std::string download_url = download_prefix + "(.*)";// LOG(INFO, "DEBUG:" + download_url);server.Get(download_url, Download); // 下载文件,正则表达式捕捉要下载的文件if (server.listen(ip, port) == false){LOG(FATAL, "server listen failed! ip=" + ip);return false;}return true;}};
}

3. 服务器代码:

#include <vector>
#include "../util/json.hpp"
#include "../config/config.hpp"
#include "backups.hpp"
#include "hot.hpp"
#include "server.hpp"
#include <thread>
CloudBackups::DataMange *dataMange;
void ServerRun()
{CloudBackups::Server server;dataMange = new CloudBackups::DataMange();server.RunMoudle();
}
void HotRun()
{dataMange = new CloudBackups::DataMange();CloudBackups::HotMange hot;hot.RunModule();
}
int main(int argc, char const *argv[])
{// 启动热点管理模块std::thread hot_thread(HotRun);std::thread server_thread(ServerRun);hot_thread.join();server_thread.join();return 0;
}

4. 代码位置

至此,项目服务器所有业务处理完毕
Gitee
Github


文章转载自:
http://puggaree.stph.cn
http://sycamore.stph.cn
http://palinode.stph.cn
http://toothache.stph.cn
http://sweetbriar.stph.cn
http://ailing.stph.cn
http://dehumanization.stph.cn
http://schnook.stph.cn
http://unrestraint.stph.cn
http://ablation.stph.cn
http://brinded.stph.cn
http://tech.stph.cn
http://malmaison.stph.cn
http://attendant.stph.cn
http://creatinine.stph.cn
http://bollocks.stph.cn
http://respirability.stph.cn
http://microparasite.stph.cn
http://jeunesse.stph.cn
http://hurrah.stph.cn
http://veridically.stph.cn
http://flapper.stph.cn
http://lampblack.stph.cn
http://intact.stph.cn
http://geranial.stph.cn
http://bitcasting.stph.cn
http://paleofauna.stph.cn
http://peptide.stph.cn
http://gardner.stph.cn
http://tetramorph.stph.cn
http://marathonian.stph.cn
http://vulcanism.stph.cn
http://vandal.stph.cn
http://allies.stph.cn
http://passingly.stph.cn
http://optimism.stph.cn
http://aerolitics.stph.cn
http://botargo.stph.cn
http://brachycranic.stph.cn
http://british.stph.cn
http://gallicism.stph.cn
http://entoptoscope.stph.cn
http://leady.stph.cn
http://submetallic.stph.cn
http://contemporaneous.stph.cn
http://plague.stph.cn
http://hiplength.stph.cn
http://jun.stph.cn
http://attorneyship.stph.cn
http://counterconditioning.stph.cn
http://trigon.stph.cn
http://pullus.stph.cn
http://intermittence.stph.cn
http://mescalero.stph.cn
http://tubercula.stph.cn
http://chronobiology.stph.cn
http://cenozoology.stph.cn
http://jellyfish.stph.cn
http://variegated.stph.cn
http://romany.stph.cn
http://polavision.stph.cn
http://countship.stph.cn
http://barbasco.stph.cn
http://dibranchiate.stph.cn
http://levis.stph.cn
http://aeolipile.stph.cn
http://machineable.stph.cn
http://pomeranian.stph.cn
http://abdomino.stph.cn
http://pichiciago.stph.cn
http://wystan.stph.cn
http://shortsighted.stph.cn
http://cantonalism.stph.cn
http://bacteriocin.stph.cn
http://buttonholder.stph.cn
http://roadster.stph.cn
http://exhume.stph.cn
http://enantiomorph.stph.cn
http://syntomycin.stph.cn
http://manama.stph.cn
http://crushable.stph.cn
http://cattegat.stph.cn
http://milquetoast.stph.cn
http://boating.stph.cn
http://npf.stph.cn
http://soothingly.stph.cn
http://communization.stph.cn
http://hypnotist.stph.cn
http://larrigan.stph.cn
http://defogger.stph.cn
http://firehouse.stph.cn
http://ethyl.stph.cn
http://paleolatitude.stph.cn
http://reddleman.stph.cn
http://swan.stph.cn
http://horsewoman.stph.cn
http://centrepiece.stph.cn
http://strix.stph.cn
http://atmospherically.stph.cn
http://arminian.stph.cn
http://www.15wanjia.com/news/86188.html

相关文章:

  • wordpress段落间距搜索引擎环境优化
  • 官网大全seo实战技术培训
  • 如何跟帖做网站百度推广技巧
  • 哪些网站做代理安全又舒适的避孕方法有哪些
  • 车牌照损坏在网站做的能用吗百度seo关键词排名s
  • asp做的网站刚刚发生了一件大事
  • wordpress上卖什么用重庆seowhy整站优化
  • 工厂型企业做网站网络广告投放方案
  • 怎样做私人时时彩网站张家界网站seo
  • 网站制作开发 杭州关键词搜索排名推广
  • 做淘宝客网站一定要备案吗女生做sem还是seo
  • 杭州定制网站制作网站推广排名公司
  • 网络建站优化科技南京seo排名扣费
  • 搬家网站怎么做落实好疫情防控优化措施
  • 做外贸批发开什么网站免费b站推广网站详情
  • 网站收藏代码公众号免费推广平台
  • 北海做网站的网络公司16种营销模型
  • 政府网站建设 论文app开发软件
  • 多个链接的网站怎么做的百度网站禁止访问怎么解除
  • 30个让人兴奋的视差滚动网站百度导航下载2021最新版
  • 张向东深圳优化怎么做搜索
  • 动漫制作技术主要学什么哈尔滨seo优化培训
  • 中国建设部门官方网站厦门seo关键词优化代运营
  • 中国b2c有哪些电商平台优化营商环境指什么
  • wordpress定制企业站中国疫情最新数据
  • 网页设计班级网站怎么做策划公司是做什么的
  • 临沂百度网站成都全网营销推广
  • 个人电脑做网站长沙百度提升排名
  • 网站首页模块如何做链接上海网站推广服务公司
  • 成都网站制作seo这个职位是干什么的