Skip to content

Commit

Permalink
gh-16 Add initial timeout support
Browse files Browse the repository at this point in the history
Preliminary support added for timeouts on HTTP requests. Usage is via
.req.timeout function e.g.

q).req.timeout[5;`GET;"http://httpbin.org/delay/10";()!();()]
'timeout
  [0]  .req.timeout[5;`GET;"http://httpbin.org/delay/10";()!();()]
       ^
q).req.timeout[5;`GET;"http://httpbin.org/delay/3";()!();()]
`HTTP/1.1 200 OK`Connection`Server`Date`Content-Type`Content-Length`Access-Co..
"{\n  \"args\": {}, \n  \"data\": \"\", \n  \"files\": {}, \n  \"form\": {}, ..
  • Loading branch information
jonathonmcmurray committed Oct 11, 2018
1 parent 2f7b8ce commit 8c93054
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions req.q
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,13 @@ parseresp:{[r]
:$[(`j in key`)&r[0][`$"Content-Type"]like .h.ty[`json],"*";.j.k;] r[1]; //check for JSON, parse if so
}

timeout:{[t;m;u;hd;p]
ot:system"T";system"T ",string t; //store old timeout & set new
r:@[0;(`.req.send;m;u;hd;p;VERBOSE);{x}]; //send request & trap error
system"T ",string ot; //reset timeout
:$[r~"stop";'"timeout";r]; //return or signal
}

.req.get:{parseresp okstatus[VERBOSE] send[`GET;x;y;();VERBOSE]} //get - projection with no payload & GET method
.req.g:.req.get[;()!()] //simple get, no custom headers
.req.post:{parseresp okstatus[VERBOSE] send[`POST;x;y;z;VERBOSE]} //post - project with POST method
Expand Down

0 comments on commit 8c93054

Please sign in to comment.