问题: # favicon.ico 简介
是什么?请求如何处理?
favicon.ico 简介
favicon.ico
是网页上的图标文件- 名称:默认名称位 favicon.ico
- 尺寸:16x16、32x32、48x48、64x64、128x128
- 颜色: 8 位、24 位 或 32 位
一般说,在网页中可以通过 HTML 语句设置图标文件
如果不设置,浏览器会在网站根目录中请求图标文件
- 即:主动发送 HTTP 请求
/favicon.ico
- 即:主动发送 HTTP 请求
浏览器与文件服务器的交互
char buf[1024] = {0};
int max = lseek(fd, 0, SEEK_END);
sprintf(head, HTTP_FORMAT, max);
len = TcpClient_SendRow(client, head, strlen(head));
lseek(fd, 0, SEEK_SET);
while ((len > 0) && (len = read(fd, buf, sizeof(buf))) > 0) {
ret + TcpClient_SendRow(client, buf, len);
}
ret = (ret == max);
错误处理
static const char* ERR_FORMAT = ""
""
" "
" "
" D.T.Software "
" "
" "
" DT4SW Http File Server
"
"
"
" OOPS!!!
"
" Path: \'%s\' is NOT available...
"
" "
"";
char *ToErrString(const char *path)
{
char *ret = NULL;
if (path && (ret = malloc(strlen(ERR_FORMAT) + strlen(path) + 1))) {
sprintf(ret, ERR_FORMAT, path);
}
return ret;
}
响应模块入口函数
int RequestHandler(TcpClient* client, const char* req, const char* root)
{
int ret = 0;
if (client && req && root) {
char *ap = GetAbsPath(req, root);
if (ap && (access(ap, F_OK) == 0)) {
if (GetEntryCount(ap) < 0) {
ret = FileReqHandler(client, req, root);
} else {
ret = DirReqHandler(client, req, root);
}
} else {
ret = BadReqHandler(client, req, root);
}
free(ap);
}
return ret;
}