René's URL Explorer Experiment


Title: Callback-Based Response Retrieval · Issue #23 · love2d/lua-https · GitHub

Open Graph Title: Callback-Based Response Retrieval · Issue #23 · love2d/lua-https

X Title: Callback-Based Response Retrieval · Issue #23 · love2d/lua-https

Description: One of the limitation in lua-https is that it's not possible for application to create download progress bars on it (if the Content-Length header is available). This is because https.request will wait until all the response data is retri...

Open Graph Description: One of the limitation in lua-https is that it's not possible for application to create download progress bars on it (if the Content-Length header is available). This is because https.request will w...

X Description: One of the limitation in lua-https is that it's not possible for application to create download progress bars on it (if the Content-Length header is available). This is because https.request wi...

Opengraph URL: https://github.com/love2d/lua-https/issues/23

X: @github

direct link

Domain: github.com


Hey, it has json ld scripts:
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Callback-Based Response Retrieval","articleBody":"One of the limitation in `lua-https` is that it's not possible for application to create download progress bars on it (if the `Content-Length` header is available). This is because `https.request` will wait until all the response data is retrieved.\r\n\r\nMy proposal is to add optional 3rd and 4th parameter `callback` and `context`. Callback is defined as these fields:\r\n```lua\r\nlocal callback = {\r\n    -- `context` in here means user-supplied data (4th-parameter), which can be anything.\r\n    response = function(context, status, headers)\r\n        -- Called when HTTP status code and headers has been retrieved. Called once.\r\n        -- `status` is HTTP status code\r\n        -- `headers` is HTTP headers in **all lowercase** for the keys.\r\n    end,\r\n    body = function(context, data)\r\n        -- Called when new HTTP body data arrives. Called multiple times as new data arrives.\r\n        -- `data` is response data as Lua string.\r\n        -- Return \"falsy\" value and additional error message (default is \"aborted\") to abort the request\r\n        return true -- success\r\n        return false, \"aborted\" -- failure\r\n    end,\r\n    complete = function(context, err)\r\n        -- Called when data has been transferred, or an error occurs.\r\n        -- `err` will be the error message, or `nil` if everything worked as intended.\r\n    end,\r\n}\r\n```\r\n\r\nExample usage:\r\n```lua\r\nlocal data = {current = 0, length = 0}\r\n\r\nhttps.request(\"https://love2d.org\", {}, {\r\n    -- `context` in here means user-supplied data (4th-parameter), which can be anything.\r\n    response = function(context, status, headers)\r\n        print(\"HTTP status code\", status)\r\n        if headers[\"content-length\"] then\r\n            context.length = tonumber(headers[\"content-length\"]) or 0\r\n        end\r\n    end,\r\n    body = function(context, data)\r\n        context.current = context.current + #data\r\n        if context.length \u003e 0 then\r\n            print(string.format(\"Received data %d bytes (%.2f)\", #data, context.current * 100 / context.length))\r\n        else\r\n            print(string.format(\"Received data %d bytes\", #data))\r\n        end\r\n    end,\r\n    complete = function(context, err)\r\n        if err then\r\n            print(\"Download error\", err)\r\n        else\r\n            print(\"Download completed!\")\r\n        end\r\n    end,\r\n}, data)\r\n```\r\n\r\nAs an additional feature/requirement, the `callback` table can be a class object (not instance) by retrieving the function list using Lua C function that invokes metamethod and the `context` can be the class instance itself such that when a class is declared like this:\r\n\r\n```lua\r\nlocal MyDownloader = class \"MyDownloader\"\r\n\r\nfunction MyDownloader:response(status, headers)\r\nend\r\n\r\nfunction MyDownloader:body(data)\r\n    return true\r\nend\r\n\r\nfunction MyDownloader:complete(err)\r\nend\r\n```\r\n\r\nDoing something like this simply works and calls the appropriate functions.\r\n\r\n```lua\r\nlocal dlinstance = MyDownloader() -- new class instance\r\nhttps.request(\"https://love2d.org\", {}, MyDownloader, dlinstance)\r\n```\r\n\r\nThe return value of `https.request` when using this variant would be questionable.\r\n* Returning the status code, body, and the headers will preserve backward compatibility, but at same time make things redundant (the library has to keep everything until the function returns instead of discarding them).\r\n* Returning only `true` or `false` + error message (`assert`-compatible style) means less redundancy, but breaks backward compatibility.\r\n\r\nI probably can do this, but the question becomes \"should this is be done?\" and/or \"is this valid usecase to justify the feature addition?\".","author":{"url":"https://github.com/MikuAuahDark","@type":"Person","name":"MikuAuahDark"},"datePublished":"2023-07-02T05:02:17.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":9},"url":"https://github.com/23/lua-https/issues/23"}

route-pattern/_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format)
route-controllervoltron_issues_fragments
route-actionissue_layout
fetch-noncev2:0bbd6ebb-70d1-57d4-2672-fe0d68c3888b
current-catalog-service-hash81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114
request-id807A:1419FA:5AA262:81DF12:6A4D15B4
html-safe-nonce39f347bcbdb1d4c68fc9fc26a188e5c04ad2d956fc1b0ff27bd004789961b527
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4MDdBOjE0MTlGQTo1QUEyNjI6ODFERjEyOjZBNEQxNUI0IiwidmlzaXRvcl9pZCI6IjQzMzk5NDcyMjc1NTQwNTk3MDAiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ==
visitor-hmacde43ff89c43819c1a364c40b8c237803b1a8ea205f1aed2c1fe7501d1f61f652
hovercard-subject-tagissue:1784452858
github-keyboard-shortcutsrepository,issues,copilot
google-site-verificationApib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I
octolytics-urlhttps://collector.github.com/github/collect
analytics-location///voltron/issues_fragments/issue_layout
fb:app_id1401488693436528
apple-itunes-appapp-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/love2d/lua-https/23/issue_layout
twitter:imagehttps://opengraph.githubassets.com/09c01ca659688b8bec130e2a6421bb134792e1eb1415c79d56840a53554932a9/love2d/lua-https/issues/23
twitter:cardsummary_large_image
og:imagehttps://opengraph.githubassets.com/09c01ca659688b8bec130e2a6421bb134792e1eb1415c79d56840a53554932a9/love2d/lua-https/issues/23
og:image:altOne of the limitation in lua-https is that it's not possible for application to create download progress bars on it (if the Content-Length header is available). This is because https.request will w...
og:image:width1200
og:image:height600
og:site_nameGitHub
og:typeobject
og:author:usernameMikuAuahDark
hostnamegithub.com
expected-hostnamegithub.com
Nonebcb4661e6fb4fe8b394c51ea02ccdb2236d40dc59afc75a3bbba50bf6517134c
turbo-cache-controlno-preview
go-importgithub.com/love2d/lua-https git https://github.com/love2d/lua-https.git
octolytics-dimension-user_id283107
octolytics-dimension-user_loginlove2d
octolytics-dimension-repository_id435158752
octolytics-dimension-repository_nwolove2d/lua-https
octolytics-dimension-repository_publictrue
octolytics-dimension-repository_is_forkfalse
octolytics-dimension-repository_network_root_id435158752
octolytics-dimension-repository_network_root_nwolove2d/lua-https
turbo-body-classeslogged-out env-production page-responsive
disable-turbofalse
browser-stats-urlhttps://api.github.com/_private/browser/stats
browser-errors-urlhttps://api.github.com/_private/browser/errors
releasefb70bd3c4b2bec429781b65419e912c66e2d5581
ui-targetfull
theme-color#1e2327
color-schemelight dark

Links:

Skip to contenthttps://github.com/love2d/lua-https/issues/23#start-of-content
https://github.com/
Sign in https://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Flove2d%2Flua-https%2Fissues%2F23
GitHub CopilotWrite better code with AIhttps://github.com/features/copilot
GitHub Copilot appDirect agents from issue to mergehttps://github.com/features/ai/github-app
MCP RegistryNewIntegrate external toolshttps://github.com/mcp
ActionsAutomate any workflowhttps://github.com/features/actions
CodespacesInstant dev environmentshttps://github.com/features/codespaces
IssuesPlan and track workhttps://github.com/features/issues
Code ReviewManage code changeshttps://github.com/features/code-review
GitHub Advanced SecurityFind and fix vulnerabilitieshttps://github.com/security/advanced-security
Code securitySecure your code as you buildhttps://github.com/security/advanced-security/code-security
Secret protectionStop leaks before they starthttps://github.com/security/advanced-security/secret-protection
Why GitHubhttps://github.com/why-github
Documentationhttps://docs.github.com
Bloghttps://github.blog
Changeloghttps://github.blog/changelog
Marketplacehttps://github.com/marketplace
View all featureshttps://github.com/features
Enterpriseshttps://github.com/enterprise
Small and medium teamshttps://github.com/team
Startupshttps://github.com/enterprise/startups
Nonprofitshttps://github.com/solutions/industry/nonprofits
App Modernizationhttps://github.com/solutions/use-case/app-modernization
DevSecOpshttps://github.com/solutions/use-case/devsecops
DevOpshttps://github.com/solutions/use-case/devops
CI/CDhttps://github.com/solutions/use-case/ci-cd
View all use caseshttps://github.com/solutions/use-case
Healthcarehttps://github.com/solutions/industry/healthcare
Financial serviceshttps://github.com/solutions/industry/financial-services
Manufacturinghttps://github.com/solutions/industry/manufacturing
Governmenthttps://github.com/solutions/industry/government
View all industrieshttps://github.com/solutions/industry
View all solutionshttps://github.com/solutions
AIhttps://github.com/resources/articles?topic=ai
Software Developmenthttps://github.com/resources/articles?topic=software-development
DevOpshttps://github.com/resources/articles?topic=devops
Securityhttps://github.com/resources/articles?topic=security
View all topicshttps://github.com/resources/articles
Customer storieshttps://github.com/customer-stories
Events & webinarshttps://github.com/resources/events
Ebooks & reportshttps://github.com/resources/whitepapers
Business insightshttps://github.com/solutions/executive-insights
GitHub Skillshttps://skills.github.com
Documentationhttps://docs.github.com
Customer supporthttps://support.github.com
Community forumhttps://github.com/orgs/community/discussions
Trust centerhttps://github.com/trust-center
Partnershttps://github.com/partners
View all resourceshttps://github.com/resources
GitHub SponsorsFund open source developershttps://github.com/sponsors
Security Labhttps://securitylab.github.com
Maintainer Communityhttps://maintainers.github.com
Acceleratorhttps://github.com/accelerator
GitHub Starshttps://stars.github.com
Archive Programhttps://archiveprogram.github.com
Topicshttps://github.com/topics
Trendinghttps://github.com/trending
Collectionshttps://github.com/collections
Enterprise platformAI-powered developer platformhttps://github.com/enterprise
GitHub Advanced SecurityEnterprise-grade security featureshttps://github.com/security/advanced-security
Copilot for BusinessEnterprise-grade AI featureshttps://github.com/features/copilot/copilot-business
Premium SupportEnterprise-grade 24/7 supporthttps://github.com/premium-support
Pricinghttps://github.com/pricing
Search syntax tipshttps://docs.github.com/search-github/github-code-search/understanding-github-code-search-syntax
documentationhttps://docs.github.com/search-github/github-code-search/understanding-github-code-search-syntax
Sign in https://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Flove2d%2Flua-https%2Fissues%2F23
Sign up https://github.com/signup?ref_cta=Sign+up&ref_loc=header+logged+out&ref_page=%2F%3Cuser-name%3E%2F%3Crepo-name%3E%2Fvoltron%2Fissues_fragments%2Fissue_layout&source=header-repo&source_repo=love2d%2Flua-https
Reloadhttps://github.com/love2d/lua-https/issues/23
Reloadhttps://github.com/love2d/lua-https/issues/23
Reloadhttps://github.com/love2d/lua-https/issues/23
Please reload this pagehttps://github.com/love2d/lua-https/issues/23
love2d https://github.com/love2d
lua-httpshttps://github.com/love2d/lua-https
Notifications https://github.com/login?return_to=%2Flove2d%2Flua-https
Fork 30 https://github.com/login?return_to=%2Flove2d%2Flua-https
Star 69 https://github.com/login?return_to=%2Flove2d%2Flua-https
Code https://github.com/love2d/lua-https
Issues 9 https://github.com/love2d/lua-https/issues
Pull requests 1 https://github.com/love2d/lua-https/pulls
Actions https://github.com/love2d/lua-https/actions
Projects https://github.com/love2d/lua-https/projects
Security and quality 0 https://github.com/love2d/lua-https/security
Insights https://github.com/love2d/lua-https/pulse
Code https://github.com/love2d/lua-https
Issues https://github.com/love2d/lua-https/issues
Pull requests https://github.com/love2d/lua-https/pulls
Actions https://github.com/love2d/lua-https/actions
Projects https://github.com/love2d/lua-https/projects
Security and quality https://github.com/love2d/lua-https/security
Insights https://github.com/love2d/lua-https/pulse
Callback-Based Response Retrievalhttps://github.com/love2d/lua-https/issues/23#top
enhancementNew feature or requesthttps://github.com/love2d/lua-https/issues?q=state%3Aopen%20label%3A%22enhancement%22
https://github.com/MikuAuahDark
MikuAuahDarkhttps://github.com/MikuAuahDark
on Jul 2, 2023https://github.com/love2d/lua-https/issues/23#issue-1784452858
enhancementNew feature or requesthttps://github.com/love2d/lua-https/issues?q=state%3Aopen%20label%3A%22enhancement%22
https://github.com
Termshttps://docs.github.com/site-policy/github-terms/github-terms-of-service
Privacyhttps://docs.github.com/site-policy/privacy-policies/github-privacy-statement
Securityhttps://github.com/security
Statushttps://www.githubstatus.com/
Communityhttps://github.community/
Docshttps://docs.github.com/
Contacthttps://support.github.com?tags=dotcom-footer

Viewport: width=device-width


URLs of crawlers that visited me.