我的http服务器无法响应GET〜/ PNG请求

时间:2018-11-04 05:17:38

标签: http curl

当我使用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);
}

0 个答案:

没有答案