Support $'...' strings
MikhailKlemin opened this issue · 9 comments
Hi, I just getting blank header when I use proposed os.ExpandEnv("$Cookie"), if I try without it (ie just setting req.Header.Set("Cookie","cookies;values;")
the request does not work, while curl works.
Huh? Can you give the full code you're talking about? (Also, you shouldn't put dollar signs in the env variable)
Hi, if you try this example
curl 'http://hello.world' -H 'Pragma: no-cache' -H 'Accept-Encoding: gzip, deflate' -H 'Accept-Language: en-US,en;q=0.8,ru;q=0.6' -H 'User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/60.0.3112.90 Safari/537.36' -H 'Accept: application/json, text/javascript, */*; q=0.01' -H 'X-Requested-With: XMLHttpRequest' -H $'Cookie: dt=desktop;bb=ok' -H 'Connection: keep-alive' -H 'Cache-Control: no-cache' --compressed
it will produce
// Generated by curl-to-Go: https://mholt.github.io/curl-to-go
req, err := http.NewRequest("GET", "http://hello.world", nil)
if err != nil {
// handle err
}
req.Header.Set("Pragma", "no-cache")
req.Header.Set("Accept-Encoding", "gzip, deflate")
req.Header.Set("Accept-Language", "en-US,en;q=0.8,ru;q=0.6")
req.Header.Set("User-Agent", "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/60.0.3112.90 Safari/537.36")
req.Header.Set("Accept", "application/json, text/javascript, */*; q=0.01")
req.Header.Set("X-Requested-With", "XMLHttpRequest")
req.Header.Set(os.ExpandEnv("$Cookie"), "dt=desktop;bb=ok")
req.Header.Set("Connection", "keep-alive")
req.Header.Set("Cache-Control", "no-cache")
resp, err := http.DefaultClient.Do(req)
if err != nil {
// handle err
}
defer resp.Body.Close()
I see.
What is this?
-H $'Cookie: dt=desktop; ot=i1-prod-ch3-vX-; ak_bmsc=1223C7D9C7E5F885E8B843718B9AE46C0215F0324F1F00002E1A8B5907626020~plP2QFS0l+Q+wpta/wQsNTUjnped8/f9DCGHeZJT7wmGvLpzGRgZVCSvTgWs5PW6DiIQ5x7fVQkpKa7ggY1bRTZS6a3aycJrwCKvCz1+jyJBZP3PNNASPEehU4VFdFZtP4Xj2MQwBnSZXRHSd5jhPkflUXzv/2DsN1/gocxCuW+gfwTX9uG654/bPy+Xu3bp6gOFmtb6+tVcjZ26ovKKPniN9u1i6PsmOSymZqOpGKXv0=;'
The dollar sign before the string is unfamiliar to me.
This is also not familiar for me, but this is what Chrome gives, if I copy request as CURL from inspector. Then if I paste it into Terminal, I receive correct response...
Okay, googling it says the dollar sign before single quoted string causes escape sequences to be interpreted. I suppose this tool needs to consider that...
http://www.gnu.org/software/bash/manual/html_node/ANSI_002dC-Quoting.html#ANSI_002dC-Quoting
Words of the form $'string' are treated specially. The word expands to string, with backslash-escaped characters replaced as specified by the ANSI C standard. Backslash escape sequences, if present, are decoded as follows: ...
oh, I was looking into curl docs, and didn't find anything, but silly me -- was looking wrong place.
May be possible to leave it as future request? I would not propose if not Chrome Inspector use such quoting for curl (sometimes)..
Yeah, it's fine, I'll get this fixed sooner or later.
Here is a stackoverflow question that would benefit from this feature: https://stackoverflow.com/questions/51233437/what-is-the-equivalent-of-http-request-using-curl-data-binary-string-in-go