[PATCH v2] httpd: Pass custom HTTP headers to CGI scripts
Xabier Oneca -- xOneca
xoneca at gmail.com
Mon Apr 1 22:06:42 UTC 2019
Hi Alex,
> > > #if ENABLE_FEATURE_HTTPD_BASIC_AUTH
> > > - if (STRNCASECMP(iobuf, "Authorization:") == 0) {
> > > + else if (STRNCASECMP(iobuf, "Authorization:") == 0) {
> >
> > You cannot convert this to 'else if'.
>
> Doh.. Do you think the approach in my first version would be acceptable?
I personally prefer the code without 'else'. It is simpler and more clear.
> > > /* We only allow Basic credentials.
> > > * It shows up as "Authorization: Basic <user>:<passwd>" where
> > > * "<user>:<passwd>" is base64 encoded.
> > > @@ -2341,7 +2322,7 @@ static void handle_incoming_and_exit(const len_and_sockaddr *fromAddr)
> > > }
> > > #endif
> > > #if ENABLE_FEATURE_HTTPD_RANGES
> > > - if (STRNCASECMP(iobuf, "Range:") == 0) {
> > > + else if (STRNCASECMP(iobuf, "Range:") == 0) {
> >
> > ... Same here.
> >
> > > /* We know only bytes=NNN-[MMM] */
> > > char *s = skip_whitespace(iobuf + sizeof("Range:")-1);
> > > if (is_prefixed_with(s, "bytes=")) {
> > > @@ -2358,7 +2339,7 @@ static void handle_incoming_and_exit(const len_and_sockaddr *fromAddr)
> > > }
> > > #endif
> > > #if ENABLE_FEATURE_HTTPD_GZIP
> > > - if (STRNCASECMP(iobuf, "Accept-Encoding:") == 0) {
> > > + else if (STRNCASECMP(iobuf, "Accept-Encoding:") == 0) {
> >
> > ... And here.
> >
> > > /* Note: we do not support "gzip;q=0"
> > > * method of _disabling_ gzip
> > > * delivery. No one uses that, though */
> > > @@ -2373,6 +2354,46 @@ static void handle_incoming_and_exit(const len_and_sockaddr *fromAddr)
> > > //}
> > > }
> > > }
> > > +#endif
> > > +#if ENABLE_FEATURE_HTTPD_CGI
> > > + else if (STRNCASECMP(iobuf, "Content-Type:") == 0) {
> > > + if (!content_type)
> > > + content_type = xstrdup(skip_whitespace(iobuf + sizeof("Content-Type:")-1));
> > > + } else {
> > > + HTTP_Header *cur;
> > > + char *after_colon = strchr(iobuf, ':');
> > > + char *ch = iobuf;
> > > +
> > > + if (!after_colon)
> > > + continue;
> > > +
> > > + cur = xmalloc(sizeof(HTTP_Header));
> > > + *after_colon++ = '\0';
> > > +
> > > + while (*ch) {
> > > + if (isalpha(*ch))
> > > + *ch &= ~0x20;
> > > + else if (!isdigit(*ch))
> > > + *ch = '_';
> > > + ch++;
> > > + }
> > > +
> > > + cur->name = xmalloc(sizeof("HTTP_")+strlen(iobuf));
> > > + memcpy(cur->name, "HTTP_", sizeof("HTTP_")-1);
> > > + strcpy(cur->name + sizeof("HTTP_")-1, iobuf);
> >
> > Why not just:
> >
> > cur->name = xasprintf("HTTP_%s", iobuf)?
>
> I thought my version would be faster.
But probably bigger too, and more complicated. I don't think the gain
in speed will be noticeable...
> > > + cur->value = xstrdup(skip_whitespace(after_colon));
> > > +
> > > + /* Insert new header into header list */
> > > + if (!G.hdr_list) {
> > > + G.hdr_list = cur;
> > > + cur->next = G.hdr_list;
> > > + last = cur;
> > > + } else {
> > > + cur->next = G.hdr_list;
> > > + last->next = cur;
> > > + last = cur;
> > > + }
> > > + }
> > > #endif
> > > } /* while extra header reading */
> > > }
Cheers,
Xabier Oneca_,,_
More information about the busybox
mailing list