-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
SSHTunneledBaseClient parses HTTP headers
- Loading branch information
1 parent
6749af4
commit 428acf0
Showing
7 changed files
with
225 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
// Copyright 2019 dartssh developers | ||
// Use of this source code is governed by a MIT-style license that can be found in the LICENSE file. | ||
|
||
import 'dart:async'; | ||
import 'dart:html' as html; | ||
|
||
import 'package:dartssh/http.dart'; | ||
import 'package:dartssh/transport.dart'; | ||
|
||
/// dart:html based alternative [HttpClient] implementation. | ||
class HttpClientImpl extends HttpClient { | ||
static const String type = 'html'; | ||
HttpClientImpl({StringCallback debugPrint, StringFilter userAgent}) | ||
: super(debugPrint); | ||
|
||
@override | ||
Future<HttpResponse> request(String url, {String method, String data}) { | ||
numOutstanding++; | ||
Completer<HttpResponse> completer = Completer<HttpResponse>(); | ||
html.HttpRequest.request(url, method: method).then((r) { | ||
numOutstanding--; | ||
completer.complete(HttpResponse(r.status, r.responseText)); | ||
}); | ||
return completer.future; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
// Copyright 2019 dartssh developers | ||
// Use of this source code is governed by a MIT-style license that can be found in the LICENSE file. | ||
|
||
import 'dart:async'; | ||
import 'dart:convert'; | ||
import 'dart:io' as io; | ||
|
||
import 'package:dartssh/http.dart'; | ||
import 'package:dartssh/transport.dart'; | ||
|
||
/// dart:io based alternative [HttpClient] implementation. | ||
class HttpClientImpl extends HttpClient { | ||
static const String type = 'io'; | ||
io.HttpClient client = io.HttpClient(); | ||
|
||
HttpClientImpl({StringCallback debugPrint, StringFilter userAgent}) | ||
: super(debugPrint) { | ||
if (userAgent != null) client.userAgent = userAgent(client.userAgent); | ||
} | ||
|
||
@override | ||
Future<HttpResponse> request(String url, {String method, String data}) async { | ||
numOutstanding++; | ||
|
||
Uri uri = Uri.parse(url); | ||
var request; | ||
switch (method) { | ||
case 'POST': | ||
request = await client.postUrl(uri); | ||
break; | ||
|
||
default: | ||
request = await client.getUrl(uri); | ||
break; | ||
} | ||
|
||
if (debugPrint != null) debugPrint('HTTP Request: ${request.uri}'); | ||
var response = await request.close(); | ||
HttpResponse ret = HttpResponse(response.statusCode); | ||
await for (var contents in response.transform(Utf8Decoder())) { | ||
if (ret.text == null) { | ||
ret.text = contents; | ||
} else { | ||
ret.text += contents; | ||
} | ||
} | ||
|
||
if (debugPrint != null) { | ||
debugPrint('HTTP Response=${ret.status}: ${ret.text}'); | ||
} | ||
numOutstanding--; | ||
return ret; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters