mirror of
https://github.com/nim-lang/Nim.git
synced 2026-02-17 16:38:33 +00:00
* fix #7680 * Don't send on every HTTP method * These should be squashed * 80 column limit
This commit is contained in:
@@ -745,10 +745,11 @@ proc downloadFile*(url: string, outputFilename: string,
|
||||
proc generateHeaders(requestUrl: Uri, httpMethod: string,
|
||||
headers: HttpHeaders, body: string, proxy: Proxy): string =
|
||||
# GET
|
||||
result = httpMethod.toUpperAscii()
|
||||
let upperMethod = httpMethod.toUpperAscii()
|
||||
result = upperMethod
|
||||
result.add ' '
|
||||
|
||||
if proxy.isNil or (not proxy.isNil and requestUrl.scheme == "https"):
|
||||
if proxy.isNil or requestUrl.scheme == "https":
|
||||
# /path?query
|
||||
if requestUrl.path[0] != '/': result.add '/'
|
||||
result.add(requestUrl.path)
|
||||
@@ -774,7 +775,9 @@ proc generateHeaders(requestUrl: Uri, httpMethod: string,
|
||||
add(result, "Connection: Keep-Alive\c\L")
|
||||
|
||||
# Content length header.
|
||||
if body.len > 0 and not headers.hasKey("Content-Length"):
|
||||
const requiresBody = ["POST", "PUT", "PATCH"]
|
||||
let needsContentLength = body.len > 0 or upperMethod in requiresBody
|
||||
if needsContentLength and not headers.hasKey("Content-Length"):
|
||||
add(result, "Content-Length: " & $body.len & "\c\L")
|
||||
|
||||
# Proxy auth header.
|
||||
|
||||
Reference in New Issue
Block a user