Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 0 additions & 14 deletions src/async.mbt
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,6 @@
// See the License for the specific language governing permissions and
// limitations under the License.

///|
/// Create a fresh event loop and run a async program inside the loop.
/// A new task group will be created for convenience,
/// that is, `with_event_loop(f)` will run `with_task_group(f)` using the event loop.
///
/// There can only one event loop running for every program,
/// calling `with_event_loop` inside another event loop is invalid,
/// and will result in immediate failure.
#deprecated("use `async fn main` or `async test` instead")
#cfg(target="native")
pub fn with_event_loop(f : async (TaskGroup[Unit]) -> Unit) -> Unit raise {
@event_loop.with_event_loop(() => with_task_group(f))
}

///|
/// `sleep` will wait for the given time (in milliseconds) before returning.
/// Other task can still run while current task is sleeping.
Expand Down
30 changes: 0 additions & 30 deletions src/fs/file.mbt
Original file line number Diff line number Diff line change
Expand Up @@ -393,17 +393,6 @@ pub async fn read_file(
result
}

///|
/// Read the contents of a text file located at `path`.
#deprecated("use `read_file(path).text()` instead")
pub async fn read_text_file(
path : StringView,
encoding~ : @io.Encoding,
) -> String {
guard encoding is UTF8
read_file(path).text()
}

///|
/// Write data to a file located at `path`.
/// The meaning of `sync`, `append`, `create`, and `truncate`,
Expand All @@ -421,22 +410,3 @@ pub async fn write_file(
defer file.close()
file.write(content.binary())
}

///|
/// Write data to a text file located at `path`.
/// The meaning of `sync`, `append`, `create`, truncate` is the same as `open`,
/// except that `truncate` is `true` by default. See `open` for more details.
#deprecated("use `write_file(path, content)` instead")
pub async fn write_text_file(
path : StringView,
content : String,
encoding~ : @io.Encoding,
sync? : SyncMode = Data,
append? : Bool = false,
create? : Int,
truncate? : Bool = true,
) -> Unit {
let file = open(path, mode=WriteOnly, sync~, append~, create?, truncate~)
defer file.close()
file.write_string(content, encoding~)
}
6 changes: 0 additions & 6 deletions src/fs/pkg.generated.mbti
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,6 @@ pub async fn opendir(StringView) -> Directory

pub async fn read_file(StringView, sync_timestamp? : Bool) -> &@io.Data

#deprecated
pub async fn read_text_file(StringView, encoding~ : @io.Encoding) -> String

pub async fn readdir(StringView, include_hidden? : Bool, include_special? : Bool, sort? : Bool) -> Array[String]

pub async fn realpath(StringView) -> String
Expand All @@ -53,9 +50,6 @@ pub async fn walk(StringView, async (String, Array[String]) -> Unit, exclude? :

pub async fn write_file(StringView, &@io.Data, sync? : SyncMode, append? : Bool, create? : Int, truncate? : Bool) -> Unit

#deprecated
pub async fn write_text_file(StringView, String, encoding~ : @io.Encoding, sync? : SyncMode, append? : Bool, create? : Int, truncate? : Bool) -> Unit

// Errors

// Types and methods
Expand Down
26 changes: 1 addition & 25 deletions src/http/client.mbt
Original file line number Diff line number Diff line change
Expand Up @@ -35,31 +35,7 @@ pub suberror ProxyError {
} derive(Show, ToJson)

///|
/// Create a new HTTP client by connecting to a remote host.
/// If `protocol` is `Https` (`Https` by default),
/// a TLS connection will be established,
/// and the certificate of the remote peer will be verified.
///
/// `headers` can be used to specify persistent headers for the client,
/// i.e. all requests made from this client will share these headers.
/// The ownership of `headers` will be transferred to the new client,
/// so `headers` should not be used by the caller later.
/// The following headers is automatically set,
/// and must not be specified in `headers`:
///
/// - Host
/// - Content-Length, Transfer-Encoding
///
/// If `proxy` is present, it should be another HTTP client in a clean state.
/// The new client will send a `CONNECT` request via the proxy client
/// and try to establish a tunnel via the proxy client.
/// All subsequent requests made by the new client will go through the proxy tunnel.
/// The ownership of the proxy client is transferred to the new client,
/// so it must not be used nor closed anymore by the caller.
/// Using another HTTP client as proxy allows advanced features such as
/// proxy authentication and https `CONNECT` proxy.
#deprecated("use `@http.Client::new()` and specify protocol/port in the URI instead", skip_current_package=true)
pub async fn Client::connect(
async fn Client::connect(
host : String,
headers? : Map[String, String] = {},
protocol? : Protocol = Https,
Expand Down
23 changes: 6 additions & 17 deletions src/http/pkg.generated.mbti
Original file line number Diff line number Diff line change
Expand Up @@ -7,26 +7,17 @@ import {
}

// Values
#label_migration(port, fill=false, msg="specify the port in URI instead")
pub async fn get(String, headers? : Map[String, String], port? : Int, body? : &@io.Data, proxy? : Client) -> (Response, &@io.Data)
pub async fn get(String, headers? : Map[String, String], body? : &@io.Data, proxy? : Client) -> (Response, &@io.Data)

#label_migration(port, fill=false, msg="specify the port in URI instead")
pub async fn get_stream(String, headers? : Map[String, String], port? : Int, body? : &@io.Data, proxy? : Client) -> (Response, Client)
pub async fn get_stream(String, headers? : Map[String, String], body? : &@io.Data, proxy? : Client) -> (Response, Client)

#label_migration(port, fill=false, msg="specify the port in URI instead")
pub async fn post(String, &@io.Data, headers? : Map[String, String], port? : Int, proxy? : Client) -> (Response, &@io.Data)
pub async fn post(String, &@io.Data, headers? : Map[String, String], proxy? : Client) -> (Response, &@io.Data)

#label_migration(port, fill=false, msg="specify the port in URI instead")
pub async fn post_stream(String, headers? : Map[String, String], port? : Int, proxy? : Client) -> Client
pub async fn post_stream(String, headers? : Map[String, String], proxy? : Client) -> Client

#label_migration(port, fill=false, msg="specify the port in URI instead")
pub async fn put(String, &@io.Data, headers? : Map[String, String], port? : Int, proxy? : Client) -> (Response, &@io.Data)
pub async fn put(String, &@io.Data, headers? : Map[String, String], proxy? : Client) -> (Response, &@io.Data)

#label_migration(port, fill=false, msg="specify the port in URI instead")
pub async fn put_stream(String, headers? : Map[String, String], port? : Int, proxy? : Client) -> Client

#deprecated
pub async fn run_server(@socket.Addr, async (ServerConnection, @socket.Addr) -> Unit, headers? : Map[String, String], dual_stack? : Bool, reuse_addr? : Bool, allow_failure? : Bool, max_connections? : Int) -> Unit
pub async fn put_stream(String, headers? : Map[String, String], proxy? : Client) -> Client

// Errors
pub suberror HttpProtocolError {
Expand All @@ -53,8 +44,6 @@ pub impl ToJson for URIParseError
// Types and methods
type Client
pub fn Client::close(Self) -> Unit
#deprecated
pub async fn Client::connect(String, headers? : Map[String, String], protocol? : Protocol, port? : Int, proxy? : Self) -> Self
pub async fn Client::end_request(Self) -> Response
pub async fn Client::enter_passthrough_mode(Self) -> Unit
pub async fn Client::flush(Self) -> Unit
Expand Down
50 changes: 14 additions & 36 deletions src/http/request.mbt
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,7 @@ pub suberror URIParseError {
} derive(Show, ToJson)

///|
fn resolve_url(
uri : String,
port? : Int,
) -> (Protocol, Int, String, String) raise {
fn resolve_url(uri : String) -> (Protocol, Int, String, String) raise {
guard uri.find("://") is Some(protocol_len) else { raise InvalidFormat }
let protocol = match uri[:protocol_len] {
"http" => Http
Expand All @@ -49,18 +46,12 @@ fn resolve_url(
} else {
(uri.to_string(), "/")
}
let (host, port) = match port {
Some(port) => (host, port)
None =>
if host lexmatch? (host, ":" ("[0-9]+" as port_str)) {
let port = @strconv.parse_int(port_str) catch {
_ => raise InvalidFormat
}
guard port is (1..<65536) else { raise InvalidFormat }
(host.to_string(), port)
} else {
(host, protocol.default_port())
}
let (host, port) = if host lexmatch? (host, ":" ("[0-9]+" as port_str)) {
let port = @strconv.parse_int(port_str) catch { _ => raise InvalidFormat }
guard port is (1..<65536) else { raise InvalidFormat }
(host.to_string(), port)
} else {
(host, protocol.default_port())
}
let path = if path == "" { "/" } else { path }
(protocol, port, host, path)
Expand All @@ -72,10 +63,9 @@ async fn perform_request(
meth : RequestMethod,
headers : Map[String, String],
body : &@io.Data,
port? : Int,
proxy? : Client,
) -> (Response, &@io.Data) {
let (protocol, port, host, path) = resolve_url(uri, port?)
let (protocol, port, host, path) = resolve_url(uri)
let client = Client::connect(host, headers~, protocol~, port~, proxy?)
defer client.close()
let response = client..request(meth, path)..write(body).end_request()
Expand All @@ -92,41 +82,35 @@ async fn perform_request(
/// `proxy` is not supported on JavaScript backend.
///
/// See `Client::request` for more details.
#callsite(migration(port, fill=false, msg="specify the port in URI instead"))
pub async fn get(
uri : String,
headers? : Map[String, String] = {},
port? : Int,
body? : &@io.Data = b"",
proxy? : Client,
) -> (Response, &@io.Data) {
perform_request(uri, Get, headers, body, port?, proxy?)
perform_request(uri, Get, headers, body, proxy?)
}

///|
/// Similar to `get`, but performs a `PUT` request instead.
#callsite(migration(port, fill=false, msg="specify the port in URI instead"))
pub async fn put(
uri : String,
content : &@io.Data,
headers? : Map[String, String] = {},
port? : Int,
proxy? : Client,
) -> (Response, &@io.Data) {
perform_request(uri, Put, headers, content, port?, proxy?)
perform_request(uri, Put, headers, content, proxy?)
}

///|
/// Similar to `get`, but performs a `POST` request instead.
#callsite(migration(port, fill=false, msg="specify the port in URI instead"))
pub async fn post(
uri : String,
content : &@io.Data,
headers? : Map[String, String] = {},
port? : Int,
proxy? : Client,
) -> (Response, &@io.Data) {
perform_request(uri, Post, headers, content, port?, proxy?)
perform_request(uri, Post, headers, content, proxy?)
}

///|
Expand All @@ -139,15 +123,13 @@ pub async fn post(
///
/// Note that the returned client must be manually closed via `.close()`
/// to close the underlying connection used for the request.
#callsite(migration(port, fill=false, msg="specify the port in URI instead"))
pub async fn get_stream(
uri : String,
headers? : Map[String, String] = {},
port? : Int,
body? : &@io.Data = b"",
proxy? : Client,
) -> (Response, Client) {
let (protocol, port, host, path) = resolve_url(uri, port?)
let (protocol, port, host, path) = resolve_url(uri)
let client = Client::connect(host, headers~, protocol~, port~, proxy?)
try {
let response = client..request(Get, path)..write(body).end_request()
Expand All @@ -173,14 +155,12 @@ pub async fn get_stream(
///
/// Note that the returned `client` must be manually closed via `.close()`
/// to close the underlying connection used for the request.
#callsite(migration(port, fill=false, msg="specify the port in URI instead"))
pub async fn put_stream(
uri : String,
headers? : Map[String, String] = {},
port? : Int,
proxy? : Client,
) -> Client {
let (protocol, port, host, path) = resolve_url(uri, port?)
let (protocol, port, host, path) = resolve_url(uri)
let client = Client::connect(host, headers~, protocol~, port~, proxy?)
try client.request(Put, path) catch {
err => {
Expand All @@ -205,14 +185,12 @@ pub async fn put_stream(
///
/// Note that the returned `client` must be manually closed via `.close()`
/// to close the underlying connection used for the request.
#callsite(migration(port, fill=false, msg="specify the port in URI instead"))
pub async fn post_stream(
uri : String,
headers? : Map[String, String] = {},
port? : Int,
proxy? : Client,
) -> Client {
let (protocol, port, host, path) = resolve_url(uri, port?)
let (protocol, port, host, path) = resolve_url(uri)
let client = Client::connect(host, headers~, protocol~, port~, proxy?)
try client.request(Post, path) catch {
err => {
Expand Down
40 changes: 0 additions & 40 deletions src/http/server.mbt
Original file line number Diff line number Diff line change
Expand Up @@ -145,46 +145,6 @@ pub async fn ServerConnection::send_response(
self.sender.send_response(code, reason, extra_headers~)
}

///|
/// Create a HTTP server listening on `addr` and run its main loop.
/// New connections are handled by the callback `f`,
/// `f` will receive the new HTTP connection and the address of the client.
///
/// The client connection is closed automatically,
/// so `f` must not close the connection manually.
///
/// `headers` can be used to specify persistent headers for the server,
/// i.e. all response sent by this server will share these headers.
///
/// If `allow_failure` is `true` (`true` by default),
/// failure in `f` will be silently ignored.
///
/// If `max_connections` is present,
/// at most `max_connections` clients are allowed in parallel.
/// New clients will only get handled after a previous client terminates.
///
/// The meaning of `dual_stack` and `reuse_addr` is the same as `@socket.TcpServer::new`,
/// see its document for more details.
#deprecated("use `@http.Server::run_forever()` instead")
pub async fn run_server(
addr : @socket.Addr,
f : async (ServerConnection, @socket.Addr) -> Unit,
headers? : Map[String, String],
dual_stack? : Bool,
reuse_addr? : Bool,
allow_failure? : Bool,
max_connections? : Int,
) -> Unit {
@socket.TcpServer::new(addr, dual_stack?, reuse_addr?).run_forever(
allow_failure?,
max_connections?,
(conn, addr) => {
let conn = ServerConnection::new(conn, headers?)
f(conn, addr)
},
)
}

///|
/// A HTTP server
struct Server {
Expand Down
1 change: 0 additions & 1 deletion src/io/README.mbt.md
Original file line number Diff line number Diff line change
Expand Up @@ -580,7 +580,6 @@ Trait for writing data to a destination. Methods include:
- `write_once(data, offset~, len~)` - Single write operation
- `write(data)` - Write data (may require multiple operations)
- `write_reader(reader)` - Copy data from reader to writer
- `write_string(str, encoding~)` - Write string with encoding (deprecated)

### Data

Expand Down
Loading