inline tiny func on httpcore (#15480)

This commit is contained in:
Juan Carlos 2020-10-05 12:08:50 -03:00 • committed by GitHub
commit 1e28cea0d1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -113,7 +113,7 @@ func toCaseInsensitive(headers: HttpHeaders, s: string): string {.inline.} =
return if headers.isTitleCase: toTitleCase(s) else: toLowerAscii(s) return if headers.isTitleCase: toTitleCase(s) else: toLowerAscii(s)
func newHttpHeaders*(titleCase=false): HttpHeaders = func newHttpHeaders*(titleCase=false): HttpHeaders =
## Returns a new ``HttpHeaders`` object. if ``titleCase`` is set to true, ## Returns a new ``HttpHeaders`` object. if ``titleCase`` is set to true,
## headers are passed to the server in title case (e.g. "Content-Length") ## headers are passed to the server in title case (e.g. "Content-Length")
new result new result
result.table = newTable[string, seq[string]]() result.table = newTable[string, seq[string]]()
@ -121,7 +121,7 @@ func newHttpHeaders*(titleCase=false): HttpHeaders =
func newHttpHeaders*(keyValuePairs: func newHttpHeaders*(keyValuePairs:
openArray[tuple[key: string, val: string]], titleCase=false): HttpHeaders = openArray[tuple[key: string, val: string]], titleCase=false): HttpHeaders =
## Returns a new ``HttpHeaders`` object from an array. if ``titleCase`` is set to true, ## Returns a new ``HttpHeaders`` object from an array. if ``titleCase`` is set to true,
## headers are passed to the server in title case (e.g. "Content-Length") ## headers are passed to the server in title case (e.g. "Content-Length")
new result new result
result.table = newTable[string, seq[string]]() result.table = newTable[string, seq[string]]()
@ -134,10 +134,10 @@ func newHttpHeaders*(keyValuePairs:
result.table[key] = @[pair.val] result.table[key] = @[pair.val]
func `$`*(headers: HttpHeaders): string = func `$`*(headers: HttpHeaders): string {.inline.} =
return $headers.table $headers.table
proc clear*(headers: HttpHeaders) = proc clear*(headers: HttpHeaders) {.inline.} =
headers.table.clear() headers.table.clear()
func `[]`*(headers: HttpHeaders, key: string): HttpHeaderValues = func `[]`*(headers: HttpHeaders, key: string): HttpHeaderValues =
@ -206,7 +206,7 @@ func getOrDefault*(headers: HttpHeaders, key: string,
else: else:
return default return default
func len*(headers: HttpHeaders): int = return headers.table.len func len*(headers: HttpHeaders): int {.inline.} = headers.table.len
func parseList(line: string, list: var seq[string], start: int): int = func parseList(line: string, list: var seq[string], start: int): int =
var i = 0 var i = 0
@ -323,21 +323,21 @@ proc `==`*(rawCode: string, code: HttpCode): bool
## string form of itself. ## string form of itself.
return cmpIgnoreCase(rawCode, $code) == 0 return cmpIgnoreCase(rawCode, $code) == 0
func is2xx*(code: HttpCode): bool = func is2xx*(code: HttpCode): bool {.inline.} =
## Determines whether ``code`` is a 2xx HTTP status code. ## Determines whether ``code`` is a 2xx HTTP status code.
return code.int in {200 .. 299} code.int in {200 .. 299}
func is3xx*(code: HttpCode): bool = func is3xx*(code: HttpCode): bool {.inline.} =
## Determines whether ``code`` is a 3xx HTTP status code. ## Determines whether ``code`` is a 3xx HTTP status code.
return code.int in {300 .. 399} code.int in {300 .. 399}
func is4xx*(code: HttpCode): bool = func is4xx*(code: HttpCode): bool {.inline.} =
## Determines whether ``code`` is a 4xx HTTP status code. ## Determines whether ``code`` is a 4xx HTTP status code.
return code.int in {400 .. 499} code.int in {400 .. 499}
func is5xx*(code: HttpCode): bool = func is5xx*(code: HttpCode): bool {.inline.} =
## Determines whether ``code`` is a 5xx HTTP status code. ## Determines whether ``code`` is a 5xx HTTP status code.
return code.int in {500 .. 599} code.int in {500 .. 599}
func `$`*(httpMethod: HttpMethod): string = func `$`*(httpMethod: HttpMethod): string =
return (system.`$`(httpMethod))[4 .. ^1].toUpperAscii() return (system.`$`(httpMethod))[4 .. ^1].toUpperAscii()
@ -366,5 +366,3 @@ when isMainModule:
doAssert testTitleCase.hasKey("Content-Length") doAssert testTitleCase.hasKey("Content-Length")
for key, val in testTitleCase: for key, val in testTitleCase:
doAssert key == "Content-Length" doAssert key == "Content-Length"