Skip to content

Commit

Permalink
wsdgram: Fix handshake error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelforney committed Feb 4, 2024
1 parent 3bee9f0 commit 42c5899
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
4 changes: 2 additions & 2 deletions http.c
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,10 @@ void
http_error(FILE *fp, int code, const char *text, const char *hdr[], size_t hdr_len)
{
assert(code >= 100 && code < 1000);
fprintf(fp, "HTTP/1.1 %d %s\r\nContent-Type:text/plain\r\nContent-Length:%zu\r\n", code, text, 4 + strlen(text));
fprintf(fp, "HTTP/1.1 %d %s\r\nContent-Type:text/plain\r\nContent-Length:%zu\r\n", code, text, 5 + strlen(text));
while (hdr_len > 0) {
--hdr_len;
fprintf(fp, "%s\r\n", *hdr);
}
fprintf(fp, "\r\n%d %s", code, text);
fprintf(fp, "\r\n%d %s\n", code, text);
}
8 changes: 4 additions & 4 deletions wsdgram.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ usage(void)
exit(1);
}

static int
static void
handshake(FILE *rd, FILE *wr)
{
static const char response[] =
Expand Down Expand Up @@ -110,11 +110,11 @@ handshake(FILE *rd, FILE *wr)
fwrite(response, 1, sizeof response - 1, wr);
fprintf(wr, "Sec-WebSocket-Accept: %s\r\n\r\n", accept);
fflush(wr);
fprintf(stderr, "handshake done\n");
return 0;
return;

fail:
return -1;
http_error(wr, 400, "Bad Request", NULL, 0);
exit(1);
}

static void
Expand Down

0 comments on commit 42c5899

Please sign in to comment.