我必须编写一个非常轻量级的服务器,可以在 C 语言的嵌入式系统处理器上运行。
我计划仅支持 GET 请求。大多数内容将是静态的,但它们将由 C CGI 文件生成(是的,我知道,这很痛苦。但我们只有 C 可供使用)。
我能够支持 AJAX GET 请求吗?我不知道是否需要特殊的服务器端代码来处理它们。我觉得 AJAX 都是客户端。
最佳答案
您应该问自己的问题是为什么您需要编写自定义 HTTP 服务器。研究现有的解决方案,看看它们是否满足您的需求。假设您有某种 POSIX 层可供编程,您可以将几种轻量级 HTTP 服务器移植到您的嵌入式系统:
-
GNU libmicrohttpd is a small C library that is supposed to make it easy to run an HTTP server as part of another application. GNU GNU Libmicrohttpd is free software and part of the GNU project.
-
Security, speed, compliance, and flexibility -- all of these describe lighttpd (pron. lighty) which is rapidly redefining efficiency of a webserver; as it is designed and optimized for high performance environments. ... it's Open Source licensed under the revised BSD license.
nginx :
nginx [engine x] is an HTTP and reverse proxy server, as well as a mail proxy server, written by Igor Sysoev. ... Here are some of the success stories: Netflix, Wordpress.com, FastMail.FM. ... The sources and documentation are distributed under the 2-clause BSD-like license.
thttpd :
thttpd is a simple, small, fast, and secure HTTP server. It doesn't have a lot of special features, but it suffices for most uses of the web, it's about as fast as the best full-featured servers (Apache, NCSA Netscape), and it has one extremely useful feature (URL-traffic-based throttling) that no other server currently has.
如果可能的话,建议您不要实现自己的实现,因为 AJAX 在很大程度上依赖于 HTTP/1.1 功能来提供优质的用户体验,而从头开始实现所有 HTTP/1.1 是一项相当艰巨的任务,在服务器稳定且性能足以成为令人满意的产品之前,可能需要多次开发迭代。
关于c - 编写自定义 http 服务器,支持 AJAX 是否需要 HTTP GET 上的额外代码?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17636210/