//  [c]
error_t httpClientParseHeaderField(HttpClientContext *context, char_t *line,
   size_t length)
{
   error_t error;
   char_t *name;
   size_t nameLen;
   char_t *value;
   size_t valueLen;
   char_t *separator;

   //Properly terminate the string with a NULL character
   line[length] = '\0';

   //Debug message
   TRACE_DEBUG("%s\r\n", line);

   //The string must contains visible characters only
   error = httpCheckCharset(line, length, HTTP_CHARSET_TEXT);
   //Any error to report?
   if(error)
      return error;

   //Header field values can be folded onto multiple lines if the continuation
   //line begins with a space or horizontal tab
   if(line[0] == ' ' || line[0] == '\t')
   {
      //A continuation line cannot immediately follows the Status-Line
      if(context->bufferPos == 0)
         return ERROR_INVALID_SYNTAX;

      //Remove optional leading and trailing whitespace
      value = strTrimWhitespace(line);
      //Retrieve the length of the resulting string
      valueLen = osStrlen(value);

      //Sanity check
      if(valueLen > 0)
      {
         //The folding LWS is replaced with a single SP before interpretation
         //of the TEXT value (refer to RFC 2616, section 2.2)
         context->buffer[context->bufferPos - 1] = ' ';

         //Save field value
         osMemmove(context->buffer + context->bufferPos, value, valueLen + 1);

         //Update the size of the hash table
         context->bufferLen = context->bufferPos + valueLen + 1;
      }
   }
   else
   {
      //Each header field consists of a case-insensitive field name followed
      //by a colon, optional leading whitespace, the field value, and optional
      //trailing whitespace (refer to RFC 7230, section 3.2)
      separator = strchr(line, ':');

      //Any parsing error?
      if(separator == NULL)
         return ERROR_INVALID_SYNTAX;

      //Split the line
      *separator = '\0';

      //Remove optional leading and trailing whitespace
      name = strTrimWhitespace(line);
      value = strTrimWhitespace(separator + 1);

      //Retrieve the length of the resulting strings
      nameLen = osStrlen(name);
      valueLen = osStrlen(value);

      //The field name cannot be empty
      if(nameLen == 0)
         return ERROR_INVALID_SYNTAX;

      //Check header field name
      if(!osStrcasecmp(name, "Connection"))
      {
         //Parse Connection header field
         httpClientParseConnectionField(context, value);
      }
      else if(!osStrcasecmp(name, "Transfer-Encoding"))
      {
         //Parse Transfer-Encoding header field
         httpClientParseTransferEncodingField(context, value);
      }
      else if(!osStrcasecmp(name, "Content-Length"))
      {
         //Parse Content-Length header field
         httpClientParseContentLengthField(context, value);
      }
#if (HTTP_CLIENT_AUTH_SUPPORT == ENABLED)
      //WWW-Authenticate header field found?
      else if(!osStrcasecmp(name, "WWW-Authenticate"))
      {
         //Parse WWW-Authenticate header field
         httpClientParseWwwAuthenticateField(context, value);
      }
#endif
      else
      {
         //Discard unknown header fields
      }

      //Save each header field into a hash table by field name
      osMemmove(context->buffer + context->bufferPos, name, nameLen + 1);

      //Save field value
      osMemmove(context->buffer + context->bufferPos + nameLen + 1, value,
         valueLen + 1);

      //Update the size of the hash table
      context->bufferLen = context->bufferPos + nameLen + valueLen + 2;
   }

   //Decode the next header field
   context->bufferPos = context->bufferLen;

   //Successful processing
   return NO_ERROR;
}