Forum: NGINX ngx_http_process_header_line function in source code

2974d09ac2541e892966b762aad84943?d=identicon&s=25 alayim (Guest)
on 2014-06-16 00:03
(Received via mailing list)
Hi,
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()
creates
a pointer to a pointer to a large struct(ngx_http_request_t) containing
a
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,
doesen't
it?
Is there any reason something like this wasn't done instead?

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

Posted at Nginx Forum:
http://forum.nginx.org/read.php?2,250869,250869#msg-250869
A8108a0961c6087c43cda32c8616dcba?d=identicon&s=25 Maxim Dounin (Guest)
on 2014-06-16 13:31
(Received via mailing list)
Hello!

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
http://nginx.org/
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
for
these kinds of questions?
I'm a fairly fresh computer science student who just started working in
the
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
able
to contribute something worthwhile.

So, I'm wondering, if there is any more appropriate place where I can
ask
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
default
label.
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
http-method
is still in its unmodified initial value of NGX_HTTP_UNKNOWN, which
doesen't
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
actually
spot something? Or is it left this way by design?

Posted at Nginx Forum:
http://forum.nginx.org/read.php?2,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
design
that you don't catch the error at the parsing stage.

Posted at Nginx Forum:
http://forum.nginx.org/read.php?2,250869,251093#msg-251093
Please log in before posting. Registration is free and takes only a minute.
Existing account

NEW: Do you have a Google/GoogleMail, Yahoo or Facebook account? No registration required!
Log in with Google account | Log in with Yahoo account | Log in with Facebook account
No account? Register here.