Skip to content

Commit

Permalink
remove any calls to httpbin.org
Browse files Browse the repository at this point in the history
  • Loading branch information
iklfst committed May 12, 2023
1 parent 43a3478 commit b524d8a
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 19 deletions.
6 changes: 6 additions & 0 deletions source/requests/httpbin.d
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ version (httpbin)
import std.conv;
import std.range;
import std.string;
import std.stdio;
import core.thread;
import std.experimental.logger;

Expand Down Expand Up @@ -54,6 +55,10 @@ version (httpbin)
rs.headers["Content-Type"] = "application/json";
return rs;
}
auto anything(in App app, ref HTTPD_Request rq, RequestArgs args) {
auto rs = response(rq, buildReply(rq));
return rs;
}
auto get(in App app, ref HTTPD_Request rq, RequestArgs args) {
debug (httpd) trace("handler /get called");
auto rs = response(rq, buildReply(rq));
Expand Down Expand Up @@ -187,6 +192,7 @@ version (httpbin)
return rs;
}
server.addRoute(exactRoute(r"/", &root)).
addRoute(regexRoute(r"/anything", &anything)).
addRoute(exactRoute(r"/get", &get)).
addRoute(exactRoute(r"/post", &post)).
addRoute(exactRoute(r"/delete", &del)).
Expand Down
35 changes: 16 additions & 19 deletions source/requests/package.d
Original file line number Diff line number Diff line change
Expand Up @@ -442,6 +442,21 @@ package unittest {
rq.timeout = 1.seconds;
assertThrown!TimeoutException(rq.get(httpbinUrl ~ "delay/3"));

info("Test ByLine interfaces");
auto rsp = getContentByLine(httpbinUrl ~ "stream/50");
assert(rsp.count == 50);
rsp = getContentByLine(httpbinUrl ~ "stream/0");
assert(rsp.count == 0);
rsp = getContentByLine(httpbinUrl ~ "anything", ["1":"1"]);
assert(rsp.map!"cast(string)a".filter!(a => a.canFind("data")).count == 1);
rsp = getContentByLine(httpbinUrl ~ "anything", queryParams("1","1"));
assert(rsp.map!"cast(string)a".filter!(a => a.canFind("data")).count == 1);
rsp = postContentByLine(httpbinUrl ~ "anything", "123");
assert(rsp.map!"cast(string)a".filter!(a => a.canFind("data")).count == 1);
rsp = putContentByLine(httpbinUrl ~ "anything", "123");
assert(rsp.map!"cast(string)a".filter!(a => a.canFind("data")).count == 1);


info("Test get in parallel");
{
import std.stdio;
Expand Down Expand Up @@ -609,22 +624,4 @@ public auto patchContent(A...)(string url, A args) {
auto rq = Request();
auto rs = rq.patch(url, args);
return rs.responseBody;
}

unittest
{
import std.algorithm;
info("Test ByLine interfaces");
auto r = getContentByLine("https://httpbin.org/stream/50");
assert(r.count == 50);
r = getContentByLine("https://httpbin.org/stream/0");
assert(r.count == 0);
r = getContentByLine("https://httpbin.org/anything", ["1":"1"]);
assert(r.map!"cast(string)a".filter!(a => a.canFind("data")).count == 1);
r = getContentByLine("https://httpbin.org/anything", queryParams("1","1"));
assert(r.map!"cast(string)a".filter!(a => a.canFind("data")).count == 1);
r = postContentByLine("https://httpbin.org/anything", "123");
assert(r.map!"cast(string)a".filter!(a => a.canFind("data")).count == 1);
r = putContentByLine("https://httpbin.org/anything", "123");
assert(r.map!"cast(string)a".filter!(a => a.canFind("data")).count == 1);
}
}

0 comments on commit b524d8a

Please sign in to comment.