http server v0.1_http_reponse.c
#include <string.h>
#include <sys/stat.h>
#include <sys/mman.h>
#include <fcntl.h>
#include <unistd.h>
#include <stdio.h> #include "mime.h"
#include "http_common.h"
#include "http_webapp.h"
static STR_STATUS_MAP resp_map[]={HTTP_STATUS_MAP(HTTP_MAP_GEN)}; /*---------------------------------------------------------------------------- -----------------------------------------------------------------------------*/
int get_response_head(EN_REP_STATUS status, EN_MIME_TYPE type, char* resp_head, int content_len)
{
int stat_len = ;
char* point = NULL;
char* content_type = NULL;
char lenstr[]; if(resp_head == NULL)
return -; if(status > HTTP_END || status < )
return -; point = resp_head;
// response status
stat_len = strlen(resp_map[status].head);
strncpy(point, resp_map[status].head, stat_len);
// server version
strcat(point, HTTP_RESP_HEAD_SERVER);
// content type
content_type = get_resp_type(type);
strcat(point, HTTP_RESP_HEAD_CONTENT_TYPE);
strcat(point, content_type);
// content length
strcat(point, HTTP_RESP_HEAD_CONTENT_LENGTH);
bzero(lenstr, sizeof(lenstr));
strcat(point, itoa(content_len,lenstr,));
// head end
strncat(point, "\r\n\r\n", );
return ;
} int get_response_body(EN_MIME_TYPE type, void* body, char* uri, long len)
{
int fd = ;
void* bodybuf = NULL;
if(body == NULL || uri == NULL)
return -; if(len == )
return ; if(type == HTTP_ELSE)
return -; fd = open(uri, O_RDONLY, );
if(fd == -)
{
close(fd);
return -;
}
// virsual memory map
bodybuf = mmap(, len, PROT_READ, MAP_PRIVATE, fd, );
memcpy(body, bodybuf, len);
munmap(bodybuf, len);
close(fd);
return ;
}
http server v0.1_http_reponse.c的更多相关文章
- http server v0.1_http_server.c
/**************************************************************** filename: http_server.c author: xx ...
- http server v0.1_http_parse.c
#include <stdio.h> #include <string.h> #include <stdlib.h> #include "mime.h&q ...
- http server v0.1_http_webapp.c
#include <stdio.h> #include <stdlib.h> #include <string.h> #include <unistd.h&g ...
- http server v0.1_mime.c
#include <string.h> #include "mime.h" static STR_MIME_MAP mime_map[]= { MIME_MAP(MIM ...
- 用FileZilla Server开FTP
FileZilla(教程)是经典的开源FTP解决方案,包括FileZilla客户端和FileZilla Server.其中,FileZilla Server的功能比起商业软件FTP Serv-U毫不逊 ...
- DNS隧道之DNS2TCP实现——dns2tcpc必须带server IP才可以,此外ssh可以穿过墙的,设置代理上网
我自己的命令: server端: dns2tcpd -F -d 1 -f ./dns2tcpd.conf 输出: 09:08:59 : Debug options.c:97 Add resource ...
- docker 下 安装rancher 笔记
sudo yum update 更新系统环境 curl -sSL https://get.docker.com/ | sh 安装最新docker版本 systemctl start docker.se ...
- 容器基础(七): 使用docker compose部署程序
配置 在上一节的基础上, 增加如下的docker-compose.yml文件, 然后用docker-compose up命令启动容器进行部署: version: " services: s ...
- 容器基础(八): 使用docker swarm部署程序
环境 基于上一节的env/server:v0.1, env/worker:v0.1镜像, 在基于debian8.2的两台机器上测试部署docker swarm. docker service部署 ➜ ...
随机推荐
- Introspector(内省)简单演示样例 与 简单应用
简单演示样例: package com.asdfLeftHand.test; import java.beans.BeanDescriptor; import java.beans.BeanInfo; ...
- Android将Activity打成jar包供第三方调用(解决资源文件不能打包的问题)
转载地址:http://blog.csdn.net/xiaanming/article/details/9257853 最近有一个需要,我们公司做了一个apk客户端,然后其他的公司可以根据自己的需要来 ...
- ccrendertexture
int bgHeight=150; CCSprite *sp=CCSprite::create("HelloWorld.png"); sp->setAnchorPoint(c ...
- 基于keepalived对redis做高可用配置---转载
关于keepalived的详细介绍,请移步本人相关博客:http://wangfeng7399.blog.51cto.com/3518031/1405785 功能 ip地址 安装软件 主redis 1 ...
- NodeJs读取源代码使用的字符集
今天用NodeJs写了个简单的客户端/服务器程序,并让客户端向服务器发送汉字.当在Windows上执行客户端时,发现服务器端打印的接收到的数据是乱码.后来发现Windows上的客户端文件的储存编码方案 ...
- Freemarker学习中遇到的问题
在网上找到了尚学堂的视频,同时有书和源码等资料.但是在跟着练习的过程中,代码运行报了错: 2015-7-20 22:26:40 freemarker.log.JDK14LoggerFactory$JD ...
- 也谈android开发图像压缩
long long ago,给学院做的一个通讯录App需要有一个上传图像的功能,冥思苦想,绞尽脑汁后来还是没解决(学生时代的事),于是就直接上传原图了,一张图片2M到3M,这样我的应用发布之后,那绝对 ...
- web服务构架
以我的理解大流量电商网站,一般构架如下: CDN 负载均衡集群 < === > 缓存服务器集群 反向代理服务器集群 web服务器集群(日志采集) < === > 缓存系统集群 ...
- sql like '%x%'优化
好久没写点什么了.唉(此处省略无数,一切尽在苦逼中...) 说说sql中的全匹配优化吧.在sql server进行模糊查询的时候,如果是进行全匹配的话,那么肯定会用到like.我们知道like '%张 ...
- MyTask4
最近稍微做了点修改,把几处bug修复了下,另外新增了授权码功能和数据缓冲功能 先看看效果图 1. 如果要把软件做的高大上一些,你可以加一个授权验证,授权码以字符串形式存放在程序里面,当然你也可以另外开 ...