Forum: NGINX ngx_http_process_header_line function in source code

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
2974d09ac2541e892966b762aad84943?d=identicon&s=25 alayim (Guest)
on 2014-06-16 00:03
(Received via mailing list)
I'm browsing through the source code of the project, and looked at
ngx_http_request.c where the function ngx_http_process_header_line()
a pointer to a pointer to a large struct(ngx_http_request_t) containing
smaller one(ngx_http_headers_in_t), containing yet another one.

ngx_http_process_header_line(ngx_http_request_t *r, ngx_table_elt_t *h,
ngx_uint_t offset) {
    ph = (ngx_table_elt_t **) ((char *) &r->headers_in + offset);
    // ... then check if ph is NULL, and if so point it to h

Why is it done in this way? It seems quite complex and error prone,
Is there any reason something like this wasn't done instead?

(where range are ONE of those structures in headers_in that are a
if(r->headers_in->range == NULL) {
      r->headers_in->range = h;

Posted at Nginx Forum:,250869,250869#msg-250869
A8108a0961c6087c43cda32c8616dcba?d=identicon&s=25 Maxim Dounin (Guest)
on 2014-06-16 13:31
(Received via mailing list)

On Sun, Jun 15, 2014 at 06:03:27PM -0400, alayim wrote:

> }
> }
The ngx_http_process_header_line() function is used to handle lots
of header lines.  You can't hardcode just one name into it -
you'll have to write 15 functions instead (and add another one on
each header line added).  Using one universal function instead
greatly reduces code size and therefore less error prone.

Maxim Dounin
2974d09ac2541e892966b762aad84943?d=identicon&s=25 alayim (Guest)
on 2014-06-21 16:35
(Received via mailing list)
I see your point.
By the way, is there a more appropriate forum or email list I should use
these kinds of questions?
I'm a fairly fresh computer science student who just started working in
industry, and all I'm ever allowed to work on, is Java and C#,
so I decided to do some C hacking on a hobby basis...and chose you poor
souls as my subject.
My plan is basically to just stare at the code untill it makes a bit of
sense, and ask questions if I see something I think might be an error of
some sort, or if I don't understand it, and eventually, maybe I'm even
to contribute something worthwhile.

So, I'm wondering, if there is any more appropriate place where I can
questions about things I find in the code-base.

For instance, right now I'm staring at ngx_http_parse.c
It seems that the switch (p - m)  block at line ~164 is lacking a
So to my naive eyes, it seems it's possible to run
ngx_http_parse_request_line() on a request with a method of less than 3
characters or more than 9, and get a ok return value, where the
is still in its unmodified initial value of NGX_HTTP_UNKNOWN, which
seem to be handled elsewhere in the code(I tried grepping for it).

Should a default value return NGX_HTTP_PARSE_INVALID_METHOD? Did I
spot something? Or is it left this way by design?

Posted at Nginx Forum:,250869,251092#msg-251092
2974d09ac2541e892966b762aad84943?d=identicon&s=25 alayim (Guest)
on 2014-06-21 16:53
(Received via mailing list)
Nevermind, I see there are multiple such cases, so I guess it's by
that you don't catch the error at the parsing stage.

Posted at Nginx Forum:,250869,251093#msg-251093
This topic is locked and can not be replied to.