Skip to content

Commit 51552a5

Browse files
committed
switch to bytes instead of byteview
1 parent 790ae03 commit 51552a5

File tree

2 files changed

+13
-8
lines changed

2 files changed

+13
-8
lines changed

lightbug_http/http/request.mojo

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ from lightbug_http.strings import (
1414
nChar,
1515
lineBreak,
1616
to_string,
17+
to_bytes,
1718
)
1819

1920

@@ -36,8 +37,8 @@ struct HTTPRequest[origin: Origin](Writable, Stringable):
3637
var uri: URI
3738
var body_raw: Bytes
3839

39-
var method: ByteView[origin]
40-
var protocol: ByteView[origin]
40+
var method: Bytes
41+
var protocol: Bytes
4142

4243
var server_is_tls: Bool
4344
var timeout: Duration
@@ -46,9 +47,9 @@ struct HTTPRequest[origin: Origin](Writable, Stringable):
4647
fn from_bytes(addr: String, max_body_size: Int, b: Span[Byte]) raises -> HTTPRequest[origin]:
4748
var reader = ByteReader(b)
4849
var headers = Headers[origin]()
49-
var method: ByteView[origin]
50-
var protocol: ByteView[origin]
51-
var uri: ByteView[origin]
50+
var method: Bytes
51+
var protocol: Bytes
52+
var uri: Bytes
5253
try:
5354
var rest = headers.parse_raw(reader)
5455
var method = rest[0]
@@ -68,7 +69,7 @@ struct HTTPRequest[origin: Origin](Writable, Stringable):
6869
raise Error("HTTPRequest.from_bytes: Request body too large.")
6970

7071
var request = HTTPRequest(
71-
URI.parse(addr + String(uri)), headers=headers, method=String(method), protocol=String(protocol), cookies=cookies
72+
URI.parse(addr + to_string(uri)), headers=headers, method=to_string(method), protocol=to_string(protocol), cookies=cookies
7273
)
7374

7475
if content_length > 0:
@@ -93,8 +94,8 @@ struct HTTPRequest[origin: Origin](Writable, Stringable):
9394
):
9495
self.headers = headers
9596
self.cookies = cookies
96-
self.method = ByteView(method.as_bytes())
97-
self.protocol = protocol
97+
self.method = to_bytes(method)
98+
self.protocol = to_bytes(protocol)
9899
self.uri = uri
99100
self.body_raw = body
100101
self.server_is_tls = server_is_tls

lightbug_http/strings.mojo

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,10 @@ fn to_string(owned bytes: Bytes) -> String:
5858
return result^
5959

6060

61+
fn to_bytes(s: String) -> Bytes:
62+
return Bytes(s.as_bytes())
63+
64+
6165
fn find_all(s: String, sub_str: String) -> List[Int]:
6266
match_idxs = List[Int]()
6367
var current_idx: Int = s.find(sub_str)

0 commit comments

Comments
 (0)