Skip to content

Commit 1f8f74d

Browse files
committed
feat: small changes
1 parent edb6594 commit 1f8f74d

File tree

6 files changed

+252
-87
lines changed

6 files changed

+252
-87
lines changed

DNS.lean

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
/-
2+
Copyright (c) 2025 Lean FRO, LLC. All rights reserved.
3+
Released under Apache 2.0 license as described in the file LICENSE.
4+
Authors: Sofia Rodrigues
5+
-/
6+
module
7+
8+
prelude
9+
public import Std.Time
10+
public import Std.Internal.UV
11+
public import Std.Internal.Async.Basic
12+
13+
public section
14+
15+
namespace Std
16+
namespace Internal
17+
namespace IO
18+
namespace Async
19+
namespace DNS
20+
21+
open Std.Net
22+
23+
/--
24+
Represents a resolved hostname and service name from a socket address.
25+
-/
26+
structure NameInfo where
27+
/--
28+
The resolved hostname (e.g., "example.com").
29+
-/
30+
host : String
31+
32+
/--
33+
The service name (e.g., "http" for port 80).
34+
-/
35+
service : String
36+
37+
/--
38+
Asynchronously resolves a hostname and service to an array of socket addresses.
39+
-/
40+
@[inline]
41+
def getAddrInfo (host : String) (service : String) (addrFamily : Option AddressFamily := none) : Async (Array IPAddr) := do
42+
Async.ofPromise <| UV.DNS.getAddrInfo
43+
host
44+
service
45+
(match addrFamily with
46+
| none => 0
47+
| some .ipv4 => 1
48+
| some .ipv6 => 2)
49+
50+
/--
51+
Performs a reverse DNS lookup on a `SocketAddress`.
52+
-/
53+
@[inline]
54+
def getNameInfo (host : @& SocketAddress) : Async NameInfo :=
55+
UV.DNS.getNameInfo host
56+
|> Async.ofPromise
57+
|>.map (Function.uncurry NameInfo.mk)
58+
59+
end DNS
60+
end Async
61+
end IO
62+
end Internal
63+
end Std

src/Std/Internal/Async/Basic.lean

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ module
77

88
prelude
99
public import Init.System.Promise
10+
public meta import Lean.Elab.Term
1011

1112
public section
1213

@@ -306,11 +307,21 @@ def block (x : AsyncTask α) : IO α :=
306307
| .ok a => return a
307308
| .error e => .error e
308309

310+
syntax "currFunctionError%" : term
311+
312+
elab_rules : term
313+
| `(currFunctionError%) => do
314+
let declName? ← Lean.Elab.Term.getDeclName?
315+
let fnName := match declName? with
316+
| some name => s!"the promise linked to `{name}` was dropped"
317+
| none => "the promise linked to the Async was dropped"
318+
Lean.Elab.Term.elabTerm (← `($(Lean.quote fnName))) none
319+
309320
/--
310321
Create an `AsyncTask` that resolves to the value of `x`.
311322
-/
312323
@[inline]
313-
def ofPromise (x : IO.Promise (Except IO.Error α)) (error : String := "the promise linked to the Async Task was dropped") : AsyncTask α :=
324+
def ofPromise (x : IO.Promise (Except IO.Error α)) (error : String := by exact currFunctionError%) : AsyncTask α :=
314325
x.result?.map fun
315326
| none => .error error
316327
| some res => res
@@ -319,7 +330,7 @@ def ofPromise (x : IO.Promise (Except IO.Error α)) (error : String := "the prom
319330
Create an `AsyncTask` that resolves to the value of `x`.
320331
-/
321332
@[inline]
322-
def ofPurePromise (x : IO.Promise α) (error : String := "the promise linked to the Async Task was dropped") : AsyncTask α :=
333+
def ofPurePromise (x : IO.Promise α) (error : String := by exact currFunctionError%) : AsyncTask α :=
323334
x.result?.map (sync := true) fun
324335
| none => .error error
325336
| some res => pure res
@@ -884,7 +895,7 @@ protected def block (x : Async α) (prio := Task.Priority.default) : IO α :=
884895
Converts `Promise` into `Async`.
885896
-/
886897
@[inline]
887-
protected def ofPromise (task : IO (IO.Promise (Except IO.Error α))) (error : String := "the promise linked to the Async was dropped") : Async α := do
898+
protected def ofPromise (task : IO (IO.Promise (Except IO.Error α))) (error : String := by exact currFunctionError%) : Async α := do
888899
match ← task.toBaseIO with
889900
| .ok data => pure (f := BaseIO) <| MaybeTask.ofTask <| data.result?.map fun
890901
| none => .error error
@@ -925,7 +936,7 @@ protected def ofTask (task : Task α) : Async α := do
925936
Converts `IO (IO.Promise α)` to `Async`.
926937
-/
927938
@[inline]
928-
protected def ofPurePromise (task : IO (IO.Promise α)) (error : String := "the promise linked to the Async was dropped") : Async α := show BaseIO _ from do
939+
protected def ofPurePromise (task : IO (IO.Promise α)) (error : String := by exact currFunctionError%) : Async α := show BaseIO _ from do
929940
match ← task.toBaseIO with
930941
| .ok data => pure <| MaybeTask.ofTask <| data.result?.map fun
931942
| none => .error error

src/Std/Internal/Http/Client/Config.lean

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -29,32 +29,32 @@ structure Config where
2929
/--
3030
Maximum number of requests per connection (for keep-alive).
3131
-/
32-
maxRequestsPerConnection : Nat := 100
32+
maxRequestsPerConnection : Nat := 1000
3333

3434
/--
3535
Maximum number of headers allowed per response.
3636
-/
37-
maxResponseHeaders : Nat := 50
37+
maxResponseHeaders : Nat := 200
3838

3939
/--
4040
Maximum size of a single header value in bytes.
4141
-/
42-
maxHeaderValueSize : Nat := 8192
42+
maxHeaderValueSize : Nat := 16384
4343

4444
/--
4545
Maximum waiting time for additional data before timing out.
4646
-/
47-
readTimeout : Time.Millisecond.Offset := 5000
47+
readTimeout : Time.Millisecond.Offset := 30000
4848

4949
/--
5050
Timeout duration for keep-alive connections.
5151
-/
52-
keepAliveTimeout : { x : Time.Millisecond.Offset // 0 < x } := ⟨45000, by decide⟩
52+
keepAliveTimeout : { x : Time.Millisecond.Offset // 0 < x } := ⟨60000, by decide⟩
5353

5454
/--
5555
Timeout for the entire request lifecycle (connect + read + write).
5656
-/
57-
requestTimeout : { x : Time.Millisecond.Offset // 0 < x } := ⟨10000, by decide⟩
57+
requestTimeout : { x : Time.Millisecond.Offset // 0 < x } := ⟨120000, by decide⟩
5858

5959
/--
6060
Whether to enable keep-alive connections.
@@ -69,17 +69,17 @@ structure Config where
6969
/--
7070
Maximum number of bytes to receive in a single read call.
7171
-/
72-
maxRecvChunkSize : Nat := 8192
72+
maxRecvChunkSize : Nat := 16384
7373

7474
/--
7575
Default buffer size for request payloads.
7676
-/
77-
defaultRequestBufferSize : Nat := 8192
77+
defaultRequestBufferSize : Nat := 16384
7878

7979
/--
8080
The user-agent string to send by default.
8181
-/
82-
userAgent : Option HeaderValue := some (.new "LeanHTTPClient/1.1")
82+
userAgent : Option HeaderValue := some (.new "lean-http/1.1")
8383

8484
namespace Config
8585

0 commit comments

Comments
 (0)