Score:0

Why is request argument not returned in response?

ye flag

I'm trying to match a location url to this format /v1/images/{path1}/fetch?imageUrl={imageUrl} and I managed to do so with this snippet of code

location ~ ^/v1/images/(?<path1>[^/]+)/fetch {
    if ($args ~* "imageUrl=.*") {
      set $path1 $arg_path1;
      set_sha1 $variable $arg_imageUrl;
      set $imageUrl "https://testing.com/test/images/$variable/$path1.$image_ext";
      return 200 $imageUrl;
      add_header Content-Type text/plain;
      proxy_pass $imageUrl;
      access_log /etc/nginx/conf.d/log_file.log traffic;
    }
  }

But, I'm supposed to have a value for the path1 variable here returned in the response, but I don't get anything. I'm not sure why it's not being returned here, as it's part of the request too. Am I doing something wrong ?

Richard Smith avatar
jp flag
You are overwriting the `$path1` variable. This variable is created by the regular expression, then you overwrite it with the value of `$arg_path1` (which does not exist). Remove the `set $path1 $arg_path1;` line.
Score:0
kz flag

It seems that your Nginx configuration is missing the part that returns the value of the path1 variable in the response. You can add the add_header directive to include the path1 variable in the response header.

Example:

location ~ ^/v1/images/(?<path1>[^/]+)/fetch {
  if ($args ~* "imageUrl=.*") {
    set $path1 $arg_path1;
    set_sha1 $variable $arg_imageUrl;
    set $imageUrl "https://testing.com/test/images/$variable/$path1.$image_ext";
    add_header X-Path1 $path1; # add this line to include path1 in the response header
    return 200 $imageUrl;
    add_header Content-Type text/plain;
    proxy_pass $imageUrl;
    access_log /etc/nginx/conf.d/log_file.log traffic;
  }
}

I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.