Browse files

added -Q option

  • Loading branch information...
1 parent feca98c commit a4c323916fd9a51710b2a283e4d75656a3ea7001 @micha committed Apr 29, 2011
Showing with 34 additions and 16 deletions.
  1. +5 −2 resty
  2. +3 −0 test/tests
  3. +26 −14 test/tests.out
View
7 resty
@@ -14,7 +14,7 @@ export _resty_path=""
export _resty_nohistory=""
function resty() {
- local confdir host cookies method h2t editor domain _path opt dat res ret out err verbose raw i j d tmpf args2 wantdata vimedit
+ local confdir host cookies method h2t editor domain _path opt dat res ret out err verbose raw i j d tmpf args2 wantdata vimedit quote
local -a curlopt
local -a curlopt2
@@ -30,7 +30,7 @@ function resty() {
[ -d "$cookies" ] || (mkdir -p "$cookies"; echo "http://localhost*" > "$host")
[ -n "$1" ] && [ "${1#/}" != "$1" ] \
- && _path=$(echo "$1"|sed 's/%/%25/g;s/\[/%5B/g;s/\]/%5D/g;s/|/%7C/g;s/\$/%24/g;s/&/%26/g;s/+/%2B/g;s/,/%2C/g;s/:/%3A/g;s/;/%3B/g;s/=/%3D/g;s/?/%3F/g;s/@/%40/g;s/ /%20/g;s/#/%23/g;s/{/%7B/g;s/}/%7D/g;s/\\/%5C/g;s/\^/%5E/g;s/~/%7E/g;s/`/%60/g') && shift
+ && _path="$1" && shift
j=1
for i in "$@"; do
@@ -40,9 +40,12 @@ function resty() {
[ "$i" = "-Z" ] || [ "$method" = "HEAD" ] || [ "$method" = "OPTIONS" ] \
&& raw="yes" && continue
[ "$i" = "-W" ] && continue
+ [ "$i" = "-Q" ] && quote="yes" && continue
curlopt[j]="$i" && j=$((j + 1))
done
+ [ -z "$quote" ] && _path=$(echo "$_path"|sed 's/%/%25/g;s/\[/%5B/g;s/\]/%5D/g;s/|/%7C/g;s/\$/%24/g;s/&/%26/g;s/+/%2B/g;s/,/%2C/g;s/:/%3A/g;s/;/%3B/g;s/=/%3D/g;s/?/%3F/g;s/@/%40/g;s/ /%20/g;s/#/%23/g;s/{/%7B/g;s/}/%7D/g;s/\\/%5C/g;s/\^/%5E/g;s/~/%7E/g;s/`/%60/g')
+
[ -z "$_resty_host" ] && _resty_host=$(cat "$host" 2>/dev/null)
[ -z "$method" ] && echo "$_resty_host" && return
[ -n "$_path" ] && _resty_path=$_path
View
3 test/tests
@@ -60,3 +60,6 @@ resty 127.0.0.1:9090 2> /dev/null
# TEST 14: make sure the default options are correctly unset
GET /simple.json
+# TEST 15: try PUT with both data in body and query params in url
+echo '{"foo":"bar"}' |PUT '/simple.json?param=value&other=blah' -Q
+
View
40 test/tests.out
@@ -1,32 +1,32 @@
# [REQ] TEST 1: basic GET request
GET /simple.html HTTP/1.1
-User-Agent: curl/7.21.2 (x86_64-apple-darwin10.4.0) libcurl/7.21.2 OpenSSL/1.0.0d zlib/1.2.5 libidn/1.19
+User-Agent: curl/7.21.2 (x86_64-apple-darwin10.4.0) libcurl/7.21.2 OpenSSL/1.0.0d zlib/1.2.5 libidn/1.20
Host: 127.0.0.1:9090
Accept: */*
# [REQ] TEST 2: basic PUT request
PUT /simple.html HTTP/1.1
-User-Agent: curl/7.21.2 (x86_64-apple-darwin10.4.0) libcurl/7.21.2 OpenSSL/1.0.0d zlib/1.2.5 libidn/1.19
+User-Agent: curl/7.21.2 (x86_64-apple-darwin10.4.0) libcurl/7.21.2 OpenSSL/1.0.0d zlib/1.2.5 libidn/1.20
Host: 127.0.0.1:9090
Accept: */*
Content-Length: 17
Content-Type: application/x-www-form-urlencoded
here is some data
# [REQ] TEST 3: basic POST request
POST /simple.html HTTP/1.1
-User-Agent: curl/7.21.2 (x86_64-apple-darwin10.4.0) libcurl/7.21.2 OpenSSL/1.0.0d zlib/1.2.5 libidn/1.19
+User-Agent: curl/7.21.2 (x86_64-apple-darwin10.4.0) libcurl/7.21.2 OpenSSL/1.0.0d zlib/1.2.5 libidn/1.20
Host: 127.0.0.1:9090
Accept: */*
Content-Length: 17
Content-Type: application/x-www-form-urlencoded
here is some data
# [REQ] TEST 4: basic DELETE request
DELETE /simple.html HTTP/1.1
-User-Agent: curl/7.21.2 (x86_64-apple-darwin10.4.0) libcurl/7.21.2 OpenSSL/1.0.0d zlib/1.2.5 libidn/1.19
+User-Agent: curl/7.21.2 (x86_64-apple-darwin10.4.0) libcurl/7.21.2 OpenSSL/1.0.0d zlib/1.2.5 libidn/1.20
Host: 127.0.0.1:9090
Accept: */*
# [REQ] TEST 5: basic TRACE request
TRACE /simple.html HTTP/1.1
-User-Agent: curl/7.21.2 (x86_64-apple-darwin10.4.0) libcurl/7.21.2 OpenSSL/1.0.0d zlib/1.2.5 libidn/1.19
+User-Agent: curl/7.21.2 (x86_64-apple-darwin10.4.0) libcurl/7.21.2 OpenSSL/1.0.0d zlib/1.2.5 libidn/1.20
Host: 127.0.0.1:9090
Accept: */*
Content-Length: 17
@@ -41,16 +41,17 @@ Connection: close
Content-Length: 168
# [REQ] TEST 7: Raw response
GET /simple.html HTTP/1.1
-User-Agent: curl/7.21.2 (x86_64-apple-darwin10.4.0) libcurl/7.21.2 OpenSSL/1.0.0d zlib/1.2.5 libidn/1.19
+User-Agent: curl/7.21.2 (x86_64-apple-darwin10.4.0) libcurl/7.21.2 OpenSSL/1.0.0d zlib/1.2.5 libidn/1.20
Host: 127.0.0.1:9090
Accept: */*
# [REQ] TEST 8: Get headers too
* <url> malformed
+* <url> malformed
* About to connect() to 127.0.0.1 port 9090 (#0)
* Trying 127.0.0.1... connected
* Connected to 127.0.0.1 (127.0.0.1) port 9090 (#0)
> GET /simple.html HTTP/1.1
-> User-Agent: curl/7.21.2 (x86_64-apple-darwin10.4.0) libcurl/7.21.2 OpenSSL/1.0.0d zlib/1.2.5 libidn/1.19
+> User-Agent: curl/7.21.2 (x86_64-apple-darwin10.4.0) libcurl/7.21.2 OpenSSL/1.0.0d zlib/1.2.5 libidn/1.20
> Host: 127.0.0.1:9090
> Accept: */*
>
@@ -65,17 +66,17 @@ Accept: */*
{ [data not shown]
* Closing connection #0
GET /simple.html HTTP/1.1
-User-Agent: curl/7.21.2 (x86_64-apple-darwin10.4.0) libcurl/7.21.2 OpenSSL/1.0.0d zlib/1.2.5 libidn/1.19
+User-Agent: curl/7.21.2 (x86_64-apple-darwin10.4.0) libcurl/7.21.2 OpenSSL/1.0.0d zlib/1.2.5 libidn/1.20
Host: 127.0.0.1:9090
Accept: */*
# [REQ] TEST 9: POST with data sent in query string
POST /simple.html?foo=bar HTTP/1.1
-User-Agent: curl/7.21.2 (x86_64-apple-darwin10.4.0) libcurl/7.21.2 OpenSSL/1.0.0d zlib/1.2.5 libidn/1.19
+User-Agent: curl/7.21.2 (x86_64-apple-darwin10.4.0) libcurl/7.21.2 OpenSSL/1.0.0d zlib/1.2.5 libidn/1.20
Host: 127.0.0.1:9090
Accept: */*
# [REQ] TEST 10: POST with data sent in message body
POST /simple.html HTTP/1.1
-User-Agent: curl/7.21.2 (x86_64-apple-darwin10.4.0) libcurl/7.21.2 OpenSSL/1.0.0d zlib/1.2.5 libidn/1.19
+User-Agent: curl/7.21.2 (x86_64-apple-darwin10.4.0) libcurl/7.21.2 OpenSSL/1.0.0d zlib/1.2.5 libidn/1.20
Host: 127.0.0.1:9090
Accept: */*
Content-Length: 12
@@ -84,7 +85,7 @@ Content-Type: application/x-www-form-urlencoded
# [REQ] TEST 11: POST with extra header and basic auth, data in message body
POST /simple.html HTTP/1.1
Authorization: Basic dXNlcjpzZWNyZXQ=
-User-Agent: curl/7.21.2 (x86_64-apple-darwin10.4.0) libcurl/7.21.2 OpenSSL/1.0.0d zlib/1.2.5 libidn/1.19
+User-Agent: curl/7.21.2 (x86_64-apple-darwin10.4.0) libcurl/7.21.2 OpenSSL/1.0.0d zlib/1.2.5 libidn/1.20
Host: 127.0.0.1:9090
Accept: application/json
Content-Length: 66
@@ -94,14 +95,22 @@ Content-Type: application/x-www-form-urlencoded
# [REQ] TEST 13: make sure the default options are correctly set
GET /simple.json HTTP/1.1
Authorization: Basic dXNlcjpwYXNz
-User-Agent: curl/7.21.2 (x86_64-apple-darwin10.4.0) libcurl/7.21.2 OpenSSL/1.0.0d zlib/1.2.5 libidn/1.19
+User-Agent: curl/7.21.2 (x86_64-apple-darwin10.4.0) libcurl/7.21.2 OpenSSL/1.0.0d zlib/1.2.5 libidn/1.20
Host: 127.0.0.1:9090
Accept: application/json
# [REQ] TEST 14: make sure the default options are correctly unset
GET /simple.json HTTP/1.1
-User-Agent: curl/7.21.2 (x86_64-apple-darwin10.4.0) libcurl/7.21.2 OpenSSL/1.0.0d zlib/1.2.5 libidn/1.19
+User-Agent: curl/7.21.2 (x86_64-apple-darwin10.4.0) libcurl/7.21.2 OpenSSL/1.0.0d zlib/1.2.5 libidn/1.20
+Host: 127.0.0.1:9090
+Accept: */*
+# [REQ] TEST 15: try PUT with both data in body and query params in url
+PUT /simple.json?param=value&other=blah HTTP/1.1
+User-Agent: curl/7.21.2 (x86_64-apple-darwin10.4.0) libcurl/7.21.2 OpenSSL/1.0.0d zlib/1.2.5 libidn/1.20
Host: 127.0.0.1:9090
Accept: */*
+Content-Length: 14
+Content-Type: application/x-www-form-urlencoded
+{"foo":"bar"}
# [OUT] TEST 1: basic GET request
[1]fork me on github
@@ -348,11 +357,12 @@ Content-Length: 2340
</html>
# [OUT] TEST 8: Get headers too
* <url> malformed
+* <url> malformed
* About to connect() to 127.0.0.1 port 9090 (#0)
* Trying 127.0.0.1... connected
* Connected to 127.0.0.1 (127.0.0.1) port 9090 (#0)
> GET /simple.html HTTP/1.1
-> User-Agent: curl/7.21.2 (x86_64-apple-darwin10.4.0) libcurl/7.21.2 OpenSSL/1.0.0d zlib/1.2.5 libidn/1.19
+> User-Agent: curl/7.21.2 (x86_64-apple-darwin10.4.0) libcurl/7.21.2 OpenSSL/1.0.0d zlib/1.2.5 libidn/1.20
> Host: 127.0.0.1:9090
> Accept: */*
>
@@ -507,3 +517,5 @@ http://github.com/micha/resty
{"foo":[1,2,3],"bar":{"dog":"woof","cat":"meow","fish":"banana"}}
# [OUT] TEST 14: make sure the default options are correctly unset
{"foo":[1,2,3],"bar":{"dog":"woof","cat":"meow","fish":"banana"}}
+# [OUT] TEST 15: try PUT with both data in body and query params in url
+{"foo":[1,2,3],"bar":{"dog":"woof","cat":"meow","fish":"banana"}}

0 comments on commit a4c3239

Please sign in to comment.