Skip to content

Commit 830334b

Browse files
committed
fix more tests
1 parent 3fd0f11 commit 830334b

File tree

4 files changed

+6
-8
lines changed

4 files changed

+6
-8
lines changed

lightbug_http/header.mojo

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -286,11 +286,9 @@ struct RequestHeader:
286286
raise Error("Could not find request target or HTTP version in request line: " + String(b))
287287
elif last_whitespace == 0:
288288
raise Error("Request URI is empty: " + String(b))
289-
290289
var proto = b[last_whitespace :]
291290
if len(proto) != len(bytes(strHttp11, pop=False)):
292291
raise Error("Invalid protocol, HTTP version not supported: " + String(proto))
293-
294292
_ = self.set_protocol_bytes(proto)
295293
_ = self.set_request_uri_bytes(b[first_whitespace+1:last_whitespace])
296294

@@ -592,7 +590,7 @@ struct ResponseHeader:
592590

593591
fn protocol(self) -> BytesView:
594592
if len(self.__protocol) == 0:
595-
return strHttp11.as_bytes_slice()
593+
return BytesView(unsafe_ptr=strHttp11.as_bytes_slice().unsafe_ptr(), len=8)
596594
return BytesView(unsafe_ptr=self.__protocol.unsafe_ptr(), len=self.__protocol.size)
597595

598596
fn set_trailer(inout self, trailer: String) -> Self:

lightbug_http/http.mojo

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -339,9 +339,9 @@ fn encode(res: HTTPResponse) raises -> String:
339339
var builder = StringBuilder()
340340

341341
_ = builder.write(res.header.protocol())
342-
_ = builder.write_string(" ")
342+
_ = builder.write_string(whitespace)
343343
_ = builder.write_string(res.header.status_code().__str__())
344-
_ = builder.write_string(" ")
344+
_ = builder.write_string(whitespace)
345345
_ = builder.write(res.header.status_message())
346346

347347
_ = builder.write_string(rChar)
@@ -392,7 +392,7 @@ fn encode(res: HTTPResponse) raises -> String:
392392

393393
if len(res.body_raw) > 0:
394394
_ = builder.write(res.get_body_bytes())
395-
395+
396396
return StringSlice[False, ImmutableStaticLifetime](unsafe_from_utf8_ptr=builder.render().unsafe_ptr(), len=builder.size)
397397

398398
fn split_http_string(buf: Bytes) raises -> (String, String, String):

lightbug_http/sys/server.mojo

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ struct SysServer:
213213
Bytes(),
214214
header,
215215
)
216-
216+
217217
try:
218218
request.read_body(reader, header.content_length(), first_line_and_headers_len, max_request_body_size)
219219
except e:

tests/test_http.mojo

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,6 @@ def test_encode_http_response():
6060
var expected_split = String(expected_full).split("\r\n\r\n")
6161
var expected_headers = expected_split[0]
6262
var expected_body = expected_split[1]
63-
63+
6464
test.assert_equal(res_str[:expected_headers_len], expected_headers[:len(expected_headers) - date_header_len])
6565
test.assert_equal(res_str[(len(res_str) - hello_world_len):len(res_str)], expected_body)

0 commit comments

Comments
 (0)