summary refs log tree commit diff stats
path: root/lib/pure/httpclient.nim
Commit message (Collapse)AuthorAgeFilesLines
* Silence several Hint[Performance] warnings (#23003)c-blake2023-11-291-1/+1
| | | | With `--mm:arc` one gets the "implicit copy; if possible, rearrange your program's control flow" `Performance` warnings without these `move`s.
* Fix `IndexDefect` errors in httpclient on invalid/weird headers (#22886)Yardanico2023-11-011-10/+24
| | | | | | | | | | | | | | | | | | | | | Continuation of https://github.com/nim-lang/Nim/pull/19262 Fixes https://github.com/nim-lang/Nim/issues/19261 The parsing code is still too lenient (e.g. it will happily parse header names with spaces in them, which is outright invalid by the spec), but I didn't want to touch it beyond the simple changes to make sure that `std/httpclient` won't throw `IndexDefect`s like it does now on those cases: - Multiline header values - No colon after the header name - No value after the header name + colon One question remains - should I keep `toCaseInsensitive` exported in `httpcore` or just copy-paste the implementation? --------- Co-authored-by: Andreas Rumpf <rumpf_a@web.de>
* Fix #22862 - change the httpclient user-agent to be valid spec-wise (#22882)Yardanico2023-10-291-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Per https://datatracker.ietf.org/doc/html/rfc9110#name-user-agent a User-Agent is defined as follows: ``` User-Agent = product *( RWS ( product / comment ) ) ``` Where ``` product = token ["/" product-version] product-version = token ``` In this case, `token` is defined in RFC 7230 - https://datatracker.ietf.org/doc/html/rfc7230#section-3.2.6: ``` token = 1*tchar tchar = "!" / "#" / "$" / "%" / "&" / "'" / "*" / "+" / "-" / "." / "^" / "_" / "`" / "|" / "~" / DIGIT / ALPHA ; any VCHAR, except delimiters ``` or, in the original RFC 2616 - https://datatracker.ietf.org/doc/html/rfc2616#section-2.2 (next page): ``` token = 1*<any CHAR except CTLs or separators> separators = "(" | ")" | "<" | ">" | "@" | "," | ";" | ":" | "\" | <"> | "/" | "[" | "]" | "?" | "=" | "{" | "}" | SP | HT ``` which means that a `token` cannot have whitespace. Not sure if this should be in the breaking changelog section - theoretically, some clients might've relied on the old Nim user-agent? For some extra info, some other languages seem to have adopted the same hyphen user agent to specify the language + module, e.g.: - https://github.com/python/cpython/blob/main/Lib/urllib/request.py#L1679 (`Python-urllib/<version>`) Fixes #22862.
* fixes #22778 regression: contentLength implementation type mismatched (#22780)ringabout2023-10-031-1/+1
| | | | fixes #22778 follow up https://github.com/nim-lang/Nim/pull/19835
* Markdown code blocks migration part 8 (#22478)Andrey Makarov2023-08-151-58/+76
|
* Add URI parsing warning (#21547)Federico Ceratto2023-03-201-0/+2
| | | | | Related to CVE-2021-41259 https://github.com/nim-lang/security/security/advisories/GHSA-3gg2-rw3q-qwgc https://github.com/nim-lang/Nim/pull/19128#issuecomment-1181944367
* Add docs informing about gotcha of clients (#21262)PhilippMDoerner2023-01-181-0/+4
| | | | | | | | | | | | | | | * Add docs informing about gotcha of clients It is a hidden problem that AsyncHttpClient-instances *can not* deal with multiple requests at once. Similar to normal HttpClients they can only deal with sending one request at a time. This is not told anywhere in the documentation, but critical information that should be available to the user. * Update lib/pure/httpclient.nim fixes typo Co-authored-by: ringabout <43030857+ringabout@users.noreply.github.com> Co-authored-by: ringabout <43030857+ringabout@users.noreply.github.com>
* Change both code snippets to use the same test URL (#20647)Saint2022-10-251-1/+1
|
* Add proxy basic auth documentation (#20498)TerrorTrace2022-10-051-0/+8
|
* make more standard libraries work with `nimPreviewSlimSystem` (#20343)ringabout2022-09-271-0/+3
| | | | | | | | | | | | | | | | | | | | | | | * make more standard libraries work with `nimPreviewSlimSystem` * typo * part two * Delete specutils.nim * fixes more tests * more fixes * fixes tests * fixes three more tests * add formatfloat import * fix * last
* contentLength default to -1 if not present (#19835)Bung2022-09-211-2/+2
| | | | | * contentLength default to -1 if not present * `httpclient.contentLength` changelog
* Add client.close() in httpclient examples. (#20118)gecko2022-08-041-9/+25
| | | | | Without this, the httpclient examples are essentially setting you up for failure. I was bitten by this when my app became unable to open any more sockets. I'm not entirely sure how long this will relevant, as I hope destructors will be added to an upcoming version of the stdlib. But figured it was worth submitting anyways!
* fix nim-lang#19343 (#19344) [backport]Zachary Marquez2022-01-081-1/+1
| | | | Ensure HttpClient onProgress is called once per second Ensure that reported speed is accurate
* use uppercase "type" for Proxy-Authorization header (#19273)xioren2021-12-191-1/+1
| | | | | Some servers will reject authorization requests with a lowercase "basic" type. Changing to "Basic" seems to solve these issues. https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Proxy-Authorization
* Fix #19253 (#19254)PMunch2021-12-141-0/+3
| | | | This fixes 19253 by marking the bodyStream as completed when no content was sent.
* httpclient.nim Fixes #14794 and an issue where content-header is not set on ↵Mark Pointing2021-06-141-2/+6
| | | | | | | | | | | | | | | | postContent (#18208) * Fixed missing newline after bound marker in mulipart post (#14794) and a problem where calling postContent with multipart data does not set content-length header. * Update lib/pure/httpclient.nim * Added comment outlining the reason for changes to httpclient.nim and added tests to ensure that multipart post has a newline at the end of the body, and that the content-length header is present. * Fixed typo in comments. * Removed redundant blank lines in thttpclient_standalone.nim. Co-authored-by: Mark Pointing <mark@futurepoint.com.au> Co-authored-by: Andreas Rumpf <rumpf_a@web.de>
* Improve httpClient docs on SSL cert verification (#15201)Federico Ceratto2021-06-131-3/+16
| | | | | | | | | * Improve httpClient docs on SSL cert verification Cert verification is enabled by default after CVE-2021-29495 * Update httpclient.nim Co-authored-by: Dominik Picheta <dominikpicheta@googlemail.com>
* Move async example to asynchronous version of proc (#18078)xioren2021-05-241-7/+14
| | | | | | | | | | * improve runnableExamples in std/httpclient * Add synchronous example. * Update lib/pure/httpclient.nim Co-authored-by: Timothee Cour <timothee.cour2@gmail.com>
* add colon (#17834)flywind2021-04-241-1/+1
|
* Fix Httpclient headers from being modified accidentally (#17808)Joey2021-04-211-2/+5
|
* Clean up imports in httpclient.nim (#17367)xioren2021-03-141-4/+5
| | | | | | | | | | | * Clean up imports Fix duplicate 'streams' import. * Update lib/pure/httpclient.nim Co-authored-by: konsumlamm <44230978+konsumlamm@users.noreply.github.com> Co-authored-by: konsumlamm <44230978+konsumlamm@users.noreply.github.com>
* Relocate 4xx/5xx exception in downloadFile (#17332) [backport:1.2]xioren2021-03-121-6/+6
| | | Move 4xx/5xx exception to before disk i/o. As it stands an empty file is created on http error 4xx/5xx.
* use .. warning:: (#17226)flywind2021-03-041-1/+1
| | | | | | | * remove unnecessary when statement * remove outdated codes * use warnings
* Change stdlib imports to use std prefix in most examples (#17202)Danil Yarantsev2021-02-281-9/+9
|
* use single backtick (#17181)flywind2021-02-241-72/+72
|
* basic cleanups regarding SSL handling (#16940) [backport:1.0]Andreas Rumpf2021-02-081-1/+1
| | | | | | | * basic cleanups regarding SSL handling * enabled certificate checking on Windows * updated the SSL test * quoting helps
* fix some warnings (#16952)flywind2021-02-081-6/+6
|
* A new request should always have a new content-length (#16667)Joey2021-01-281-9/+15
| | | | | | | | | * A new request should always have a new content-length In [my last PR](https://github.com/nim-lang/Nim/pull/16618) I made a mistake by assuming that the client.headers were cleared on every request, like the Python version. So, due to the fact that Nim keeps the client headers, we need to clear the Content-Length header on each request (which makes sense because you almost never want to use the same Content-Length twice, but you may want to reuse other headers) * Move content-length to newHeaders instead of in the global client headers * Use single backticks
* Make small text changes in the docs (#16634)Elliot Waite2021-01-251-1/+1
| | | | | | | | | * Fix broken links in docs * Fix rand HSlice links * Make small text changes in the docs * Fix typo in contributing docs
* Fix SIGSEGV in httpclient response body (#16766)Daehee2021-01-221-4/+6
| | | | | | | | | * initialize httpclient response bodyStream; prevent SIGSEGV when getBody is false * Update lib/pure/httpclient.nim * Update lib/pure/httpclient.nim Co-authored-by: Andreas Rumpf <rumpf_a@web.de>
* Fix #16741 (#16783)Roman Inflianskas2021-01-221-22/+22
| | | | | | Move `downloadFileEx` out of `downloadFile` (solution, proposed by @Yardanico). Tested manually.
* Fixes #16436 (#16695)Yuriy Glukhov2021-01-141-3/+9
| | | | | * Fixes #16436 * Comments addressed
* fix broken CI (#16663)flywind2021-01-101-1/+1
|
* Httpclient improvements (#15919)Antonis Geralis2021-01-101-71/+122
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * Allow passing Uri instead of strings * Teach httpclient about 308 * Deprecate request proc where httpMethod is string * More use of HttpMethod enum Also fix handling of 308, I forgot to add the hunk to the previous commit. * Well behaved redirect handler * Also remove Transfer-Encoding * Removed unused proc * Secure redirection rules Strip sensitive headers for cross-domain redirects. * Allow httpMethod to be a string again This way unknown http verbs can be used without any problem. * Respect user-specified Host header * Missed multipart argument. * Try another method * add changelog * Fix hidden deprecation warning, parseEnum failing * This is wrong * Have to do it manually, parseEnum is not suitable * Review comments * update Co-authored-by: LemonBoy <thatlemon@gmail.com> Co-authored-by: Dominik Picheta <dominikpicheta@googlemail.com>
* DELETE requests should always have a content-length header (#16618)Joey2021-01-081-2/+5
| | | | | | | | | | * DELETE requests should always have a content-length header Not having DELETE in this list is causing hanging when trying to close webdriver sessions in [halonium](https://github.com/halonium/halonium/issues/10) and likely any other implementation of the webdriver protocol. Both at least chromedriver and geckodriver are affected by this issue. * Change the content length calculation to match the http spec For reference: https://www.w3.org/Protocols/HTTP/1.0/draft-ietf-http-spec.html#Entity-Body
* Fix broken links in docs (#16336)Elliot Waite2020-12-141-2/+2
| | | | | * Fix broken links in docs * Fix rand HSlice links
* Don't add content-length header on GET request when there is no body. (#16196)treeform2020-12-011-1/+1
| | | | | | | * Don't add content-length header on GET request when there is no body. * Add space between the not and the (. * Take Dom's suggestion.
* inline tiny proc (#15498)Juan Carlos2020-10-061-6/+6
|
* doc fix typo in lib/pure/httpclient.nim (#15364)Timothee Cour2020-09-191-1/+1
|
* fix several newline problems (#15028) [backend]Miran2020-07-211-1/+7
| | | | * prevent newlines where they shouldn't be * 'contentLength' shouldn't be negative
* Fix style inconsistencies due to the previous commitnarimiran2020-07-061-3/+3
|
* revert 0944b0f4narimiran2020-07-061-3/+3
|
* [backport] Docs: Fix broken `code-block` (#14749)ee72020-06-221-5/+5
| | | | | | | | This commit indents the contents of a `code-block` in `httpclient.nim` so that it displays correctly. The bug was introduced by 42a64245f8. I did a quick search for other `code-block`s that are broken in the same way, but the only other one I found (in `pegs.nim`) is not included in the generated documentation.
* Remove deprecated stuff from stdlib (#14699)Miran2020-06-171-1/+1
| | | | | | | * update to the latest Jester * remove deprecated procs from some stdlib modules * 'criterion' is not maintained anymore and relies on obsolete stuff
* httpcore: Add http code 308 Permanent Redirect (#14639)djazz2020-06-121-1/+1
| | | | | * httpcore: Add http code 308 * httpclient: Add 308 to redirection proc * fix typo
* move since from inclrtl to std/private/since (#14188)hlaaftana2020-05-021-1/+1
| | | | * move since from inclrtl to std/private/since * move since import in system below for HCR
* Error -> Defect for defects (#13908)Jacek Sieka2020-04-281-3/+3
| | | | | | | | | | | | | | * Error -> Defect for defects The distinction between Error and Defect is subjective, context-dependent and somewhat arbitrary, so when looking at an exception, it's hard to guess what it is - this happens often when looking at a `raises` list _without_ opening the corresponding definition and digging through layers of inheritance. With the help of a little consistency in naming, it's at least possible to start disentangling the two error types and the standard lib can set a good example here.
* New runnableExample for `newAsyncHttpClient()` (#14045)Tristram Oaten2020-04-211-0/+11
|
* Fix broken async httpclient exampleTristram Oaten2020-04-211-3/+7
| | | | | | | | | | | | | | | | | As the async httpclient is almost certainly the first async example beginners will want to try, we OWE it to them to give them a real example. Example repeated here for clarity: ```nim import asyncdispatch, httpclient proc asyncProc(): Future[string] {.async.} = var client = newAsyncHttpClient() return await client.getContent("http://example.com") echo waitFor asyncProc() ``` This is my first Nim contribution, please let me know if the code is right. (it runs on my machine, but may not be the best example)
* fix #13894, httpclient hang on Http204narimiran2020-04-071-1/+1
|