micha / resty

Little command line REST client that you can use in pipelines (bash or zsh).
MIT License
2.65k stars 143 forks source link

urls inside urls #31

Closed dlight closed 6 years ago

dlight commented 12 years ago

I use urls as my couchdb keys (maybe this is dumb, but nevermind). so I need to do things like

PUT "/$url"

with resty.

You say on your documentation that I need to escape /; all the rest, resty will handle. I substituted / to %2F on $url. but it saves with %2F on the key name, not /; somehow resty is also escaping %, where it shouldn't.

PUT '/http:%2F%2Fwww.test.com' '{"a": 5}' {"ok":true,"id":"http:%2F%2Fwww.test.com","rev":"1-8bf226e57847cf49b0d45065383cf323"}

(should return "id":"http://www.test.com")

sending unescaped obviously doesn't help

PUT '/http://www.test.com' '{"a": 5}' {"ok":true,"id":"http:","rev":"1-c04faa654c092ab691c6d82f2b57f90d"}

you say -Q prevents escaping. but then somehow www.test.com is saved as an attachment

PUT -Q '/http:%2F%2Fwww.test.com' '{"a": 5}' {"ok":true,"id":"http:","rev":"1-38668c8ceb94ab26818d36f8139af49c"} GET '/http:' {"_id":"http:","_rev":"1-38668c8ceb94ab26818d36f8139af49c","_attachments":{"www.test.com":{"content_type":"application/octet-stream","revpos":1,"length":0,"stub":true}}}

unfortunately your -v shows the curl response, but not the curl command line. I was able to see it using an (ugly) custom debug. then I figured out a workaround for my case:

curl -X PUT "http://127.0.0.1/dbname/$urlwithslashesescaped" -d "$newdoc"

so, long story short, after struggling with resty for a while, I opted to use curl directly for this request (but I'm still using resty for my other requests)

I know my case is edgy so I don't know what your tool could do for me. I produced a patch that shows curl command line with resty -v

ps: this resty tool (and jsawk) is awesome!

From 94b608b03473f2a84eb36f7314f6612611fea563 Mon Sep 17 00:00:00 2001
From: Elias Amaral <tolkiendili@gmail.com>
Date: Fri, 23 Dec 2011 23:25:35 -0300
Subject: [PATCH] adding curl command line to resty -v

---
 resty |    3 +++
 1 files changed, 3 insertions(+), 0 deletions(-)

diff --git a/resty b/resty
index 231155f..6111db2 100755
--- a/resty
+++ b/resty
@@ -82,6 +82,9 @@ function resty() {
       [ -n "$dat" ] && opt="--data-binary"
       [ "$method" = "HEAD" ] && opt="-I" && raw="yes"
       eval "args2=( $(cat "$confdir/$domain" 2>/dev/null |sed 's/^ *//' |grep ^$method |cut -b $((${#method}+2))-) )"
+   [[ $verbose ]] && echo curl -sLv $opt "$dat" -X $method \
+              -b "$cookies/$domain" -c "$cookies/$domain" \
+              "${args2[@]}" "${curlopt2[@]}" "${curlopt[@]}" "$_path$query" $'\n' 1>&2
       res=$((((curl -sLv $opt "$dat" -X $method \
               -b "$cookies/$domain" -c "$cookies/$domain" \
               "${args2[@]}" "${curlopt2[@]}" "${curlopt[@]}" "$_path$query" \
-- 
1.7.5.4
AdrieanKhisbe commented 6 years ago

Yo Dowg

Thanks for the patch. Now with the option --dry-run you can output the command that us given to curl.

For supporting Not sure I want to hack around for this very specific edge case. But if you came out with a solution I would welcome a PR with pleasure. :)

By the way Sorry for the long answer time :/