From eea45281f983e65c67412c77ac917d9b28c8d5f5 Mon Sep 17 00:00:00 2001 From: rayworks Date: Tue, 21 Dec 2021 22:28:54 +0800 Subject: [PATCH 1/2] fix : read and display the HTTP content properly --- concurrency-webserver/src/wclient.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/concurrency-webserver/src/wclient.c b/concurrency-webserver/src/wclient.c index ee3977755..a8328efbd 100644 --- a/concurrency-webserver/src/wclient.c +++ b/concurrency-webserver/src/wclient.c @@ -59,10 +59,14 @@ void client_print(int fd) { } // Read and display the HTTP Body - n = readline_or_die(fd, buf, MAXBUF); - while (n > 0) { - printf("%s", buf); - n = readline_or_die(fd, buf, MAXBUF); + int capacity = sizeof(buf) - 1; + n = read_or_die(fd, buf, capacity); + while (n > 0) + { + buf[n] = '\0'; + printf("%s", buf); + + n = read_or_die(fd, buf, capacity); } } From 3e07785223923bd9cafb3301572edf753926e694 Mon Sep 17 00:00:00 2001 From: rayworks Date: Tue, 21 Dec 2021 22:56:46 +0800 Subject: [PATCH 2/2] format the code --- concurrency-webserver/src/wclient.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/concurrency-webserver/src/wclient.c b/concurrency-webserver/src/wclient.c index a8328efbd..9d12eb6b3 100644 --- a/concurrency-webserver/src/wclient.c +++ b/concurrency-webserver/src/wclient.c @@ -61,8 +61,7 @@ void client_print(int fd) { // Read and display the HTTP Body int capacity = sizeof(buf) - 1; n = read_or_die(fd, buf, capacity); - while (n > 0) - { + while (n > 0) { buf[n] = '\0'; printf("%s", buf);