Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Comparing changes

Choose two branches to see what's changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
base fork: esromneb/dart-cors-proxy
base: f7d0adaa94
...
head fork: esromneb/dart-cors-proxy
compare: b160714895
Checking mergeability… Don't worry, you can still create the pull request.
  • 2 commits
  • 1 file changed
  • 0 commit comments
  • 1 contributor
Showing with 56 additions and 7 deletions.
  1. +56 −7 corsProxy.dart
View
63 corsProxy.dart
@@ -1,17 +1,27 @@
#import("dart:io");
#import("dart:uri");
#import("dart:utf");
+#source("auth.dart");
-final String GETURL = "";
-final String AUTH = "";
final HOST = "127.0.0.1";
-final PORT = 8080;
+final PORT = 5555;
final LOG_REQUESTS = true;
-void httpGet()
+
+/*
+
+ response.addHeader("Access-Control-Allow-Origin", "*");
+ response.addHeader("Access-Control-Allow-Methods", "OPTIONS, " + allowedMethods );
+ response.addHeader("Access-Control-Allow-Headers", "Content-Type, Accept, X-Request-With");
+ response.addHeader("Access-Control-Max-Age", "86400");
+
+*/
+
+void httpGet(HttpResponse inputResponse)
{
+
HttpClient h = new HttpClient();
HttpClientConnection conn = h.getUrl(new Uri.fromString(GETURL));
@@ -34,20 +44,59 @@ void httpGet()
InputStream i = response.inputStream;
+
+ i.pipe(inputResponse.outputStream);
+ /*
i.onData = () {
print(codepointsToString(i.read()));
};
i.onClosed = () {
print("Closed");
- };
+ };*/
};
+
+
+
}
-void main() {
+
+void requestReceivedHandler(HttpRequest inputRequest, HttpResponse inputResponse) {
+
+ //inputResponse.headers.set(HttpHeaders.CONTENT_TYPE, "text/html; charset=UTF-8");
+
+ inputResponse.headers.set("Access-Control-Allow-Origin", "*");
+ inputResponse.headers.set("Access-Control-Allow-Methods", "OPTIONS, GET, PUT, POST, DELETE");
+ inputResponse.headers.set("Access-Control-Allow-Headers", "Content-Type, Accept, X-Request-With");
+ inputResponse.headers.set("Access-Control-Max-Age", "86400");
+
- httpGet();
+ if (LOG_REQUESTS) {
+ print("Request: ${inputRequest.method} ${inputRequest.uri}");
+ }
+
+ httpGet(inputResponse);
+
+
+
+ // String htmlResponse = createHtmlResponse();
+ //response.outputStream.writeString(htmlResponse);
+ //response.outputStream.close();
+}
+
+
+void main() {
+
+HttpServer server = new HttpServer();
+
+ server.addRequestHandler((HttpRequest request) => true, requestReceivedHandler);
+
+ server.listen(HOST, PORT);
+
+ print("Serving the current time on http://${HOST}:${PORT}.");
+
print("Hello World");
}
+

No commit comments for this range

Something went wrong with that request. Please try again.