Commit Graph

201 Commits

Author SHA1 Message Date
xioren
7937abab44 Clean up imports in httpclient.nim (#17367)
* 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>
2021-03-14 11:14:44 +08:00
xioren
3d198fdcc2 Relocate 4xx/5xx exception in downloadFile (#17332) [backport:1.2]
Move 4xx/5xx exception to before disk i/o. As it stands an empty file is created on http error 4xx/5xx.
2021-03-12 08:09:39 +01:00
flywind
5670b848cb use .. warning:: (#17226)
* remove unnecessary when statement

* remove outdated codes

* use warnings
2021-03-04 11:34:55 +01:00
Danil Yarantsev
56461c280f Change stdlib imports to use std prefix in most examples (#17202) 2021-02-28 13:17:19 -08:00
flywind
fcb5cf643c use single backtick (#17181) 2021-02-24 21:47:27 -08:00
Andreas Rumpf
abac35e743 basic cleanups regarding SSL handling (#16940) [backport:1.0]
* basic cleanups regarding SSL handling
* enabled certificate checking on Windows
* updated the SSL test
* quoting helps
2021-02-08 13:54:03 +01:00
flywind
f140c92409 fix some warnings (#16952) 2021-02-08 13:50:15 +01:00
Joey
0d1c5f4137 A new request should always have a new content-length (#16667)
* 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
2021-01-28 00:07:08 +00:00
Elliot Waite
0436a7cffd Make small text changes in the docs (#16634)
* Fix broken links in docs

* Fix rand HSlice links

* Make small text changes in the docs

* Fix typo in contributing docs
2021-01-25 14:59:19 +01:00
Daehee
2d0cb18b9f Fix SIGSEGV in httpclient response body (#16766)
* 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>
2021-01-22 15:04:52 +01:00
Roman Inflianskas
fdf4f74cd1 Fix #16741 (#16783)
Move `downloadFileEx` out of `downloadFile` (solution, proposed by
@Yardanico).

Tested manually.
2021-01-22 00:29:24 +01:00
Yuriy Glukhov
4ae520711d Fixes #16436 (#16695)
* Fixes #16436

* Comments addressed
2021-01-14 08:53:21 +01:00
flywind
f82100ac93 fix broken CI (#16663) 2021-01-10 16:19:40 +00:00
Antonis Geralis
7bde6aa37f Httpclient improvements (#15919)
* 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>
2021-01-10 13:40:53 +00:00
Joey
bfcb7c1621 DELETE requests should always have a content-length header (#16618)
* 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
2021-01-08 18:48:23 +00:00
Elliot Waite
f3d57761ab Fix broken links in docs (#16336)
* Fix broken links in docs

* Fix rand HSlice links
2020-12-14 20:13:12 +01:00
treeform
cabfc7ec5c Don't add content-length header on GET request when there is no body. (#16196)
* 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.
2020-12-01 23:29:15 +01:00
Juan Carlos
695f955f70 inline tiny proc (#15498) 2020-10-06 16:52:12 +02:00
Timothee Cour
8ae4a774b7 doc fix typo in lib/pure/httpclient.nim (#15364) 2020-09-19 00:20:41 +02:00
Miran
5fafa2fd5c fix several newline problems (#15028) [backend]
* prevent newlines where they shouldn't be
* 'contentLength' shouldn't be negative
2020-07-21 22:49:08 +02:00
narimiran
46aacf917f Fix style inconsistencies due to the previous commit 2020-07-06 11:24:43 +02:00
narimiran
ebaf603c84 revert 0944b0f4 2020-07-06 10:55:51 +02:00
ee7
1e484ed62b [backport] Docs: Fix broken code-block (#14749)
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.
2020-06-22 08:12:50 +02:00
Miran
e7f280bd26 Remove deprecated stuff from stdlib (#14699)
* update to the latest Jester

* remove deprecated procs from some stdlib modules

* 'criterion' is not maintained anymore and relies on obsolete stuff
2020-06-17 15:25:02 +02:00
djazz
1168c75381 httpcore: Add http code 308 Permanent Redirect (#14639)
* httpcore: Add http code 308
* httpclient: Add 308 to redirection proc
* fix typo
2020-06-12 10:16:38 +02:00
hlaaftana
fbc97e712a move since from inclrtl to std/private/since (#14188)
* move since from inclrtl to std/private/since
* move since import in system below for HCR
2020-05-02 23:51:59 +02:00
Jacek Sieka
7d6cbf290a Error -> Defect for defects (#13908)
* 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.
2020-04-28 19:56:01 +02:00
Tristram Oaten
1a44b7e3ce New runnableExample for newAsyncHttpClient() (#14045) 2020-04-21 14:47:06 +02:00
Tristram Oaten
42a64245f8 Fix broken async httpclient example
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)
2020-04-21 00:00:30 +01:00
narimiran
3036ec9c44 fix #13894, httpclient hang on Http204 2020-04-07 22:21:39 +01:00
Federico Ceratto
5b85444244 SSL certificate verify GitHub action (#13697)
* Implement SSL/TLS certificate checking #782

* SSL: Add nimDisableCertificateValidation

Remove NIM_SSL_CERT_VALIDATION env var
tests/untestable/thttpclient_ssl.nim ran successfully on Linux with libssl 1.1.1d

* SSL: update integ test to skip flapping tests

* Revert .travis.yml change

* nimDisableCertificateValidation disable imports

Prevent loading symbols that are not defined on older SSL libs

* SSL: disable verification in net.nim

..when nimDisableCertificateValidation is set

* Update changelog

* Fix peername type

* Add define check for windows

* Disable test on windows

* Add exprimental GitHub action CI for SSL

* Test nimDisableCertificateValidation
2020-03-20 17:11:39 +01:00
Zed
e056298ceb Implement file streaming for httpclient's MultipartData (#12982)
* Add `uploadFile` to POST files by streaming them

* Use constant for \c\L

* Formatting

* Remove uploadFile

* Implement MultipartData file streaming

* Remove unnecessary var annotations

* Call string on TaintedStrings

Fixes #12789

* Move cl constant to httpcore

* Fix `request` inconsistencies

* Update documentaion

* Clean up

* Skip multipart formatting when there's 0 entries

* Remove extraneous `cl` from multipart formatting

* Update MultipartData `$` to match old behaviour

* Update comment

* Address comments
2020-03-06 18:55:45 +00:00
Juan Carlos
2fad7f134f httpclient, maxredirects to Natural, newHttpClient/newAsyncHttpClient add headers argument instead of hardcoded empty (#13207) 2020-01-21 19:34:47 +01:00
Sam Wang
441cacf70f Added fix for handling TaintedStrings in streams and httpclient (#12969)
* Added fix for taint mode in streams and httpclient

* Removed taintMode export from system.nim
2019-12-29 17:37:22 +01:00
Jack Tang
21ea1094ef Allow customize Host header 2019-12-28 17:26:02 +00:00
Pierre-Jean Grenier
a114a40b57 fix httpclient.lastModified bad pattern in parsing (#12698) 2019-11-29 11:17:10 +01:00
3n-k1
0944b0f441 [backport] Fix style issues in lib/, tools/, and testament/. Fixes #12687. (#12754) 2019-11-28 08:32:11 +01:00
Andy Davidoff
bd8f49cbd3 replace some runtime repr in stdlib for gc:arc (#12716) 2019-11-25 10:13:30 +01:00
Andreas Rumpf
e5478b32a8 fixes #11863 multipart data need $ (#12707)
* fixes #11863
* improved the code; refs #12412
2019-11-22 14:21:03 +01:00
treeform
5ba932e43c About 50% faster base64 implemention. (#12436) 2019-10-17 09:50:00 +02:00
narimiran
0ca9cc7419 [backport] run nimpretty on web stuff 2019-09-30 13:58:11 +02:00
narimiran
f7a8fc46c0 Revert "improvements for httpcore (#12228)"
This reverts commit b865c2a54b.
2019-09-23 19:06:55 +02:00
Andreas Rumpf
b865c2a54b improvements for httpcore (#12228)
* improvements for httpcore
* further improvements, now stable API but needs extensions later on
2019-09-23 12:38:35 +02:00
Dominik Picheta
8117a949c5 Remove old and unused parseBody/parseResponse procs in httpclient. (#11949) 2019-08-26 20:27:44 +02:00
Dominik Picheta
b095203f28 Fixes regression introduced by #11904. (#11948) 2019-08-15 06:05:38 +02:00
konradmb
addd7b5e20 Fix issue #10726 - HTTP response without Content-Length is not accessible (#11904)
* Add patch by @xenogenesi

* Async test for HTTP/1.1 without Content-Length

* Apply suggestions from code review

Co-Authored-By: Dominik Picheta <dominikpicheta@googlemail.com>
2019-08-08 08:41:56 +02:00
Oscar Nihlgård
1f32498a47 Use std/monotimes in the stdlib 2019-07-16 11:05:42 +02:00
Araq
bc7733827d make more parts of the stdlib compile with --styleCheck:error 2019-07-10 15:48:30 +02:00
Juan Carlos
22a1b12038 [documentation] fix #11281, httpclient examples (#11455) 2019-06-10 09:31:57 +02:00
Boris Shomodjvarac
de6b2e88d2 added getSocket proc (#11233) 2019-05-15 17:47:25 +02:00