Welcome! Log In Create A New Profile

Advanced

Re: understanding ngx_str_t structure

Roman Arutyunyan
September 27, 2019 06:16AM
Hi,

On Fri, Sep 27, 2019 at 05:44:09AM -0400, astre wrote:
> Hi,
>
> I trying to print the requested URL path. For that I came across the "uri"
> member which is of type ngx_str_t) under ngx_http_request_t structure. When
> I print the "uri" using ngx_log_debug1 (ngx_log_debug1(NGX_LOG_DEBUG_HTTP,
> log, 0, "%s", r->uri.data)) I see some extra data printed.
>
> For eg. when http://localhost/test is requested, "/test HTTP/1.1 Host" is
> printed.
>
> In my understanding "uri.data" should have contained only "/test". The
> "uri.len" correctly shows the length as 5. The "data" member is unsigned
> char *data so while extracting the actual string do we need to consider the
> length in ngx_str_t ?

The %s format suggests that the string is null-terminated, which is not the
case for r->uri.data. There's a special format %V for printing ngx_str_t:

ngx_log_debug1(NGX_LOG_DEBUG_HTTP, log, 0, "%V", &r->uri);

For more information on ngx_str_t, see the dev guide:

http://nginx.org/en/docs/dev/development_guide.html#strings

> Posted at Nginx Forum: https://forum.nginx.org/read.php?2,285729,285729#msg-285729
>
> _______________________________________________
> nginx mailing list
> nginx@nginx.org
> http://mailman.nginx.org/mailman/listinfo/nginx

--
Roman Arutyunyan
_______________________________________________
nginx mailing list
nginx@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx
Subject Author Posted

understanding ngx_str_t structure

astre September 27, 2019 05:44AM

Re: understanding ngx_str_t structure

Roman Arutyunyan September 27, 2019 06:16AM

Re: understanding ngx_str_t structure

astre September 27, 2019 06:51AM

Re: understanding ngx_str_t structure

Roman Arutyunyan September 27, 2019 07:06AM

Re: understanding ngx_str_t structure

astre September 27, 2019 07:17AM

Re: understanding ngx_str_t structure

Roman Arutyunyan September 27, 2019 07:32AM

Re: understanding ngx_str_t structure

astre September 27, 2019 07:53AM



Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 200
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready