когда я использую curl для проверки моего http-сервера: я обнаружил, что могу правильно ответить на GET /url/index.html. Но сервер не может ответить на GET /url/site.png. Я использую Wireshark для анализа, я обнаружил, что запрос GET png может быть перехвачен. Но соответствующий ответ не появляется. Но с GET index.html все в порядке. вот мое содержание локона
* TCP_NODELAY set
* Connected to localhost (127.0.0.1) port 9999 (#0)
> GET /images/liso_header.png HTTP/1.1
> Host: localhost:9999
> User-Agent: curl/7.58.0
> Accept: */*
>
< HTTP/1.1 200 OK
< Server: liso/1.0
< Content-Type: image/png
< Content-Length: 17431
< Last-Modified: Fri, 23, Sep, 2011, 15:27:06 GMT
<
\211PNG
^Z
А вот и мой код do_GET
void do_GET(Request *req, int fd){
if(check_HTTP_version(req) == -1){
send_error("505", "HTTP version not supported", fd);
}
char full_path[BUF_SIZE];
char *message_body;
long length;
strcpy(full_path, WWW_FOLDER);
strcat(full_path, req->http_uri);
if(is_dir(full_path)) {
strcat(full_path, "/index.html");
}
if(!is_regular(full_path)){
send_error("404","Not Found", fd);
}
char *ext = get_extension(full_path);
char *MIME_type = find_MIME(ext);
message_body = read_file(full_path,&length);
char *datestring = get_file_mtime(full_path);
char *reply = (char *)calloc(BUF_SIZE, sizeof(char));
construct_status_line(reply, "200","OK");
construct_header(reply, "Server",server_name);
construct_header(reply, "Content-Type",MIME_type);
//fprintf(stderr, " send message body %s\n", message_body);
construct_content_length(reply,length);
construct_header(reply, "Last-Modified", datestring);
end_header(reply);
construct_msg_body(reply, message_body);
reply_to_client(reply, fd);
}