summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--fhp.c50
-rw-r--r--header-value-parser.c48
2 files changed, 48 insertions, 50 deletions
diff --git a/fhp.c b/fhp.c
index f8263c2..1eceeee 100644
--- a/fhp.c
+++ b/fhp.c
@@ -115,51 +115,6 @@ fhp_handle_method(fhp_t * const fhp) {
return FHP_OK;
}
-// FIXME: follow RFC7230 3.3.3
-// https://tools.ietf.org/html/rfc7230#section-3.3.3
-static fhp_err_t
-fhp_handle_header_name(fhp_t * const fhp) {
- uint32_t hash = fhp->header_name_hash;
-
- if (hash == fhp->env->hashes[FHP_STR_CONTENT_LENGTH]) {
- switch (fhp->body_type) {
- case FHP_BODY_TYPE_CONTENT_LENGTH:
- // duplicate content-length, ignore first one
- // FIXME: should print warning here
- case FHP_BODY_TYPE_NONE:
- fhp->body_type = FHP_BODY_TYPE_CONTENT_LENGTH;
- break;
- case FHP_BODY_TYPE_TRANSFER_ENCODING:
- // ignore content-length
- // FIXME: should print warnings
- break;
- default:
- // never reached
- return FHP_ERR_INVALID_BODY_TYPE;
- }
- } else if (hash == fhp->env->hashes[FHP_STR_TRANSFER_ENCODING]) {
- switch (fhp->body_type) {
- case FHP_BODY_TYPE_CONTENT_LENGTH:
- // duplicate content-length, ignore first one
- // FIXME: should print warning here
- case FHP_BODY_TYPE_NONE:
- fhp->body_type = FHP_BODY_TYPE_TRANSFER_ENCODING;
- break;
- case FHP_BODY_TYPE_TRANSFER_ENCODING:
- // ignore content-length
- // FIXME: should print warnings
- break;
- default:
- // never reached
- return FHP_ERR_INVALID_BODY_TYPE;
- }
- }
-
- // return success
- return FHP_OK;
-}
-
-
static fhp_err_t
fhp_push_byte(
fhp_t * const fhp,
@@ -455,11 +410,6 @@ retry:
fhp->is_hashing = false;
fhp->header_name_hash = fhp->buf_hash;
- // handle header name
- fhp_err_t err = fhp_handle_header_name(fhp);
- if (err != FHP_OK)
- return err;
-
// send end token
if (!fhp->cb(fhp, FHP_TOKEN_HEADER_NAME_END, 0, 0))
return FHP_ERR_CB;
diff --git a/header-value-parser.c b/header-value-parser.c
index aeab7d3..c1835a5 100644
--- a/header-value-parser.c
+++ b/header-value-parser.c
@@ -88,6 +88,30 @@ fhp_header_value_parser_done(fhp_t * const fhp) {
if ((r = fhp_te_parser_get_tes(&(fhp->parsers.te), fhp->tes, FHP_MAX_TRANSFER_ENCODINGS)) != FHP_OK)
return r;
+ // update body type
+ // FIXME: follow RFC7230 3.3.3
+ // https://tools.ietf.org/html/rfc7230#section-3.3.3
+ switch (fhp->body_type) {
+ case FHP_BODY_TYPE_NONE:
+ // set body type
+ fhp->body_type = FHP_BODY_TYPE_CONTENT_LENGTH;
+
+ break;
+ case FHP_BODY_TYPE_CONTENT_LENGTH:
+ // duplicate content-length
+ // FIXME: should print warning here
+
+ break;
+ case FHP_BODY_TYPE_TRANSFER_ENCODING:
+ // already have transfer-encoding, ignore content-length
+ // FIXME: should print warning here
+
+ break;
+ default:
+ // never reached
+ return FHP_ERR_INVALID_BODY_TYPE;
+ }
+
// notify callback
if (!fhp->cb(fhp, FHP_TOKEN_HEADER_TRANSFER_ENCODING, 0, 0))
return FHP_ERR_CB;
@@ -98,6 +122,30 @@ fhp_header_value_parser_done(fhp_t * const fhp) {
if ((r = fhp_cl_parser_done(&(fhp->parsers.cl), &(fhp->content_length))) != FHP_OK)
return r;
+ // update body type
+ // FIXME: follow RFC7230 3.3.3
+ // https://tools.ietf.org/html/rfc7230#section-3.3.3
+ switch (fhp->body_type) {
+ case FHP_BODY_TYPE_NONE:
+ // set body type
+ fhp->body_type = FHP_BODY_TYPE_TRANSFER_ENCODING;
+
+ break;
+ case FHP_BODY_TYPE_CONTENT_LENGTH:
+ // both content-type and transfer-encoding, ignore content-type
+ // FIXME: should print warning here
+
+ break;
+ case FHP_BODY_TYPE_TRANSFER_ENCODING:
+ // duplicate transfer-encoding
+ // FIXME: should print warnings
+
+ break;
+ default:
+ // never reached
+ return FHP_ERR_INVALID_BODY_TYPE;
+ }
+
// notify callback
if (!fhp->cb(fhp, FHP_TOKEN_HEADER_CONTENT_LENGTH, 0, 0))
return FHP_ERR_CB;