Skip to content

Commit 80724a2

Browse files
authored
Merge pull request #246 from Lightbug-HQ/fix/docker-crash
Fix server crashing with large headers
2 parents 150928b + 1c2c54d commit 80724a2

File tree

15 files changed

+145
-3819
lines changed

15 files changed

+145
-3819
lines changed

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,18 +49,18 @@ The only hard dependency for `lightbug_http` is Mojo.
4949
Learn how to get up and running with Mojo on the [Modular website](https://www.modular.com/max/mojo).
5050
Once you have a Mojo project set up locally,
5151

52-
1. Add the `modular-community` channel to your `mojoproject.toml`, e.g:
52+
1. Add the `mojo-community` channel to your `mojoproject.toml`, e.g:
5353

5454
```toml
5555
[project]
56-
channels = ["conda-forge", "https://conda.modular.com/max", "https://repo.prefix.dev/modular-community"]
56+
channels = ["conda-forge", "https://conda.modular.com/max", "https://repo.prefix.dev/mojo-community"]
5757
```
5858

5959
2. Add `lightbug_http` as a dependency:
6060

6161
```toml
6262
[dependencies]
63-
lightbug_http = ">=0.1.12"
63+
lightbug_http = ">=0.1.13"
6464
```
6565

6666
3. Run `magic install` at the root of your project, where `mojoproject.toml` is located

lightbug_http/_libc.mojo

Lines changed: 39 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -353,7 +353,7 @@ fn htonl(hostlong: c_uint) -> c_uint:
353353
```
354354
355355
#### Notes:
356-
* Reference: https://man7.org/linux/man-pages/man3/htonl.3p.html.
356+
* Reference: https://man7.org/linux/man-pages/man3/htonl.3p.html .
357357
"""
358358
return external_call["htonl", c_uint, c_uint](hostlong)
359359

@@ -373,7 +373,7 @@ fn htons(hostshort: c_ushort) -> c_ushort:
373373
```
374374
375375
#### Notes:
376-
* Reference: https://man7.org/linux/man-pages/man3/htonl.3p.html.
376+
* Reference: https://man7.org/linux/man-pages/man3/htonl.3p.html .
377377
"""
378378
return external_call["htons", c_ushort, c_ushort](hostshort)
379379

@@ -393,7 +393,7 @@ fn ntohl(netlong: c_uint) -> c_uint:
393393
```
394394
395395
#### Notes:
396-
* Reference: https://man7.org/linux/man-pages/man3/htonl.3p.html
396+
* Reference: https://man7.org/linux/man-pages/man3/htonl.3p.html .
397397
"""
398398
return external_call["ntohl", c_uint, c_uint](netlong)
399399

@@ -413,7 +413,7 @@ fn ntohs(netshort: c_ushort) -> c_ushort:
413413
```
414414
415415
#### Notes:
416-
* Reference: https://man7.org/linux/man-pages/man3/htonl.3p.html
416+
* Reference: https://man7.org/linux/man-pages/man3/htonl.3p.html .
417417
"""
418418
return external_call["ntohs", c_ushort, c_ushort](netshort)
419419

@@ -441,7 +441,7 @@ fn _inet_ntop(
441441
```
442442
443443
#### Notes:
444-
* Reference: https://man7.org/linux/man-pages/man3/inet_ntop.3p.html.
444+
* Reference: https://man7.org/linux/man-pages/man3/inet_ntop.3p.html .
445445
"""
446446
return external_call[
447447
"inet_ntop",
@@ -479,7 +479,7 @@ fn inet_ntop[
479479
```
480480
481481
#### Notes:
482-
* Reference: https://man7.org/linux/man-pages/man3/inet_ntop.3p.html.
482+
* Reference: https://man7.org/linux/man-pages/man3/inet_ntop.3p.html .
483483
"""
484484
constrained[
485485
Int(address_family) in [AF_INET, AF_INET6], "Address family must be either INET_ADDRSTRLEN or INET6_ADDRSTRLEN."
@@ -537,7 +537,7 @@ fn _inet_pton(af: c_int, src: UnsafePointer[c_char], dst: UnsafePointer[c_void])
537537
```
538538
539539
#### Notes:
540-
* Reference: https://man7.org/linux/man-pages/man3/inet_ntop.3p.html
540+
* Reference: https://man7.org/linux/man-pages/man3/inet_ntop.3p.html .
541541
"""
542542
return external_call[
543543
"inet_pton",
@@ -570,7 +570,7 @@ fn inet_pton[address_family: Int32](src: UnsafePointer[c_char]) raises -> c_uint
570570
```
571571
572572
#### Notes:
573-
* Reference: https://man7.org/linux/man-pages/man3/inet_ntop.3p.html
573+
* Reference: https://man7.org/linux/man-pages/man3/inet_ntop.3p.html .
574574
* This function is valid for `AF_INET` and `AF_INET6`.
575575
"""
576576
constrained[Int(address_family) in [AF_INET, AF_INET6], "Address family must be either AF_INET or AF_INET6."]()
@@ -609,7 +609,7 @@ fn _socket(domain: c_int, type: c_int, protocol: c_int) -> c_int:
609609
```
610610
611611
#### Notes:
612-
* Reference: https://man7.org/linux/man-pages/man3/socket.3p.html
612+
* Reference: https://man7.org/linux/man-pages/man3/socket.3p.html .
613613
"""
614614
return external_call["socket", c_int, c_int, c_int, c_int](domain, type, protocol)
615615

@@ -641,7 +641,7 @@ fn socket(domain: c_int, type: c_int, protocol: c_int) raises -> c_int:
641641
```
642642
643643
#### Notes:
644-
* Reference: https://man7.org/linux/man-pages/man3/socket.3p.html
644+
* Reference: https://man7.org/linux/man-pages/man3/socket.3p.html .
645645
"""
646646
var fd = _socket(domain, type, protocol)
647647
if fd == -1:
@@ -707,7 +707,7 @@ fn _setsockopt[
707707
```
708708
709709
#### Notes:
710-
* Reference: https://man7.org/linux/man-pages/man3/setsockopt.3p.html
710+
* Reference: https://man7.org/linux/man-pages/man3/setsockopt.3p.html .
711711
"""
712712
return external_call[
713713
"setsockopt",
@@ -748,7 +748,7 @@ fn setsockopt(
748748
```
749749
750750
#### Notes:
751-
* Reference: https://man7.org/linux/man-pages/man3/setsockopt.3p.html
751+
* Reference: https://man7.org/linux/man-pages/man3/setsockopt.3p.html .
752752
"""
753753
var result = _setsockopt(socket, level, option_name, Pointer.address_of(option_value), sizeof[Int]())
754754
if result == -1:
@@ -796,7 +796,7 @@ fn _getsockopt[
796796
```
797797
798798
#### Notes:
799-
* Reference: https://man7.org/linux/man-pages/man3/setsockopt.3p.html
799+
* Reference: https://man7.org/linux/man-pages/man3/setsockopt.3p.html .
800800
"""
801801
return external_call[
802802
"getsockopt",
@@ -838,7 +838,7 @@ fn getsockopt(
838838
```
839839
840840
#### Notes:
841-
* Reference: https://man7.org/linux/man-pages/man3/getsockopt.3p.html
841+
* Reference: https://man7.org/linux/man-pages/man3/getsockopt.3p.html .
842842
"""
843843
var option_value = stack_allocation[1, c_void]()
844844
var option_len: socklen_t = sizeof[Int]()
@@ -882,7 +882,7 @@ fn _getsockname[
882882
```
883883
884884
#### Notes:
885-
* Reference: https://man7.org/linux/man-pages/man3/getsockname.3p.html
885+
* Reference: https://man7.org/linux/man-pages/man3/getsockname.3p.html .
886886
"""
887887
return external_call[
888888
"getsockname",
@@ -917,7 +917,7 @@ fn getsockname[
917917
```
918918
919919
#### Notes:
920-
* Reference: https://man7.org/linux/man-pages/man3/getsockname.3p.html
920+
* Reference: https://man7.org/linux/man-pages/man3/getsockname.3p.html .
921921
"""
922922
var result = _getsockname(socket, address, address_len)
923923
if result == -1:
@@ -957,7 +957,7 @@ fn _getpeername[
957957
```
958958
959959
#### Notes:
960-
* Reference: https://man7.org/linux/man-pages/man2/getpeername.2.html
960+
* Reference: https://man7.org/linux/man-pages/man2/getpeername.2.html .
961961
"""
962962
return external_call[
963963
"getpeername",
@@ -989,7 +989,7 @@ fn getpeername(file_descriptor: c_int) raises -> sockaddr_in:
989989
```
990990
991991
#### Notes:
992-
* Reference: https://man7.org/linux/man-pages/man2/getpeername.2.html
992+
* Reference: https://man7.org/linux/man-pages/man2/getpeername.2.html .
993993
"""
994994
var remote_address = stack_allocation[1, sockaddr]()
995995
var result = _getpeername(file_descriptor, remote_address, Pointer.address_of(socklen_t(sizeof[sockaddr]())))
@@ -1033,7 +1033,7 @@ fn _bind[origin: MutableOrigin](socket: c_int, address: Pointer[sockaddr_in, ori
10331033
```
10341034
10351035
#### Notes:
1036-
* Reference: https://man7.org/linux/man-pages/man3/bind.3p.html
1036+
* Reference: https://man7.org/linux/man-pages/man3/bind.3p.html .
10371037
"""
10381038
return external_call["bind", c_int, c_int, Pointer[sockaddr_in, origin], socklen_t](socket, address, address_len)
10391039

@@ -1071,7 +1071,7 @@ fn bind(socket: c_int, mut address: sockaddr_in) raises:
10711071
```
10721072
10731073
#### Notes:
1074-
* Reference: https://man7.org/linux/man-pages/man3/bind.3p.html
1074+
* Reference: https://man7.org/linux/man-pages/man3/bind.3p.html .
10751075
"""
10761076
var result = _bind(socket, Pointer.address_of(address), sizeof[sockaddr_in]())
10771077
if result == -1:
@@ -1129,7 +1129,7 @@ fn _listen(socket: c_int, backlog: c_int) -> c_int:
11291129
```
11301130
11311131
#### Notes:
1132-
* Reference: https://man7.org/linux/man-pages/man3/listen.3p.html
1132+
* Reference: https://man7.org/linux/man-pages/man3/listen.3p.html .
11331133
"""
11341134
return external_call["listen", c_int, c_int, c_int](socket, backlog)
11351135

@@ -1154,7 +1154,7 @@ fn listen(socket: c_int, backlog: c_int) raises:
11541154
```
11551155
11561156
#### Notes:
1157-
* Reference: https://man7.org/linux/man-pages/man3/listen.3p.html
1157+
* Reference: https://man7.org/linux/man-pages/man3/listen.3p.html .
11581158
"""
11591159
var result = _listen(socket, backlog)
11601160
if result == -1:
@@ -1190,7 +1190,7 @@ fn _accept[
11901190
```
11911191
11921192
#### Notes:
1193-
* Reference: https://man7.org/linux/man-pages/man3/accept.3p.html
1193+
* Reference: https://man7.org/linux/man-pages/man3/accept.3p.html .
11941194
"""
11951195
return external_call[
11961196
"accept", c_int, c_int, Pointer[sockaddr, address_origin], Pointer[socklen_t, len_origin] # FnName, RetType
@@ -1227,7 +1227,7 @@ fn accept(socket: c_int) raises -> c_int:
12271227
```
12281228
12291229
#### Notes:
1230-
* Reference: https://man7.org/linux/man-pages/man3/accept.3p.html
1230+
* Reference: https://man7.org/linux/man-pages/man3/accept.3p.html .
12311231
"""
12321232
var remote_address = sockaddr()
12331233
var result = _accept(socket, Pointer.address_of(remote_address), Pointer.address_of(socklen_t(sizeof[socklen_t]())))
@@ -1293,7 +1293,7 @@ fn _connect[origin: Origin](socket: c_int, address: Pointer[sockaddr_in, origin]
12931293
```
12941294
12951295
#### Notes:
1296-
* Reference: https://man7.org/linux/man-pages/man3/connect.3p.html
1296+
* Reference: https://man7.org/linux/man-pages/man3/connect.3p.html .
12971297
"""
12981298
return external_call["connect", c_int](socket, address, address_len)
12991299

@@ -1328,7 +1328,7 @@ fn connect(socket: c_int, address: sockaddr_in) raises:
13281328
```
13291329
13301330
#### Notes:
1331-
* Reference: https://man7.org/linux/man-pages/man3/connect.3p.html
1331+
* Reference: https://man7.org/linux/man-pages/man3/connect.3p.html .
13321332
"""
13331333
var result = _connect(socket, Pointer.address_of(address), sizeof[sockaddr_in]())
13341334
if result == -1:
@@ -1402,7 +1402,7 @@ fn _recv(
14021402
```
14031403
14041404
#### Notes:
1405-
* Reference: https://man7.org/linux/man-pages/man3/recv.3p.html
1405+
* Reference: https://man7.org/linux/man-pages/man3/recv.3p.html .
14061406
"""
14071407
return external_call[
14081408
"recv",
@@ -1437,7 +1437,7 @@ fn recv(
14371437
```
14381438
14391439
#### Notes:
1440-
* Reference: https://man7.org/linux/man-pages/man3/recv.3p.html
1440+
* Reference: https://man7.org/linux/man-pages/man3/recv.3p.html .
14411441
"""
14421442
var result = _recv(socket, buffer, length, flags)
14431443
if result == -1:
@@ -1504,7 +1504,7 @@ fn _recvfrom[
15041504
```
15051505
15061506
#### Notes:
1507-
* Reference: https://man7.org/linux/man-pages/man3/recvfrom.3p.html
1507+
* Reference: https://man7.org/linux/man-pages/man3/recvfrom.3p.html .
15081508
* Valid Flags:
15091509
* `MSG_PEEK`: Peeks at an incoming message. The data is treated as unread and the next recvfrom() or similar function shall still return this data.
15101510
* `MSG_OOB`: Requests out-of-band data. The significance and semantics of out-of-band data are protocol-specific.
@@ -1550,7 +1550,7 @@ fn recvfrom(
15501550
```
15511551
15521552
#### Notes:
1553-
* Reference: https://man7.org/linux/man-pages/man3/recvfrom.3p.html
1553+
* Reference: https://man7.org/linux/man-pages/man3/recvfrom.3p.html .
15541554
* Valid Flags:
15551555
* `MSG_PEEK`: Peeks at an incoming message. The data is treated as unread and the next recvfrom() or similar function shall still return this data.
15561556
* `MSG_OOB`: Requests out-of-band data. The significance and semantics of out-of-band data are protocol-specific.
@@ -1610,7 +1610,7 @@ fn _send(socket: c_int, buffer: UnsafePointer[c_void], length: c_size_t, flags:
16101610
```
16111611
16121612
#### Notes:
1613-
* Reference: https://man7.org/linux/man-pages/man3/send.3p.html
1613+
* Reference: https://man7.org/linux/man-pages/man3/send.3p.html .
16141614
"""
16151615
return external_call["send", c_ssize_t](socket, buffer, length, flags)
16161616

@@ -1652,7 +1652,7 @@ fn send(socket: c_int, buffer: UnsafePointer[c_void], length: c_size_t, flags: c
16521652
```
16531653
16541654
#### Notes:
1655-
* Reference: https://man7.org/linux/man-pages/man3/send.3p.html
1655+
* Reference: https://man7.org/linux/man-pages/man3/send.3p.html .
16561656
"""
16571657
var result = _send(socket, buffer, length, flags)
16581658
if result == -1:
@@ -1746,7 +1746,7 @@ fn _sendto(
17461746
```
17471747
17481748
#### Notes:
1749-
* Reference: https://man7.org/linux/man-pages/man3/sendto.3p.html
1749+
* Reference: https://man7.org/linux/man-pages/man3/sendto.3p.html .
17501750
* Valid Flags:
17511751
* `MSG_EOR`: Terminates a record (if supported by the protocol).
17521752
* `MSG_OOB`: Sends out-of-band data on sockets that support out-of-band data. The significance and semantics of out-of-band data are protocol-specific.
@@ -1804,7 +1804,7 @@ fn sendto(
18041804
```
18051805
18061806
#### Notes:
1807-
* Reference: https://man7.org/linux/man-pages/man3/sendto.3p.html
1807+
* Reference: https://man7.org/linux/man-pages/man3/sendto.3p.html .
18081808
* Valid Flags:
18091809
* `MSG_EOR`: Terminates a record (if supported by the protocol).
18101810
* `MSG_OOB`: Sends out-of-band data on sockets that support out-of-band data. The significance and semantics of out-of-band data are protocol-specific.
@@ -1880,7 +1880,7 @@ fn _shutdown(socket: c_int, how: c_int) -> c_int:
18801880
```
18811881
18821882
#### Notes:
1883-
* Reference: https://man7.org/linux/man-pages/man3/shutdown.3p.html
1883+
* Reference: https://man7.org/linux/man-pages/man3/shutdown.3p.html .
18841884
"""
18851885
return external_call["shutdown", c_int, c_int, c_int](socket, how)
18861886

@@ -1911,7 +1911,7 @@ fn shutdown(socket: c_int, how: c_int) raises:
19111911
```
19121912
19131913
#### Notes:
1914-
* Reference: https://man7.org/linux/man-pages/man3/shutdown.3p.html
1914+
* Reference: https://man7.org/linux/man-pages/man3/shutdown.3p.html .
19151915
"""
19161916
var result = _shutdown(socket, how)
19171917
if result == -1:
@@ -1946,7 +1946,7 @@ fn gai_strerror(ecode: c_int) -> UnsafePointer[c_char]:
19461946
```
19471947
19481948
#### Notes:
1949-
* Reference: https://man7.org/linux/man-pages/man3/gai_strerror.3p.html
1949+
* Reference: https://man7.org/linux/man-pages/man3/gai_strerror.3p.html .
19501950
"""
19511951
return external_call["gai_strerror", UnsafePointer[c_char], c_int](ecode)
19521952

@@ -1973,7 +1973,7 @@ fn _close(fildes: c_int) -> c_int:
19731973
```
19741974
19751975
#### Notes:
1976-
* Reference: https://man7.org/linux/man-pages/man3/close.3p.html
1976+
* Reference: https://man7.org/linux/man-pages/man3/close.3p.html .
19771977
"""
19781978
return external_call["close", c_int, c_int](fildes)
19791979

@@ -2006,7 +2006,7 @@ fn close(file_descriptor: c_int) raises:
20062006
```
20072007
20082008
#### Notes:
2009-
* Reference: https://man7.org/linux/man-pages/man3/close.3p.html
2009+
* Reference: https://man7.org/linux/man-pages/man3/close.3p.html .
20102010
"""
20112011
if _close(file_descriptor) == -1:
20122012
var errno = get_errno()

lightbug_http/cookie/cookie.mojo

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,9 @@ struct Cookie(CollectionElement):
134134
if v:
135135
header_value.write(Cookie.SEPERATOR, Cookie.EXPIRES, Cookie.EQUAL, v.value())
136136
if self.max_age:
137-
header_value.write(Cookie.SEPERATOR, Cookie.MAX_AGE, Cookie.EQUAL, String(self.max_age.value().total_seconds))
137+
header_value.write(
138+
Cookie.SEPERATOR, Cookie.MAX_AGE, Cookie.EQUAL, String(self.max_age.value().total_seconds)
139+
)
138140
if self.domain:
139141
header_value.write(Cookie.SEPERATOR, Cookie.DOMAIN, Cookie.EQUAL, self.domain.value())
140142
if self.path:

lightbug_http/http/common_response.mojo

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from lightbug_http.io.bytes import Bytes
22

3+
34
fn OK(body: String, content_type: String = "text/plain") -> HTTPResponse:
45
return HTTPResponse(
56
headers=Headers(Header(HeaderKey.CONTENT_TYPE, content_type)),

0 commit comments

Comments
 (0)