源码分析-简洁的HTTPServer-tinyhttpd

tinyhttpd编译执行 源文件下载地址:https://sourceforge.net/projects/tinyhttpd/1.解压压缩文件 tar -zxvf tinyhttpd-0.1.0.tar.gz2.进入文件目录 cd tinyhttpd-0.1.0修改htdocs文件夹里面.cgi文件因为cgi文件是用perl写的,我这里perl的位置是/usr/bin/perl所以打开.cgi文件第一句改为 #!/usr... 阅读详情

源码分析-简洁的HTTPServer

second60  20180610

1. tinyhttpd 简介

tinyhttpd 可以说是最小最精简的HTTP服务器,C语言编写,全部代码只有五百多行。通过阅读tinyhttpd源码可以了解HTTP服务器搭建的本质和HTTP基础。

下载链接:http://sourceforge.net/projects/tinyhttpd/

2. tinyhttpd 安装和使用

httpd编译: make

在编译时,如果报错,在makefile中注释-lsocket.(源码开头注释)

 

httpd运行: ./httpd

simpleclient编译: gcc  simpleclient.c  -o  simpleclient

simpleclient运行: ./simpleclient

此程序中的端口是随机生成的,可以在练习时,固定好一个端口,或修改成命令行传入。

3. tinyhttpd 流程

1) 创建服务器套接字,如果端口为0,随机生成一个端口,startup

2) 套接字绑定并监听startup

3) 如果有客户端连接,单独开启一个线程来处理客户端请求accept_request

a) 获取客户端数据

b) 分析客户端请求数据:GET/POST/query_string/path等

c) 非cgi,执行serve_file,读取文件并返回给客户端(非脚本文件)

d) cgi存在执行execute_cgi(脚本文件)

 

4. http 原理

4.1 HTTP协议流程

1.用户在浏览器中键入需要访问网页的URL或者点击某个网页中链接;
2.浏览器根据URL中的域名,通过DNS解析出目标网页的IP地址;
3.浏览器与网页所在服务器建立TCP连接;
4.浏览器发送HTTP请求报文,获取目标网页的文件;
5.服务器发送HTTP响应报文,将目标网页文件发送给浏览器;
6.释放TCP连接;
7.浏览器将网页的内容包括文本、图像、声音等显示呈现在用户计算机屏幕。

4.2 HTTP请求报文格式

HTTP请求报文的由请求行、请求头部行、空行和请求数据四部分构成,具体格式如下所示:

(请求行)方法名+空格+URL+空格+版本+回车换行(\r\n)
(请求头部行1)关键字+“:”+空格+值+回车换行(\r\n)
...
(请求头部行N)关键字+“:”+空格+值+回车换行(\r\n)
(空行)回车换行(\r\n)
(请求数据)……

4.2.1 请求行

请求行由请求方法字段、URL字段和HTTP协议版本字段3个字段组成,它们用空格分隔。最后由回车和换行表示请求行结束。

例如: GET  www.sdu.edu.cn  HTTP/1.1 回车换行(\r\n)

 

HTTP请求报文的主要方法包括:

GET

 

 

POST

 

 

HEAD

 

 

PUT

 

 

DELETE

 

 

OPTIONS

 

 

TRACE

 

 

CONNECT

 

 


4.2.2 请求头部行(header)

请求头部行包括若干行,每行由关键字及其值构成的,关键字和值用英文冒号“:”分隔,每一行都由回车换行表示结束。

 

请求头部通知服务器有关于客户端请求的信息,典型的请求头部关键字有:

User-Agent

产生请求的浏览器类型

 

Accept

客户端可识别的内容类型列表

 

Accept-Language

客户端可识别的语言类型

 

Host

请求的主机名

 

Connection

告知服务器发送完文档后释放连接还是保持连接

 

 

 

 


4.2.3 空行

最后一个请求头部之后是一个空行,发送回车符和换行符,通知服务器以下不再有请求头部了。

4.2.4 请求数据

GET方法中没有请求数据的内容

POST方法使用请求数据,用于客户端向服务器端填写表单等操作。

 

4.2.5 HTTP请求例子

GET /index.html HTTP/1.1  \r\n
Host:www.baidu.com\r\n
User-Agent:Mozilla/5.0
Accept-Language:cn*/*\r\n

4.3 HTTP响应报文格式

HTTP响应也由四个部分组成,分别是:状态行、消息头部、空行和响应正文。

其具体格式如下:

(状态行)版本+空格+状态码+空格+短语+回车换行
(消息头部1)关键字+“:”+空格+值+回车换行
  ……
(消息头部N)关键字+“:”+空格+值+回车换行
(空行)回车换行(\r\n)
(响应正文)……

4.3.1 响应状态行

在响应报文的状态行中,版本字的表示服务器HTTP协议的版本,状态码字的表示服务器发回的响应状态代码;短语字段表示状态代码的文本描述。


状态码由三位十进制数字组成,第一个数字定义了响应的类别,有五种可能取值(1-5)

每种状态码的含义如下:

1xx

指示信息

表示请求已接收,继续处理

2xx

成功

表示请求已被成功接收、理解、接受

3xx

重定向

要完成请求必须进行更进一步的操作

4xx

客户端错误

请求有语法错误或请求无法实现

5xx

服务器端错误

服务器未能实现合法的请求


常见状态码及状态描述的说明如下:

 

 

 

200

OK

客户端请求成功

400

Bad Request

客户端请求有语法错误,不能被服务器所理解

401

Unauthorized

请求未经授权

403

Forbidden

服务器收到请求,但是拒绝提供服务

404

Not Found

请求资源不存在,比如输入了错误的URL

500

Internal ServerError

服务器发生不可预期的错误

503

ServerUnavailable

服务器当前不能处理客户端的请求,一段时间后可能恢复正常

 

4.3.2 响应消息头部

消息头部与请求头部的格式相似,也是包含若干行,每行由关键字及其值构成

 

常用的关键字包括:

Date

表示返回消息的时间

 

Content-Type

表示返回消息的内容类型

 

Content-Length

返回内容的长度(字节数)

 

Server

使用的服务器软件及其版本号

 

 

 

 


4.3.3 空行

同样,最后一个消息头部之后是一个空行,发送回车符和换行符,通知客户端以下不再有消息头部了。(注:空行必须有)

 

4.3.4 响应正文

响应正文部分是服务器端根据客户端的请求发回的具体文档内容,以HTML语言表示。

 

4.4 CGI 简介

CGI(Common Gateway Interface) 是WWW技术中最重要的技术之一,有着不可替代的重要地位。CGI是外部应用程序(CGI程序)与WEB服务器之间的接口标准,是在CGI程序和Web服务器之间传递信息的过程。CGI规范允许Web服务器执行外部程序,并将它们的输出发送给Web浏览器,CGI将Web的一组简单的静态超媒体文档变成一个完整的新的交互式媒体。

 

5 源码分析

/* J. David's webserver */
/* This is a simple webserver.
 * Created November 1999 by J. David Blackstone.
 * CSE 4344 (Network concepts), Prof. Zeigler
 * University of Texas at Arlington
 */
/* This program compiles for Sparc Solaris 2.6.
 * To compile for Linux:
 *  1) Comment out the #include <pthread.h> line.
 *  2) Comment out the line that defines the variable newthread.
 *  3) Comment out the two lines that run pthread_create().
 *  4) Uncomment the line that runs accept_request().
 *  5) Remove -lsocket from the Makefile.
 */
#include <stdio.h>
#include <sys/socket.h>
#include <sys/types.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <unistd.h>
#include <ctype.h>
#include <strings.h>
#include <string.h>
#include <sys/stat.h>
#include <pthread.h>
#include <sys/wait.h>
#include <stdlib.h>
#define ISspace(x) isspace((int)(x))
#define SERVER_STRING "Server: jdbhttpd/0.1.0\r\n"
void accept_request(int);
void bad_request(int);
void cat(int, FILE *);
void cannot_execute(int);
void error_die(const char *);
void execute_cgi(int, const char *, const char *, const char *);
int get_line(int, char *, int);
void headers(int, const char *);
void not_found(int);
void serve_file(int, const char *);
int startup(u_short *);
void unimplemented(int);

/**********************************************************************/
/* A request has caused a call to accept() on the server port to
 * return.  Process the request appropriately.
 * Parameters: the socket connected to the client */
/**********************************************************************/
// 有客户端连接进来时,开启一个线程单独处理一个客户端连接
void accept_request(int client)
{
 char buf[1024];
 int numchars;
 char method[255];
 char url[255];
 char path[512];
 size_t i, j;
 struct stat st;
 int cgi = 0;      /* becomes true if server decides this is a CGI
                    * program */
 char *query_string = NULL;

 // 获取客户端数据
 numchars = get_line(client, buf, sizeof(buf));
 i = 0; j = 0;
 while (!ISspace(buf[j]) && (i < sizeof(method) - 1))
 {
  method[i] = buf[j];
  i++; j++;
 }
 method[i] = '\0';
 if (strcasecmp(method, "GET") && strcasecmp(method, "POST"))
 {
  unimplemented(client);
  return;
 }

 if (strcasecmp(method, "POST") == 0)
  cgi = 1;

 i = 0;
 while (ISspace(buf[j]) && (j < sizeof(buf)))
  j++;
 while (!ISspace(buf[j]) && (i < sizeof(url) - 1) && (j < sizeof(buf)))
 {
  url[i] = buf[j];
  i++; j++;
 }

 url[i] = '\0';
 if (strcasecmp(method, "GET") == 0)
 {
  query_string = url;
  while ((*query_string != '?') && (*query_string != '\0'))
   query_string++;
  if (*query_string == '?')
  {
   cgi = 1;
   *query_string = '\0';
   query_string++;
  }
 }

 sprintf(path, "htdocs%s", url);
 if (path[strlen(path) - 1] == '/')
    strcat(path, "index.html");
 if (stat(path, &st) == -1) {
    while ((numchars > 0) && strcmp("\n", buf))  /* read & discard headers */
      numchars = get_line(client, buf, sizeof(buf));
    not_found(client);
 }
 else
 {
  if ((st.st_mode & S_IFMT) == S_IFDIR)
    strcat(path, "/index.html");
  if ((st.st_mode & S_IXUSR) ||
      (st.st_mode & S_IXGRP) ||
      (st.st_mode & S_IXOTH)    )
   cgi = 1;
  if (!cgi)
    serve_file(client, path);
  else
    execute_cgi(client, path, method, query_string);
 }
 close(client);
}

/**********************************************************************/
/* Inform the client that a request it has made has a problem.
 * Parameters: client socket */
/**********************************************************************/
// 非法请求时返回给客户端的内容
void bad_request(int client)
{
 char buf[1024];
 sprintf(buf, "HTTP/1.0 400 BAD REQUEST\r\n");
 send(client, buf, sizeof(buf), 0);
 sprintf(buf, "Content-type: text/html\r\n");
 send(client, buf, sizeof(buf), 0);
 sprintf(buf, "\r\n");
 send(client, buf, sizeof(buf), 0);
 sprintf(buf, "<P>Your browser sent a bad request, ");
 send(client, buf, sizeof(buf), 0);
 sprintf(buf, "such as a POST without a Content-Length.\r\n");
 send(client, buf, sizeof(buf), 0);
}

/**********************************************************************/
/* Put the entire contents of a file out on a socket.  This function
 * is named after the UNIX "cat" command, because it might have been
 * easier just to do something like pipe, fork, and exec("cat").
 * Parameters: the client socket descriptor
 *             FILE pointer for the file to cat */
/**********************************************************************/

// 把 resource中的内容发送到套接字中
void cat(int client, FILE *resource)
{
   char buf[1024];
   // 第一次读取
   fgets(buf, sizeof(buf), resource);
   while (!feof(resource))
   {
      // 发送
      send(client, buf, strlen(buf), 0);
      // 继续读取
      fgets(buf, sizeof(buf), resource);
   }
}

/**********************************************************************/
/* Inform the client that a CGI script could not be executed.
 * Parameter: the client socket descriptor. */
/**********************************************************************/
// CGI 脚本不能执行时返回给客户端的内容
void cannot_execute(int client)
{
 char buf[1024];
 sprintf(buf, "HTTP/1.0 500 Internal Server Error\r\n");
 send(client, buf, strlen(buf), 0);
 sprintf(buf, "Content-type: text/html\r\n");
 send(client, buf, strlen(buf), 0);
 sprintf(buf, "\r\n");
 send(client, buf, strlen(buf), 0);
 sprintf(buf, "<P>Error prohibited CGI execution.\r\n");
 send(client, buf, strlen(buf), 0);
}

/**********************************************************************/
/* Print out an error message with perror() (for system errors; based
 * on value of errno, which indicates system call errors) and exit the
 * program indicating an error. */
/**********************************************************************/
void error_die(const char *sc)
{
   perror(sc);
   exit(1);
}

/**********************************************************************/
/* Execute a CGI script.  Will need to set environment variables as
 * appropriate.
 * Parameters: client socket descriptor
 *             path to the CGI script */
/**********************************************************************/
// 执行CGI脚本
void execute_cgi(int client, const char *path,
                 const char *method, const char *query_string)
{
 char buf[1024];
 // 输入和输出管道
 int cgi_output[2];
 int cgi_input[2];
 pid_t pid;
 int status;
 int i;
 char c;
 int numchars = 1;
 int content_length = -1;
 buf[0] = 'A'; buf[1] = '\0';
 if (strcasecmp(method, "GET") == 0)
 {
    while ((numchars > 0) && strcmp("\n", buf))  /* read & discard headers */
      numchars = get_line(client, buf, sizeof(buf));
 }
 else    /* POST */
 {
    numchars = get_line(client, buf, sizeof(buf));
    while ((numchars > 0) && strcmp("\n", buf))
    {
       buf[15] = '\0';
       if (strcasecmp(buf, "Content-Length:") == 0)
       {
          content_length = atoi(&(buf[16]));
       }
       numchars = get_line(client, buf, sizeof(buf));
    }
    if (content_length == -1)
    {
       bad_request(client);
       return;
    }
 }

 sprintf(buf, "HTTP/1.0 200 OK\r\n");
 // 发送http头给客户端
 send(client, buf, strlen(buf), 0);

 // 打开管道
 if (pipe(cgi_output) < 0) {
  cannot_execute(client);
  return;
 }

 if (pipe(cgi_input) < 0) {
  cannot_execute(client);
  return;
 }

 // 创建一个进程
 if ( (pid = fork()) < 0 ) {
    cannot_execute(client);
    return;
 }

 // 子进程处理CGI 脚本
 if (pid == 0)  /* child: CGI script */
 {
    char meth_env[255];
    char query_env[255];
    char length_env[255];

    // 复制输出管道中的写描述符到标准输出
    dup2(cgi_output[1], 1);
    // 复制输入管道中的读描榜符到标准输入
    dup2(cgi_input[0], 0);
    // 关闭输出管道中的读描述符
    close(cgi_output[0]);
    // 关闭输入管道中的写描述符
    close(cgi_input[1]);

    // 设置环境变量
    sprintf(meth_env, "REQUEST_METHOD=%s", method);
    putenv(meth_env);
    //GET方法处理
    if (strcasecmp(method, "GET") == 0) {
       sprintf(query_env, "QUERY_STRING=%s", query_string);
       putenv(query_env);
    }
    // POST方法处理
    else
    {   /* POST */
       sprintf(length_env, "CONTENT_LENGTH=%d", content_length);
       putenv(length_env);
    }

    // 执行CGI脚本
    execl(path, path, NULL);
    exit(0);
  }
  // 父进程处理
  else
  {    /* parent */
    // 关闭输出管道的写描述符
    close(cgi_output[1]);
    // 关闭输入管道的读描述符
    close(cgi_input[0]);
    // 从管道中读取或发送数据
    if (strcasecmp(method, "POST") == 0)
    {
        // 从客户端发来的空容中读取数据
        // 并写到CGI输入管理中
       for (i = 0; i < content_length; i++)
       {
          recv(client, &c, 1, 0);
          write(cgi_input[1], &c, 1);
       }      
    }

    // 从CGI输出管道中的内容
    // 并发送给客户端
    while (read(cgi_output[0], &c, 1) > 0)
      send(client, &c, 1, 0);

    //关闭管道
    close(cgi_output[0]);
    close(cgi_input[1]);
    // 等待子进程退出
    waitpid(pid, &status, 0);
  }
}

/**********************************************************************/
/* Get a line from a socket, whether the line ends in a newline,
 * carriage return, or a CRLF combination.  Terminates the string read
 * with a null character.  If no newline indicator is found before the
 * end of the buffer, the string is terminated with a null.  If any of
 * the above three line terminators is read, the last character of the
 * string will be a linefeed and the string will be terminated with a
 * null character.
 * Parameters: the socket descriptor
 *             the buffer to save the data in
 *             the size of the buffer
 * Returns: the number of bytes stored (excluding null) */
/**********************************************************************/
// 从socket 读取一行数据
int get_line(int sock, char *buf, int size)
{
 int i = 0;
 char c = '\0';
 int n;
 while ((i < size - 1) && (c != '\n'))
 {
    n = recv(sock, &c, 1, 0);
    /* DEBUG printf("%02X\n", c); */
    if (n > 0)
    {
       if (c == '\r')
       {
        n = recv(sock, &c, 1, MSG_PEEK);
        /* DEBUG printf("%02X\n", c); */
        if ((n > 0) && (c == '\n'))
         recv(sock, &c, 1, 0);
        else
         c = '\n';
       }
       buf[i] = c;
       i++;
    }
    else
     c = '\n';
 }
 buf[i] = '\0';
 return(i);
}

/**********************************************************************/
/* Return the informational HTTP headers about a file. */
/* Parameters: the socket to print the headers on
 *             the name of the file */
/**********************************************************************/
// HTTP headers文件
void headers(int client, const char *filename)
{
 char buf[1024];
 (void)filename;  /* could use filename to determine file type */
 strcpy(buf, "HTTP/1.0 200 OK\r\n");
 send(client, buf, strlen(buf), 0);
 strcpy(buf, SERVER_STRING);
 send(client, buf, strlen(buf), 0);
 sprintf(buf, "Content-Type: text/html\r\n");
 send(client, buf, strlen(buf), 0);
 strcpy(buf, "\r\n");
 send(client, buf, strlen(buf), 0);
}

/**********************************************************************/
/* Give a client a 404 not found status message. */
/**********************************************************************/
// 文件没找到
void not_found(int client)
{
 char buf[1024];
 sprintf(buf, "HTTP/1.0 404 NOT FOUND\r\n");
 send(client, buf, strlen(buf), 0);
 sprintf(buf, SERVER_STRING);
 send(client, buf, strlen(buf), 0);
 sprintf(buf, "Content-Type: text/html\r\n");
 send(client, buf, strlen(buf), 0);
 sprintf(buf, "\r\n");
 send(client, buf, strlen(buf), 0);
 sprintf(buf, "<HTML><TITLE>Not Found</TITLE>\r\n");
 send(client, buf, strlen(buf), 0);
 sprintf(buf, "<BODY><P>The server could not fulfill\r\n");
 send(client, buf, strlen(buf), 0);
 sprintf(buf, "your request because the resource specified\r\n");
 send(client, buf, strlen(buf), 0);
 sprintf(buf, "is unavailable or nonexistent.\r\n");
 send(client, buf, strlen(buf), 0);
 sprintf(buf, "</BODY></HTML>\r\n");
 send(client, buf, strlen(buf), 0);
}

/**********************************************************************/
/* Send a regular file to the client.  Use headers, and report
 * errors to client if they occur.
 * Parameters: a pointer to a file structure produced from the socket
 *              file descriptor
 *             the name of the file to serve */
/**********************************************************************/
// 读取服务器本地文件发送给客户端
void serve_file(int client, const char *filename)
{
   FILE *resource = NULL;
   int numchars = 1;
   char buf[1024];
   buf[0] = 'A'; buf[1] = '\0';
   while ((numchars > 0) && strcmp("\n", buf))  /* read & discard headers */
      numchars = get_line(client, buf, sizeof(buf));

   resource = fopen(filename, "r");
   // 文件没找到
   if (resource == NULL)
      not_found(client);
   else
   {
      // 发送HTTP头
      headers(client, filename);
      // 发送文件内容
      cat(client, resource);
   }
   fclose(resource);
}

/**********************************************************************/
/* This function starts the process of listening for web connections
 * on a specified port.  If the port is 0, then dynamically allocate a
 * port and modify the original port variable to reflect the actual
 * port.
 * Parameters: pointer to variable containing the port to connect on
 * Returns: the socket */
/**********************************************************************/
// 启动服务端HTTP监听套接字
// 并返回端口
int startup(u_short *port)
{
 int httpd = 0;
 struct sockaddr_in name;
 // 打开套字字
 httpd = socket(PF_INET, SOCK_STREAM, 0);
 if (httpd == -1)
  error_die("socket");

  // 设置服务端套接字地址
 memset(&name, 0, sizeof(name));
 name.sin_family = AF_INET;
 name.sin_port = htons(*port);
 name.sin_addr.s_addr = htonl(INADDR_ANY);

 // 绑定套接字
 if (bind(httpd, (struct sockaddr *)&name, sizeof(name)) < 0)
  error_die("bind");

  // 如果端口为0
  // 自动分配一个端口
 if (*port == 0)  /* if dynamically allocating a port */
 {
    int namelen = sizeof(name);
    if (getsockname(httpd, (struct sockaddr *)&name, &namelen) == -1)
      error_die("getsockname");
    *port = ntohs(name.sin_port);
 }

 // 服务端监听套接字
 if (listen(httpd, 5) < 0)
  error_die("listen");
 return(httpd);
}

/**********************************************************************/
/* Inform the client that the requested web method has not been
 * implemented.
 * Parameter: the client socket */
/**********************************************************************/
// HTTP 501 错误返回
void unimplemented(int client)
{
 char buf[1024];
 sprintf(buf, "HTTP/1.0 501 Method Not Implemented\r\n");
 send(client, buf, strlen(buf), 0);
 sprintf(buf, SERVER_STRING);
 send(client, buf, strlen(buf), 0);
 sprintf(buf, "Content-Type: text/html\r\n");
 send(client, buf, strlen(buf), 0);
 sprintf(buf, "\r\n");
 send(client, buf, strlen(buf), 0);
 sprintf(buf, "<HTML><HEAD><TITLE>Method Not Implemented\r\n");
 send(client, buf, strlen(buf), 0);
 sprintf(buf, "</TITLE></HEAD>\r\n");
 send(client, buf, strlen(buf), 0);
 sprintf(buf, "<BODY><P>HTTP request method not supported.\r\n");
 send(client, buf, strlen(buf), 0);
 sprintf(buf, "</BODY></HTML>\r\n");
 send(client, buf, strlen(buf), 0);
}

/**********************************************************************/

int main(void)
{
 // 服务端套接字
 int server_sock = -1;
 // 端口
 u_short port = 8888;
 // 客户端套接字
 int client_sock = -1;
 // 客户端地址
 struct sockaddr_in client_name;
 int client_name_len = sizeof(client_name);
 // 线程
 pthread_t newthread;
 // 创建一个套接字服务
 server_sock = startup(&port);
 printf("httpd running on port %d\n", port);

 while (1)
 {
  // 接受客户端连接
  client_sock = accept(server_sock,
                       (struct sockaddr *)&client_name,
                       &client_name_len);
  if (client_sock == -1)
   error_die("accept");
 /* accept_request(client_sock); */
 // 创建线程并处理新连接
 if (pthread_create(&newthread , NULL, accept_request, client_sock) != 0)
   perror("pthread_create");
 }

 // 关闭服务端套接字
 close(server_sock);
 return(0);
}

6 总结

tinyhttpd 是个非常轻量级的HTTP SERVER,对于学习HTTP SEVER实现非常有帮助,而且可以修改或增加源码,来实现其他功能,麻雀虽小,五脏俱全,里面包含:HTTP的整体工作流程,HTTP原理,HTTP请求和响应实现,还包括CGI,可以执行脚本文件等。

HTTP在本质上就是TCP连接,有一定的规范,请求格式和响应格式。按照相应的规范发送和接收消息,最后解析内容并展示到浏览器上。

学编程,最主要的就是学习本质,如果一门技术或语言,如果本质原理都懂了,开发质量会更好,也可以去做更深层次的优化。

最小的http服务器 最小的http服务器,只需拷贝到文件目录中运行,别人输入你的IP 就可访问文件目录 立即下载

相关推荐

最小的http文件服务器,最精巧的文件服务器,界面美观,便于管理,一键搭建文件服务器,http文件服务器

最小的文件服务器,最精巧的文件服务器,界面美观,便于管理,一键搭建文件服务器,http文件服务器,支持win10

史上最小的Http服务器

概述 TinyHttp基于CSAPP(深入理解计算机系统第11章网络编成)实现。 TinyHttp足够小,只有不到300行的代码,却可以完整的展示一个Web服务器的基本原理和功能。 TinyHttp实现了HTTP的GET、POST、HEAD方法处理过程。 TinyHttp可以动态的扩展静态文件类型。 TinyHttp可以动态的扩展cgi-bin下的可执行程序,完成各种不同功能的动态内容的生成。 TinyHttp是健壮的,实现对于常见异常的处理过程,比如,SIGPIPE信号等。 项目代码:https://

飞翔de刺猬 2597

MATLAB绘图中文乱码终极解决方案:从方框到清晰显示的全面指南

本文提供了MATLAB绘图中文乱码的全面解决方案。针对中文显示为方框的问题,从单次绘图的临时字体设置,到通过修改默认配置实现一劳永逸,再到系统级字体排查与Java环境配置,给出了详细的步骤指南。文章还涵盖了字体名称指定、图像导出防丢失以及跨平台协作等高级技巧,帮助用户彻底解决中文乱码困扰。

weixin_29093017的博客 613

基于c开发的一个超轻量型 HTTP Server附源码

Tiny HTTPd 是一个超轻量型 HTTP Server。

热情、奔放、快乐编程! 558

Kaamel白皮书:Agent-to-Agent(A2A)隐私安全最佳实践

随着AI智能体架构从单体模型演化为多Agent协同系统,A2A协议为智能生态提供了强大的互操作能力。然而,能力越大,责任亦重。若无完备的隐私保护和安全防护体系,A2A将沦为数据泄露、滥权执行的温床。Kaamel作为专注于泛安全方向的Agent基础设施构建者,呼吁业界将“隐私工程”与“安全编排”作为A2A系统设计的核心前提,共建可信Agent生态,守护智能协同时代的数据主权与系统安全。未来,Kaamel计划发布一套“可信Agent协同蓝图”,涵盖:A2A协议适配Agent SDK工具集;

kaamelai的博客 1598

ANSYS 有限元分析 接触分析

目 录一、前沿二、接触单元类三、接触单元关键选项3.1 CONTA174 KeyOption3.2 TARGE170 KeyOption四、接触分析标准步骤4.1 定义实常数4.2 定义接触和目标单元4.3 创建接触和目标单元五、接触分析实例5.1 MPC5.2 标准接触六、尾声七、参考文献 阿阳的 ANSYS 使用指南,本文仅用于个人学习,除此之外,无其他任何用途。 ANSYS 有限元分析 概述 ANSYS 有限元分析 坐标系/工作平面 ANSYS 有限元分析 几何建模 ANSY

Hulunbuir 4万+

一个非常小的http服务器NanoHTTPD使用教程

NanoHTTPD 免费,轻量,开源 的特性是每个开发者的最爱,由于采用的是java,天生跨平台,所以还可以运行android手机上。

qyhua的专栏 5765

GD32F470 DSP库移植避坑指南:从CMSIS版本冲突到AC6工程配置

本文详细解析了在GD32F470平台上移植CMSIS-DSP库的完整流程与关键避坑点。针对CMSIS版本冲突、AC6编译器下的浮点ABI配置、DSP库源文件添加等核心难题,提供了经过验证的解决方案,帮助开发者高效完成移植,确保硬件FPU正常工作并优化性能。

data3的博客 529

简单的http服务器源码

/* 简单的http服务器,参考《深入理解计算机系统》 运行后在浏览器输入http://127.0.0.1/1.htm */ import "rsock.h" import "rfile.h" import "rdir.h" main { rsock svr rsock client svr.listen 80 for svr.accept client { rstr s

RPP 国产开源编程语言 2278

西门子与汇川伺服脉冲连接(速度模式)

如何使用西门子PLC与汇川伺服进行脉冲连接

2301_77347966的博客 1万+

反光柱定位算法实战05:Cartographer Landmark融合定位——从原理到实战

本文介绍了CartographerLandmark融合定位方案,该方案将反光柱作为Landmark节点直接融入Cartographer后端优化框架,避免了传统双系统切换导致的位姿跳变问题。文章详细阐述了Landmark的核心原理、数据发布格式(包括ID、坐标、权重等关键字段)以及两种工作模式(建图模式和导航模式)。特别指出组合反光柱作为Landmark可提供方向参考,有效解决镜像歧义问题。该方案通过统一优化框架实现稳定定位,尤其适用于缺乏自然特征的环境,但存在ID匹配不稳定等局限性。整体而言,Cartogr

Studying…… 424

项目--基于http协议的小型web服务器

在我们对Linux以及C++学习的过程中,我们只进行基础语法的学习是远远不够的,所以我们找到了一个项目用以练手 众所周知C++的boost库只提供查询功能,没有提供搜索功能,而我们这次的项目,就是来实现一下boost的文档搜索 前置准备 我们需要进行boost文档搜索,就一定先拥有一个boost文档,我们的官方给我们的boost由一个离线版本的boost,和一个在线版本的boost,我们可以将离线的boost,下载到我们本地,用于我们离线搜索,具体可以到官网进行搜索 在我们下载完成离弦的boost之

平生的小铺子 2252

chembl_webresource_client 包数据接口下载chembl数据库;ZINC数据库下载、simles获取

点击进去https://zinc.docking.org/subclasses/kinase/predictions/,然后下载sdf模式,这里可以转化simles格式,如果下载csv里面没有包含simles。参考:https://github.com/chembl/chembl_webresource_client/blob/master/demo_wrc.ipynb。参考:https://zinc.docking.org/这是网页搜索查看,16条数据。这个数据这下载特别慢。

weixin_42357472的博客 3046

Tinyhttp源码分析

文章目录tinyhttpd简介tinyhttpd运行源码分析Tinyhttp的执行流程 tinyhttpd简介 tinyhttpd是一个超轻量型Http Server,使用C语言开发,附带一个简单的Client,毕竟只有500来行,是很好的 Http Server 学习资料。下载链接:tinyhttpd tinyhttpd运行 在运行之前在不同的Linux版本上可能要做不同的改动,根据编译器的提示走很快就能编译好,注意要改下Makefile文件。 运行结果如下: 源码分析 tinyhttpd中主要包含以下

weixin_44988779的博客 263

以 Joule 驱动的生成式开发:把需求文档直接变成可运行的 SAP 应用

摘要:SAP BTP的AI助手Joule正在改变开发方式,支持从自然语言描述自动生成数据模型、服务、UI及测试代码。在SAP Business Application Studio中,Joule能根据业务需求生成结构化代码,并提供代码补全、重构、解释等功能。开发者需注意避免上传敏感数据,并对AI生成的代码进行人工审核。Joule特别针对ABAP开发进行了优化,提供符合SAP规范的代码建议,帮助迁移遗留系统。此外,它还能快速生成CAP项目原型,但所有AI生成内容都需经过严格测试验证。

2007 年 ~ 2025 年,深耕 SAP 技术 18 年 340

visio安装包

Microsoft Office Visio 是一款专业的制图软件。利用经过更新的形状、协作工具和数据链接图表,创建专业级图表以简化复杂的信息。

【源码剖析】tinyhttpd —— C 语言实现最简单的 HTTP 服务器

tinyhttpd 是一个不到 500 行的超轻量型 Http Server,用来学习非常不错,可以帮助我们真正理解服务器程序的本质。     看完所有源码,真的感觉有很大收获,无论是 unix 的编程,还是 GET/POST 的 Web 处理流程,都清晰了不少。废话不说,开始我们的 Server 探索之旅。     (水平有限,如有错误之处,欢迎指正)      项目主页    

ProgramVAE的博客 4432

SIMATIC S7-1200, S7-1500 PID 控制[手册]

SIMATIC S7-1200, S7-1500 PID 控制[手册]

Tinyhttp学习之路

加粗样式 写在前面 最近在学习Linux网络编程,对客户端/服务端有了大致了解,纸上得来终觉浅,总觉得理解得不够彻底,于是在网上找了一个开源代码学习。 tinyhttpd是一个超轻量型Http Server,使用C语言开发,全部代码只有502行(包括注释),附带一个简单的client,可以通过阅读这段代码理解一个 Http Server 的本质。 下载链接:http://sourceforge.n...

weixin_44918162的博客 657

蓝牙模块HM-10手册

蓝牙模块HM-10手册,该手册对蓝牙模块HM-10进行了详细的介绍和使用方法以及一些AT指令。

win10 跳过U8环境检测的IE WebControls.rar

win10 安装u8的时候 提示IE WebControls 不通过,这个工具可以欺骗u8的检查。 跳过U8环境检测的IE WebControls。提示导入失败后,重新检测通过。

最适合新手学习的http服务器——tinyhttpd

tinyhttpd是一个非常小的http服务器,一个c文件,十多个函数,总共500多行代码,但清晰解释了web服务器的处理流程,可谓是麻雀虽小,五脏俱全。拿tinyhttpd源码做例子对于一个想了解web服务的新手来说非常合适! 新手花个20分钟时间学习之后再去学习其它的Web服务器时就容易多了。http.c源码: 每个函数的作用都给出了解释,自个阅读吧!/* J. David's webser

图像、视频、算法、Linux 2849

【亲测免费】 C Http服务器源码下载

C# Http服务器源码下载 去发现同类优质开源项目:https://gitcode.com/ 简介 本仓库提供了一个基于C#编写的Http服务器源码,适用于Visual Studio 2010(VS2010)。该源码可以帮助开发者快速搭建一个简单的Http服务器,适用于学习和开发小型Web应用。 资源文件 文件名: C# Http服务器 描述: 【源码】【vs2010】Http服务器 使用说...

gitblog_09755的博客 340

探索小巧而强大的 `tiny-httpd`:一个微型HTTP服务器

探索小巧而强大的 tiny-httpd:一个微型HTTP服务器 简介 是一个轻量级的、开源的C语言实现的HTTP服务器,由lzxeth开发。它以其小巧的体积和高效的性能脱颖而出,适用于快速搭建本地测试环境、教育目的或是对资源有限的嵌入式设备进行Web服务。 技术分析 架构与设计 tiny-httpd采用了经典的客户端-服务器模型,处理每个连接时都会创建一个新的线程。这种设计允许服务器同时处理多个请...

gitblog_00096的博客 681

tinyWebServer 学习笔记——二、HTTP 连接处理

从模型的角度来看,从状态机负责通用的操作处理,主状态机负责特定的操作处理,主状态机需要使用从状态机提供的数据,从状态机需要被主状态机调用,每个状态机又是一个有限状态机。有限状态机是一种抽象的理论模型,使用选择语句来实现。模型要求代码存在 n 个状态,使用当前状态。

BeZer0的学习笔记 6092

六款小巧的HTTP Server[C语言]

1、micro_httpd - really small HTTP server 特点: 支持安全的 .. 上级目录过滤 支持通用的MIME类型 支持简单的目录 支持目录列表 支持使用 index.html 作为首页 Trailing-slash redirection 程序总共代码才200多行 这个httpd适合学习简单的Web Server编写学习,因为它只有一个简单的框架,只能够处理简单的静态页,可以考虑用来放静态页。 官方地址:http://www.acme.com/software/micro_h

Sapphire521的博客 2220

探索Tinyhttpd:一款轻量级HTTP服务器

探索Tinyhttpd:一款轻量级HTTP服务器 TinyhttpdA tiny http server with multi-port monitoring.项目地址:https://gitcode.com/gh_mirrors/tinyhtt/Tinyhttpd 是一个小型、简洁且易于理解的HTTP服务器项目,由Huangtuzhi开发并维护。它旨在为学习网络编程和Web服务器工作原理提供一...

gitblog_00025的博客 551

自主实现小型的http服务器

该项目是一个基于Http和Tcp协议自主实现的WebServer,用于实现服务器对客户端发送过来的GET和POST请求的接收、解析、处理,并返回处理结果给到客户端。项目源码为了更好的学习网络协议等知识,对http的协议进行更深一步的了解//进行监听。

m0_56271369的博客 429

六款小巧的HTTP Server

http://blog.chinaunix.net/uid-25885064-id-3455912.html 1、micro_httpd - really small http server 特点:     支持安全的 .. 上级目录过滤     支持通用的MIME类型     支持简单的目录     支持目录列表     支持使用 index.html 作为首页

武溪嵌人 1538

strcpy函数实现(C语言)

strcpy函数实现(C语言)second60  20180530#include &lt;stdio.h&gt; char* strcpy(char *strDest, const char* strSrc) { char *p=NULL; if(strDest == NULL || strSrc == NULL) { return NULL; }...

second60的博客 2万+
上一篇: [源码分析] 性能压测工具-webbench
下一篇: [源码分析]-轻量级JSON-cJson
second60
博客等级 码龄9年 155粉丝 88原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值