Skip to content

Commit

Permalink
remove until find a better solution
Browse files Browse the repository at this point in the history
  • Loading branch information
enghitalo committed Dec 7, 2024
1 parent 2df7c74 commit e8a70c4
Showing 1 changed file with 1 addition and 58 deletions.
59 changes: 1 addition & 58 deletions v/v/src/request_parser.v
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ mut:
method Slice
path Slice
version Slice
headers map[string]Slice
}

fn parse_request_line(mut req HttpRequest) ! {
Expand Down Expand Up @@ -55,68 +54,12 @@ fn parse_request_line(mut req HttpRequest) ! {
}
}

fn parse_headers(mut req HttpRequest, offset &int) ! {
for offset < req.buffer.len {
// End of headers
if req.buffer[*offset] == `\r` && req.buffer[*offset + 1] == `\n` {
unsafe {
*offset += 2
}
break
}

// Parse header name
mut header_start := *offset
for offset < req.buffer.len && req.buffer[*offset] != `:` {
unsafe {
*offset = *offset + 1
}
}
header_name := req.buffer[header_start..*offset].bytestr()
unsafe {
*offset++ // Skip the colon
}
// Skip whitespace after the colon
for offset < req.buffer.len && req.buffer[*offset] == ` ` {
unsafe {
*offset++
}
}

// Parse header value
mut value_start := *offset
for offset < req.buffer.len && req.buffer[*offset] != `\r` {
unsafe {
*offset++
}
}
header_value := Slice{
start: value_start
len: *offset - value_start
}
req.headers[header_name] = header_value

// Move to the next line
if *offset + 1 < req.buffer.len && req.buffer[*offset] == `\r`
&& req.buffer[*offset + 1] == `\n` {
unsafe {
*offset += 2
}
} else {
return error('Invalid header line')
}
}
}

fn decode_http_request(buffer []u8) !HttpRequest {
mut req := HttpRequest{
buffer: buffer
headers: map[string]Slice{}
buffer: buffer
}
offset := 0

parse_request_line(mut req)!
parse_headers(mut req, &offset)!

return req
}
Expand Down

0 comments on commit e8a70c4

Please sign in to comment.