Socket网络编程--简单Web服务器(4)

  上一小节已经实现了对图片的传输,接下来就是判断文件是否为js,css,png等格式。我们增加一个函数用于判断格式

1 int WebServer::get_filetype(char *type,char *path)//用于判断该url指向文件的后缀 2 { 3 if(strstr(path,".html")) 4 strcpy(type,"text/html"); 5 else if(strstr(path,".gif")) 6 strcpy(type,"image/gif"); 7 else if(strstr(path,".jpg")) 8 strcpy(type,"image/jpeg"); 9 else if(strstr(path,".png")) 10 strcpy(type,"image/png"); 11 else if(strstr(path,".ico")) 12 strcpy(type,"image/x-icon"); 13 else if(strstr(path,".js")) 14 strcpy(type,"text/javascript"); 15 else if(strstr(path,".json")) 16 strcpy(type,"application/json"); 17 else if(strstr(path,".css")) 18 strcpy(type,"text/css"); 19 else 20 strcpy(type,"text/plain"); 21 return 0; 22 }

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/zzzjfj.html