#include "stdafx.h" #include #include "constdef.h" void sendHead(SOCKET s, int state, char* fileExtension, char* version) { char buf[MAXSIZE] = {'\0'}, *content = "text/plain", *stateStr = NULL; switch(state) { case 200: stateStr = "OK"; break; case 400: stateStr = "Bad Request"; break; case 404: stateStr = "Not Found"; break; default: stateStr = "Unknown"; break; } if(strcmp(fileExtension, "html") == 0 || strcmp(fileExtension, "htm") == 0) { content = "text/html"; } else if(strcmp(fileExtension, "css") == 0) { content = "text/css"; } else if(strcmp(fileExtension, "gif") == 0) { content = "image/gif"; } else if(strcmp(fileExtension, "jpeg") == 0) { content ="image/jpeg"; } else if(strcmp(fileExtension, "jpg") == 0) { content = "image/jpg"; } else if(strcmp(fileExtension,"png") == 0) { content = "image/png"; } sprintf_s(buf, "%s %d %s \r\nContent-Type: %s \r\n\r\n", version, state, stateStr, content); int sendCount = strlen(buf); //for(;buf[sendCount]!='\0';sendCount++); send(s, buf, sendCount, 0); return ; }