From dbd1e0a849f3d3e7037d3d651e7b626a7fc49fad Mon Sep 17 00:00:00 2001 From: Eduardo Julian Date: Sat, 27 Apr 2019 09:44:59 -0400 Subject: Got rid of the half-baked HTTP client machinery. --- stdlib/source/lux/world/net/http/client.lux | 87 ----------------------------- 1 file changed, 87 deletions(-) delete mode 100644 stdlib/source/lux/world/net/http/client.lux (limited to 'stdlib') diff --git a/stdlib/source/lux/world/net/http/client.lux b/stdlib/source/lux/world/net/http/client.lux deleted file mode 100644 index dfef02f3f..000000000 --- a/stdlib/source/lux/world/net/http/client.lux +++ /dev/null @@ -1,87 +0,0 @@ -(.module: - [lux #* - [control - ["." monad (#+ do)] - [concurrency - ["." promise] - ["." frp (#+ Channel Sink)]]] - [data - ["." error] - [format - ["." context]] - [collection - ["." dictionary]]] - [tool - [compiler - ["." host]]] - ["." io (#+ IO)] - [host (#+ import:)]] - ["." // (#+ Data Client) - [// (#+ URL)]]) - -## TODO: This is unfinished work. Things like headers and cookies are missing. -(`` (for {(~~ (static host.old)) - (as-is (import: #long java/lang/String) - - (import: #long java/io/Flushable - (flush [] #io #try void)) - - (import: #long java/lang/AutoCloseable - (close [] #io #try void)) - - (import: #long java/io/OutputStream - (write [(Array byte)] #io #try void)) - - (import: #long java/net/URLConnection - (setRequestProperty [java/lang/String java/lang/String] #io #try void) - (setDoOutput [boolean] #io #try void) - (getOutputStream [] #io #try java/io/OutputStream) - (connect [] #io #try void)) - - (import: #long java/net/HttpURLConnection - (setRequestMethod [java/lang/String] #io #try void) - (disconnect [] #io #try void) - (getResponseCode [] #io #try int)) - - (import: #long java/net/URL - (new [java/lang/String]) - (openConnection [] #io #try java/net/URLConnection)))} - )) - -(def: #export (request [method url headers body]) - Client - (`` (for {(~~ (static host.old)) - (promise.future - (do (error.with io.monad) - [conn (java/net/URL::openConnection (java/net/URL::new url)) - #let [conn (:coerce java/net/HttpURLConnection conn)] - _ (java/net/HttpURLConnection::setRequestMethod (case method - #//.Post "POST" - #//.Get "GET" - #//.Put "PUT" - #//.Patch "PATCH" - #//.Delete "DELETE" - #//.Head "HEAD" - #//.Connect "CONNECT" - #//.Options "OPTIONS" - #//.Trace "TRACE") - conn) - _ (|> headers - dictionary.entries - (monad.map @ (function (_ [name value]) - (java/net/URLConnection::setRequestProperty name value conn)))) - _ (java/net/URLConnection::setDoOutput true conn) - sink (java/net/URLConnection::getOutputStream conn) - _ (java/io/OutputStream::write body sink) - _ (java/io/Flushable::flush sink) - _ (java/lang/AutoCloseable::close sink) - _ (java/net/URLConnection::connect conn) - status (java/net/HttpURLConnection::getResponseCode conn) - #let [[channel source] (: [(Channel Data) (Sink Data)] - (frp.channel []))] - _ (:: source close) - _ (java/net/HttpURLConnection::disconnect conn)] - (wrap [(.nat status) - {#//.headers context.empty - #//.body channel}])))} - ))) -- cgit v1.2.3