Skip to content

Commit

Permalink
added proxy; fix for parsing url
Browse files Browse the repository at this point in the history
  • Loading branch information
ikod committed Apr 29, 2016
1 parent 0a31204 commit 2c8f58f
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 4 deletions.
6 changes: 6 additions & 0 deletions debian/changelog
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
dlang-requests (0.0.7-0) unstable; urgency=low

* added proxy; fix for parsing url

-- igor <igor.khasilev@gmail.com> Tue, 29 Apr 2016 12:11:22 -0400

dlang-requests (0.0.6-0) unstable; urgency=low

* Initial release (Closes: #nnnn) <nnnn is the bug number of your ITP>
Expand Down
20 changes: 17 additions & 3 deletions source/requests/http.d
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,7 @@ public struct Request {
uint __verbosity = 0; // 0 - no output, 1 - headers, 2 - headers+body info
DataPipe!ubyte __bodyDecoder;
DecodeChunked __unChunker;
string __proxy;
}

mixin(getter("keepAlive"));
Expand All @@ -385,6 +386,7 @@ public struct Request {
mixin(setter("bufferSize"));
mixin(getter("verbosity"));
mixin(setter("verbosity"));
mixin(setter("proxy"));

this(string uri) {
__uri = URI(uri);
Expand Down Expand Up @@ -425,6 +427,9 @@ public struct Request {
}

@property string requestString(string[string] params = null) {
if ( __proxy ) {
return "%s %s HTTP/1.1\r\n".format(__method, __uri.uri);
}
if ( __method != "GET" ) {
// encode params into url only for GET
return "%s %s HTTP/1.1\r\n".format(__method, __uri.path);
Expand Down Expand Up @@ -584,12 +589,20 @@ public struct Request {
void setupConnection() {
if ( !__stream || !__stream.isConnected ) {
tracef("Set up new connection");
final switch (__uri.scheme) {
URI uri;
if ( __proxy ) {
// use proxy uri to connect
uri.uri_parse(__proxy);
} else {
// use original uri
uri = __uri;
}
final switch (uri.scheme) {
case "http":
__stream = new TCPSocketStream().connect(__uri.host, __uri.port, __timeout);
__stream = new TCPSocketStream().connect(uri.host, uri.port, __timeout);
break;
case "https":
__stream = new SSLSocketStream().connect(__uri.host, __uri.port, __timeout);
__stream = new SSLSocketStream().connect(uri.host, uri.port, __timeout);
break;
}
} else {
Expand Down Expand Up @@ -1178,6 +1191,7 @@ unittest {
assert(rs.code==200);
// rq = Request();
rq.keepAlive = 5;
// rq.proxy = "http://localhost:8888/";
rs = rq.get("http://httpbin.org/absolute-redirect/2");
assert(rs.history.length == 2);
assert(rs.code==200);
Expand Down
4 changes: 3 additions & 1 deletion source/requests/uri.d
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,9 @@ struct URI {
if ( path_and_query.length ) {
i = path_and_query.findSplit("?");
__path = "/" ~ i[0];
__query = "?" ~ i[2];
if ( i[2].length) {
__query = "?" ~ i[2];
}
}
//
return true;
Expand Down

0 comments on commit 2c8f58f

Please sign in to comment.