I am using Squid 3.5 using the logformat attribute.
I would like to add double quotes around a field. The documentation states the following:
% ["|[|'|#] [-] [[0]width] [{argument}] formatcode
" output in quoted string format
[ output in squid text log format as used by log_mime_hdrs
# output in URL quoted format
' output as-is
I have tried the following and various other things:
logformat some someId=%"{someID}>h
access_log /some/path some
but I am unable to get the value of someID to be in double qoutes. Where am I going wrong? The documentation is not very clear and I can't find any examples of using the double quotes.
It was simple as:
logformat some someId="%{someID}>h"
access_log /some/path some
This worked for me.
Related
I'm trying to write this redirection
images/catalog/1002/10002/main-200x250.12345.jpg to url images/catalog/1002/10002/main.jpg?w=200&h=250&vw=main
I tried this rule:
rewrite "^/images/(.*)/([a-z0-9]+)-([0-9])x([0-9]).([0-9]{5}).(jpg|jpeg|png|gif|ico)$" /images/$1/$2.$6?w=$3&h=$4&vw=$2 break;
It is not working, it return 404 not found error. I don't know what I'm missing.
Also when I remove double quotes (") I got this error
directive "rewrite" is not terminated by ";"
And I don't clear see the utility of the sign " and when should I use it or avoid it
I m working on a Mac with MAMP Pro v 5.2.2
You forgot to add a quantifier for the width and height numbers in your regex. Try this (I added a twice a +, you might want to use {X} instead, where X is the amount of digits for each number (if it is always the same amount of digits)):
rewrite "^/images/(.*)/([a-z0-9]+)-([0-9]+)x([0-9]+).([0-9]{5}).(jpg|jpeg|png|gif|ico)$" /images/$1/$2.$6?w=$3&h=$4&vw=$2 break;
Your reqular expression needs to be quoted because there is a } in it.
I think the nginx documentation about rewrite directive will answer your question, when a regular expression needs to be quoted:
If a regular expression includes the “}” or “;” characters, the whole
expressions should be enclosed in single or double quotes.
I'm currently writing my CSP policy in NGINX and I need to provide a report-uri that has the special character ; in it. Notice that ; is valid for an URI path.
default-src: 'self'; report-uri: /;index
However, the ; doesn't get recognized as a valid character and so I'm getting following error in my browsers (Chrome) console:
Unrecognized Content-Security-Policy directive 'index'.
Is there any way to escape the character or wrap the URI inside a string (inside the header string)? I already tried \; and single quote wrapping (I'm using double quotes to wrap the header content).
You need to percent-encode the semicolon as %3B. The CSP spec has the following note:
Note: Characters like U+003B SEMICOLON (;) and U+002C COMMA (,) cannot appear in source expressions directly: if you’d like to include these characters in a source expression, they must be percent encoded as %3B and %2C respectively.
So the CSP policy shown in the question should instead be written like this:
default-src: 'self'; report-uri: /%3Bindex
I'm using the proxy_cookie_domain directive, and the docs say I should be able to use regex:
The directive can also be specified using regular expressions. In this
case, domain should start from the “~” symbol. A regular expression
can contain named and positional captures, and replacement can
reference them:
proxy_cookie_domain ~\.(?P<sl_domain>[-0-9a-z]+\.[a-z]+)$ $sl_domain
How do I use regex to replace every instance of example.com with mydomain.com, e.g.:
anything.example.com with anything.mydomain.com
any.thing.example.com with any.thing.mydomain.com
literally.any.thing.example.com with literally.any.thing.mydomain.com
And so on...
Turns out nginx uses the PRCE flavor of regex, which you can play with at regex101
Here's my what I came up with
proxy_cookie_domain ~\.((?<cookie_pre>.*)example.com)$ "${cookie_pre}mydomain.com";
I had a rewrite rule on Apache for /year/month/date links in a form that specifically defined 4 digits, then 2 digits, then 2 digits, that looked like this:
^([0-9]{4})/([0-9]{2})/([0-9]{2})/$
On nginx this regex causes an error that says the whole line is not terminated by a ; sign, until i remove the {} brackets and leave the regex like this:
^/([0-9]+)/([0-9]+)/([0-9]+)/$
Is this limitation intentional on nginx's part or some mistake on my part?
The whole line from Apache:
RewriteRule ^([0-9]{4})/([0-9]{2})/([0-9]{2})/$ index.php?page=date&year=$1&month=$2&day=$3
The whole (working) line from nginx:
rewrite ^/([0-9]+)/([0-9]+)/([0-9]+)/$ /index.php?page=date&year=$1&month=$2&day=$3;
If a regular expression includes the “}” or “;” characters, the whole expressions should be enclosed in single or double quotes.
http://nginx.org/en/docs/http/ngx_http_rewrite_module.html#rewrite
Windows copies path with backslash \, which R does not accept. So, I wanted to write a function which would convert \ to /. For example:
chartr0 <- function(foo) chartr('\','\\/',foo)
Then use chartr0 as...
source(chartr0('E:\RStuff\test.r'))
But chartr0 is not working. I guess, I am unable to escape /. I guess escaping / may be important in many other occasions.
Also, is it possible to avoid the use chartr0 every time, but convert all path automatically by creating an environment in R which calls chartr0 or use some kind of temporary use like using options
From R 4.0.0 you can use r"(...)" to write a path as raw string constant, which avoids the need for escaping:
r"(E:\RStuff\test.r)"
# [1] "E:\\RStuff\\test.r"
There is a new syntax for specifying raw character constants similar to the one used in C++: r"(...)" with ... any character sequence not containing the sequence )". This makes it easier to write strings that contain backslashes or both single and double quotes. For more details see ?Quotes.
Your fundamental problem is that R will signal an error condition as soon as it sees a single back-slash before any character other than a few lower-case letters, backslashes themselves, quotes or some conventions for entering octal, hex or Unicode sequences. That is because the interpreter sees the back-slash as a message to "escape" the usual translation of characters and do something else. If you want a single back-slash in your character element you need to type 2 backslashes. That will create one backslash:
nchar("\\")
#[1] 1
The "Character vectors" section of _Intro_to_R_ says:
"Character strings are entered using either matching double (") or single (') quotes, but are printed using double quotes (or sometimes without quotes). They use C-style escape sequences, using \ as the escape character, so \ is entered and printed as \, and inside double quotes " is entered as \". Other useful escape sequences are \n, newline, \t, tab and \b, backspace—see ?Quotes for a full list."
?Quotes
chartr0 <- function(foo) chartr('\\','/',foo)
chartr0('E:\\RStuff\\test.r')
You cannot write E:\Rxxxx, because R believes R is escaped.
The problem is that every single forward slash and backslash in your code is escaped incorrectly, resulting in either an invalid string or the wrong string being used. You need to read up on which characters need to be escaped and how. Take a look at the list of escape sequences in the link below. Anything not listed there (such as the forward slash) is treated literally and does not require any escaping.
http://cran.r-project.org/doc/manuals/R-lang.html#Literal-constants