在wireshark中没有来自服务器的响应,但收到响应,并且解压缩失败错误

时间:2018-05-06 14:52:29

标签: c proxy httpresponse wireshark

这是我的第一个代理实现,它将请求从客户端发送到服务器,并将响应从服务器发送到客户端。

我实际上有两个问题。

Q1: 如第二行所示,请求被发送到服务器。 但我希望收到来自服务器地址' 143.248.36.166'

的回复

但是,服务器地址与源地址没有响应。 但是,如第3行及以下所示,响应从代理发送到客户端。 然后代理在哪里得到响应?

(我清除了历史,因此我认为没有缓存)

enter image description here

我的代码:

        while(1){
        char response[1024];
        bzero(response, 1024);
        int n = read(connfd_to_server, res_buf, 1024);
        if (n <=0){
            printf("will break");
            break;
        }
        else{ //if first packet, modify header
            if(packet == 0){
                res_line = strtok(res_buf, "\r\n");
                for(int i = 0; i<11; i++){  //copy first 11 lines as it is
                    strcat(response, res_line);
                    strcat(response, "\r\n");
                    res_line = strtok(NULL, "\r\n");
                }
                strcat(response, "Via: 1.1 ubuntu (ee323_proxy/1.0.0)");
                strcat(response, "\r\n");  //add this new line
                memcpy(response+strlen(response),res_line,n-strlen(response));  //memcpy rest header, and some message body
                if (send(connfd_to_client, response, n, 0)<0){
                    perror("send failed");
                }
            }
            else{  //if not first packet, there is no header, just send
                if (send(connfd_to_client, res_buf, n, 0)<0){
                    perror("send failed");
                }
            }
        }
        packet++;
    }

Q2: 我想将修改后的内容发送给客户端。 但是有一个错误。

enter image description here

如图所示,添加了新行。 但是,新行之后的行不会以&#39; \ r \ n&n;作为其他线。 我不知道为什么结局发生了变化。

还有一个错误说:减压失败

我想要我的最后一个res_line缓冲区get(rest header + message body),但是,它似乎是错误的。

如何修复这两个问题?

许多人提前感谢 我被困了一段时间......

0 个答案:

没有答案