aboutsummaryrefslogtreecommitdiff
path: root/lib/http/sseclient
AgeCommit message (Collapse)Author
2026-01-15all: convert license and copyright to use SPDX identifiersShulhan
With help of spdxconv tool [1], we able to bulk update all files license and copyright format to comply with SPDX formats. [1] https://kilabit.info/project/spdxconv/
2025-02-04all: remove the nolint tagsShulhan
The "nolint" tag is used to ignore lines from being processed by golangci-lint. Since we are not using golangci-lint anymore, now and in the future, those lines can be removed.
2024-03-09lib/http: refactoring NewServer and NewClientShulhan
The NewServer and NewClient now accept non-pointer options, so the caller unable to modify the options once the server or client has been created.
2024-03-09lib/http: refactor of RegisterEndpoint and RegisterSSE to non-pointerShulhan
Once the endpoint registered, the caller should not able to changes any values on endpoint again.
2024-03-05all: comply with linter recommendations #3Shulhan
For HTTP server that use TLS, set the minimum TLS version and ReadHeaderTimeout to mitigate slowloris attack. For HTTP client or server that parameterize the use of InsecureSkipVerify, annotate the line with "nolint:gosec" to allow the code pass the check. Library that still use sha1, in example in DKIM and TOTP, skip the warnings by annotating the line with "nolint:gosec". A pointer variable now allocated their address before assigning its value. Any error that returned now wrapped using "%w". Also, replace error checking using [errors.Is] or [errors.As] instead of using equal or not-equal operators. In "lib/http", replace any usage of "math/rand" with "crypto/rand". Any call of [math/big.Rat.SetString] now annotated with "nolint:gosec" since its false positive, the issue has been fixed in Go >= 1.17.7. Any switch case that does not cover the rest of the possible values now handled by adding the cases or by replacing the "default" case with the rest of values.
2024-03-05all: comply with linter recommendations #2Shulhan
HTTP request now implicitly create request with context. Any false positive related to not closing HTTP response body has been annotated with "nolint:bodyclose". In the example code, use consistent "// Output:" comment format, by prefixing with single space. Any comment on code now also prefixing with single space. An error returned without variables now use [errors.New] instead of [fmt.Errorf]. Any error returned using [fmt.Errorf] now wrapped using "%w" instead of "%s". Also, replace error checking using [errors.Is] or [errors.As], instead of using equal/not-equal operator. Any statement like "x = x OP y" now replaced with "x OP= y". Also, swap statement is simplified using "x, y = y, x". Any switch statement with single case now replaced with if-condition. Any call to defer on function or program that call [os.Exit], now replaced by calling the deferred function directly. Any if-else condition now replaced with switch statement, if possible.
2024-03-05all: comply with linter recommendations #1Shulhan
Instead of annotating the lines that caught by linters, fix it to comply with the recommendations. This causes several breaking changes, especially related to naming, * api/slack: [Message.IconUrl] become [Message.IconURL] * lib/dns: DefaultSoaMinumumTtl become DefaultSoaMinimumTTL * lib/email: [Message.SetBodyHtml] become [Message.SetBodyHTML] * lib/http: [Client.GenerateHttpRequest] become [Client.GenerateHTTPRequest] * lib/http: [ClientOptions.ServerUrl] become [ClientOptions.ServerURL] * lib/http: [EndpointRequest.HttpWriter] become [EndpointRequest.HTTPWriter] * lib/http: [EndpointRequest.HttpRequest] become [EndpointRequest.HTTPRequest] * lib/http: [ServerOptions.EnableIndexHtml] become [ServerOptions.EnableIndexHTML] * lib/http: [SSEConn.HttpRequest] become [SSEConn.HTTPRequest] * lib/smtp: [ClientOptions.ServerUrl] become [ClientOptions.ServerURL] * lib/ssh/sftp: [FileAttrs.SetUid] become [FileAttrs.SetUID] * lib/ssh/sftp: [FileAttrs.Uid] become [FileAttrs.UID]
2024-03-02all: move the repository to "git.sr.ht/~shulhan/pakakeh.go"Shulhan
There are several reasons that why we move from github.com. First, related to the name of package. We accidentally name the package with "share" a common word in English that does not reflect the content of repository. By moving to other repository, we can rename it to better and unique name, in this "pakakeh.go". Pakakeh is Minang word for tools, and ".go" suffix indicate that the repository related to Go programming language. Second, supporting open source. The new repository is hosted under sourcehut.org, the founder is known to support open source, and all their services are licensed under AGPL, unlike GitHub that are closed sources. Third, regarding GitHub CoPilot. The GitHub Terms of Service [1], allow any public content that are hosted there granted them to parse the content. On one side, GitHub helps and flourish the open source, but on another side have an issues regarding scraping the copyleft license [2]. [1]: https://docs.github.com/en/site-policy/github-terms/github-terms-of-service#4-license-grant-to-us [2]: https://githubcopilotinvestigation.com
2023-12-17http/sseclient: fix data race on [Client.Close]Shulhan
The data race happened when Close set conn to nil but the consume method still on Read. The fix is by waiting for 100ms so consume goroutine can check if closeq is triggered from Close or not.
2023-12-17http/sseclient: fix Retry value not set to millisecondShulhan
When client receive "retry:" message, the value is in millisecond, but when we store it we only convert it to [time.Duration] which default to nanosecond. While at it, update comments on field [Client.Retry] and [Client.Insecure].
2023-12-13all: fix linter warnings reported by reviveShulhan
There are some reports that I disagree with revive, in example, code should not declare the type after variables. In my opinion, on some cases, declaring the type make the code more readable and explicit. Since I did not want to add new configuration file, we changes it and follow revive for now.
2023-12-03http/sseclient: add test for multi lines with empty line in middleShulhan
When running the EventSource client in Firefox, we found out that when server send a multi line content with empty line in the middle, the empty line is ignored by Firefox. Just to make sure we test it here and the server send it as expected event:message\ndata:line 1\ndata:\ndata:line2\ndata:\ndata:\n\n This case is similar with case number 3 when testing raw data. So probably this is bug in our implementation of SSE in another project.
2023-11-26http/sseclient: add method IDInt to EventShulhan
The IDInt return the ID as int64. If the ID cannot be converted to integer it would return 0.
2023-11-26lib/http: simplify SSEConn API, remove the WriteMessageShulhan
Using the WriteEvent alone, we can skip writing "event:" line if the passed "event" parameter is empty, and write the rest of data and/or id.
2023-11-26http/sseclient: implement Client retryShulhan
This changes everything. On the server we split the SSEEndpoint to new type SSEConn, so each callback use different instance of conn. On the Client, we need to store the parsed serverUrl and the passed header so it can be reused.
2023-11-26http/sseclient: remove double check for non-empty packetShulhan
Let the parseEvent handle and check for empty packet.
2023-11-26lib/http: add method WriteRaw to SSEEndpointShulhan
The WriteRaw method write raw event message directly, without any parsing.
2023-11-26lib/http: change id type in WriteEvent/WriteMessage parameter to pointerShulhan
Server can send empty ID to signal client that the ID has been reset or set to empty value.
2023-11-26lib/http: implement Server-Sent Events (SSE)Shulhan
For server SSE, we add new type SSEEndpoint, for registering endpoint that can handle SSE. For client SSE, we add it in new sub package "sseclient". Implements: https://todo.sr.ht/~shulhan/share/1 Implements: https://todo.sr.ht/~shulhan/share/2 Signed-off-by: Shulhan <ms@kilabit.info>