0

In a conditionally compliant/general-purpose server, something likes this

#define HTTP_MSG_LEN_MAX = ??;

...

int read_request(sockfd, ...)
{
  char *buf = malloc(sizeof(char) * http_msg_len_max + 1);
  int read_total = 0;
  int read_once = 0;

    while (zStrFind(buf, "\r\n\r\n") != -1 && read_total < HTTP_MSG_LEN_MAX) {
      read_once = read(sockfd, buf + read_total, HTTP_MSG_LEN_MAX - read_total);

     if (read_once < 0) {
       fprintf(stderr, "read failed: %s \n", strerror(errno));
       free(buf);
       return -1;
     }

     read_total += read_once;
  }

  ...

  return 0;
}

I already know maximum length of HTTP URI in request, but what's the maximum length of an HTTP message?
RFC2616 doesn't mentions it.

Community
  • 1
  • 1
Morty
  • 746
  • 5
  • 12
  • imo you can/should use a buffer and realloc it if it's too small while you process the reads – ablm Feb 06 '13 at 10:34
  • I'm think developer could define this limit by himself, and it should be larger than 8192 bytes. Finally, I'm define it in compiling option. – Morty Feb 27 '13 at 16:01

1 Answers1

2

There is no maximum length (per specification).

Julian Reschke
  • 40,156
  • 8
  • 95
  • 98