mirror of
https://github.com/status-im/nim-chronos.git
synced 2026-08-27 04:51:15 +00:00
* Docs: Tutorials: HTTP Client: Chapter 1. * Docs: Tutorials: HTTP Client: Chapter 2 (WIP). * Docs: Tutorials: HTTP Client: Chapter 2. * Docs: Uptimemon: Chapter 2: Replace status.im with mock.codes for reliable 403 response. * Docs: Tutorials: HTTP Client: Chapter 3. * Docs: Tutorials: HTTP Client: Chapter 4 (WIP). * Docs: Tutorials: HTTP Client: Chapter 4 (WIP). * Docs: Tutorials: HTTP Client: Chapter 4. * Docs: Tutorials: HTTP Client: Chapter 5 (WIP). * Docs: Tutorials: HTTP Client: Chapter 5. * Docs: Tutorials: HTTP Client: Chapter 6. * Docs: Tutorials: HTTP Client: Add links to the source code. * Build API docs for modules in apps/http. * Fix exception printing. * Docs: Tutorials: HTTP Client: Chapter 1: Add ref links. * Docs: Tutorials: HTTP Client: Add ref links to all chapters. * CI: Add shiftinclude. * CI: Add shiftinclude. * Docs: Chapter 1: Replace hardcoded code snippets with includes. * Docs: Uptimemon: Replace line numbers with anchors. * Docs: Uptimemon: Chapter 1: Improve exception handling. * Docs: Uptimemon: Chapter 2: Replace copypasta with includes. * Docs: Uptimemon: Chapter 3: Replace copypasta with includes. * Docs: Uptimemon: Chapter 4: Replace copypasta with includes. * Docs: Uptimemon: Chapter 5: Replace copypasta with includes. * Docs: Uptimemon: Fix missing exceptions. * Docs: Uptimemon: Chapter 6: Replace copypasta with includes. * HTTP client tutorial: Rename directory to http_client. * HTTP client tutorial: Switch from single files to Nimble projects in examples. * Docs: Concepts: Clarify noCancel usage. * Docs: HTTP Client: Remove info about noCancel usage. * Docs: HTTP Client: Remove redundant noCancel. * Examples: Remove redundant noCancel. * Docs: HTTP Client: Fix info about session purpose. * Docs: HTTP Client: Fix the section about serial vs. concurrent requests. * Examples: HTTP Client: Require Chronos >= 4.2.2. We're using cancelAndWait which is not available in earlier versions. * Examples: HTTP Client: Update check[uris] to handle cancellation. * Docs: HTTP Client: Add info about cancellation policy in check[uris]. * Docs: HTTP Client: Add a general tip about HTTP protocol. * Examples: HTTP Client: Use valueOr instead of isErr. * Docs: HTTP Client: Remove a weasel word. * Docs: HTTP Client: Fix text about error checking on request creation. * Docs: HTTP Client: Split address resolution from async requests. DNS resolution is always blocking. If it's part of the URI check, we're randomly blocking the event loop forcing timeouts on healthy URIs. * Docs: HTTP Client: Optimize marker lookup to detect valid HTML in checked URIs. * Docs: HTTP Client: Add finally block to close request. * Ignore documentation samples technical files. * Update .github/workflows/doc.yml Co-authored-by: Jacek Sieka <jacek@status.im> * Update .github/workflows/doc.yml Co-authored-by: Jacek Sieka <jacek@status.im> * Update .github/workflows/doc.yml Co-authored-by: Jacek Sieka <jacek@status.im> * Docs: HTTP Client: Chapter 6: Handle AsyncSemaphoreError in check. * Docs: HTTP Client: Chapter 6: Update text about AsyncSemaphoreError. * Docs: HTTP Client: Add chapter on session reuse. The new chapter is now chapter 2. Chapter 3 is now about concurrency and the rest of the chapters are shifted. * Docs: HTTP Client: Chapter 6: Rewrite marker lookup to use strings instead of a moving windows of array of bytes. * Add readOnce flavor that reads directly to a string. * Docs: HTTP Client: Timeout: Use wait instead of withTimeout. The new chapter is now chapter 2. Chapter 3 is now about concurrency and the rest of the chapters are shifted. * Docs: HTTP Client: Add a page about handling erroneous URIs. The new chapter is now chapter 2. Chapter 3 is now about concurrency and the rest of the chapters are shifted. * Docs: HTTP client: Rewrite chapter about streaming, fix code samples. * Update docs/src/tutorials/http_client/chapter1.md Co-authored-by: Jacek Sieka <jacek@status.im> * Docs: Examples: HTTP Client: Close bodyReader after use. * Docs: HTTP Client: Update stdout messages. * Docs: Examples: HTTP Client: Close bodyReader *properly*; close requests. * Docs: HTTP Client: Remove chapter about invalid URI handling and DNS resolution. * Docs: HTTP Client: Add a note aboutt timer drift. * Docs: HTTP Client: Add more info about drift. * Remove string-aiming readOnce variant. * Docs: HTTP Client: Add request and response finalization and closing. * Remove compiled binary. * Docs: Examples: HTTP Client: Work around a bug with except in let block. * Docs: HTTP Client: Refactor chapter about streaming. * Docs: HTTP Client: Fix typo. * Remove compiled binaries. * Docs: HTTP Client: Update code samples to use refactored findMarker. * Docs: HTTP Client: Replace getCurrentExceptionMsg with e.msg. * Move examples out of docs. Fixes #662. * Docs: HTTP Client: Replace e.msg with getCurrentExceptionMsg. * Docs: HTTP Client: Chapter 4: Clarify the usage of `except ... as ...` syntax. --------- Co-authored-by: Jacek Sieka <jacek@status.im>
17 lines
536 B
Nim
17 lines
536 B
Nim
import chronos/apps/http/httpclient
|
|
|
|
proc retrievePage*(uri: string): Future[string] {.async.} =
|
|
# Create a new HTTP session
|
|
let httpSession = HttpSessionRef.new()
|
|
try:
|
|
# Fetch page contents
|
|
let resp = await httpSession.fetch(parseUri(uri))
|
|
# Convert response to a string, assuming its encoding matches the terminal!
|
|
bytesToString(resp.data)
|
|
finally: # Close the session
|
|
await httpSession.closeWait()
|
|
|
|
echo waitFor retrievePage(
|
|
"https://raw.githubusercontent.com/status-im/nim-chronos/master/README.md"
|
|
)
|