aboutsummaryrefslogtreecommitdiff
path: root/lib/http/http.go
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/
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
2024-02-20lib/http: add constanta for header Set-CookieShulhan
2024-01-25lib/path: new package to work with pathShulhan
The path package provide a new type Route, detached from "lib/http". A Route represent a parsed path. A path can have a key, or binding, that can be replaced with string value. For example, "/org/:user/:repo" have two keys "user" and "repo". Route handle the path in case-insensitive manner.
2024-01-24lib/http: add support for If-Modified-Since in HandleFSShulhan
If the node modification time is less than requested time value in request header If-Modified-Since, server will response with 304 Not Modified.
2024-01-24lib/http: use raw string literal for string constantsShulhan
While at it, group the constants by its values.
2024-01-24lib/http: update doc to use comment linksShulhan
2024-01-24lib/http: refactoring Range request, limit content served by serverShulhan
When server receive, GET /big Range: bytes=0- and the requested resources is quite larger, where writing all content of file result in i/o timeout, it is best practice [1][2] if the server write only partial content and let the client continue with the subsequent Range request. In the above case, the server should response with, HTTP/1.1 206 Partial content Content-Range: bytes 0-<limit>/<size> Content-Length: <limit> Where limit is maximum packet that is reasonable [3] for most of the client. In this server we choose 8MB as limit. [1]: https://stackoverflow.com/questions/63614008/how-best-to-respond-to-an-open-http-range-request [2]: https://bugzilla.mozilla.org/show_bug.cgi?id=570755 [3]: https://docs.aws.amazon.com/whitepapers/latest/s3-optimizing-performance-best-practices/use-byte-range-fetches.html
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-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>
2023-09-11lib/http: add comment to ErrClientDownloadNoOutput and type RangePositionShulhan
2023-03-12lib/http: add function to parse multipart Range response for ClientShulhan
The ParseMultipartRange parse the multipart/byteranges body or response from HTTP Range request. Each Content-Range position and body part in the multipart will be stored under RangePosition.
2023-03-12lib/http: add support for HTTP Range in ServerShulhan
For HTTP Server using HandleFS, the Range request is handled automatically. For other HTTP server, user can use the HandleRange function. The HandleRange function handle [HTTP Range] request using "bytes" unit. The body parameter contains the content of resource being requested that accept Seek method. If the Request method is not GET, or no Range in header request it will return all the body [RFC7233 S-3.1]. The contentType is optional, if its empty, it will detected by http.ResponseWriter during Write. [HTTP Range]: https://developer.mozilla.org/en-US/docs/Web/HTTP/Range_requests [RFC7233 S-3.1]: https://datatracker.ietf.org/doc/html/rfc7233#section-3.1 # Conflicts: # CHANGELOG.adoc
2022-05-09all: reformat all codes using gofmt 1.19 (the Go tip)Shulhan
2022-04-06all: replace any usage of ioutil package with os or ioShulhan
Since Go 1.16, the ioutil package has been deprecated. This changes replace any usage that use functions from ioutil package with their replacement from package os or package io.
2022-01-30lib/http: implement method Download() on ClientShulhan
The Download method get a resource from remote server and write it into DownloadRequest.Output (a io.Writer).
2022-01-30lib/http: detach method setHeaders from ClientShulhan
This will allow calling setHeaders without instance of Client.
2021-09-22lib/http: support server caching file system using ETagShulhan
If the Server handle file system using MemFS, server will set the ETag [1] header using the file epoch as value. On the next request, server will compare the request header If-None-Match with the requested file epoch. If its equal server will return the response as 304 StatusNotModified. [1] https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/ETag
2021-03-14http: add constants for content type multipart formShulhan
2021-03-05http: update package documentation with latest changesShulhan
Change the Callback and ErrorCallbackHandler parameter to EndpointRequest.
2021-02-10http: revert the HeaderBearer back to HeaderAuthKeyBearerShulhan
The "Bearer" string is not in the header key but in the value of "Authorization". While at it, add HTTP header names for "Host" and "Cookie".
2021-02-10http: change signature of IPAddressOfRequestShulhan
Previously, the IPAddressOfRequest accept only one parameter, the http.Request. This make the function only works on HTTP server from standard library, not from other library (for example websocket) or other protocol that use HTTP header too. This commit changes the parameter to http.Header and default address. If no headers present, then the default address will be used.
2021-02-07http: add methods IPAddressOfRequest and ParseXForwardedForShulhan
The IPAddressOfRequest get the client IP address from HTTP request header "X-Real-IP" or "X-Forwarded-For" or from Request.RemoteAddr, which ever non-empty first. The ParseXForwardedFor parse the HTTP header "X-Forwarded-For" value from the following format "client, proxy1, proxy2" into client address and list of proxy addressess.
2021-02-06http: add prefix Header to constants AcceptEncoding and ContentEncodingShulhan
Since both of those constants are used only for HTTP header, it could be more clear if we prefix it with "Header". Also, rename "HeaderAuthKeyBearer" to "HeaderBearer" and sort the list of header constants.
2021-01-31http: add section Summary to illustrate how everything are connectedShulhan
The Summary section contains pseudocode that illustrate how Endpoint, Callback, and CallbackErrorHandler works when the Server receive HTTP request. Its provide an overview of how everythins connected in Server.
2021-01-31http: fix the package documentationShulhan
The RegisterXxx methods on Server has been replaced with single method, RegisterEndpoint.
2021-01-10http: update documentation on how to use memory file systemShulhan
2020-11-27http: allow Endpoint to register custom error handlerShulhan
The new field ErrorHandler on Endpoint allow the implementor to define their own function to handler error from Endpoint.Call. If the ErrorHandler is nil it will default to DefaultErrorHandler.
2020-09-09http: add constanst for header "Authorization" and key "Bearer"Shulhan
2020-05-13http: support CORS with white list of origin and headersShulhan
The list of origin and headers are set on ServerOptions. Once their set, any OPTIONS request with Access-Control-Request-Method and/or Accces-Control-Request-Headers will be automatically check and responsed with apropriate white list.
2020-05-12http: prefix the header constants with "Header"Shulhan
2020-04-22http: automatically uncompress the response body from serverShulhan
If the content-type of response body from server is text or JSON and Content-Encoding is one of the compression methods (bzip2, compress, deflate, or gzip) then uncompress them before returning it to user.
2019-10-21all: fix and add missing commentsShulhan
2019-09-23http: update the package documentationShulhan
2019-09-23http: add content and response type HTML and XMLShulhan
2019-09-12http: implement key binding in registered Endpoint's PathShulhan
Previously, only raw path can be registered on Endpoint. This changes implement key binding using colon ":" on path. For example, registering path "/:x/y" will bind key "x" to a string value that can be accessed on http.Request.Form using Get method.
2019-08-05lib/memfs: add method to encode the content of fileShulhan
The ContentEncode() method encode each node's content into specific encoding, in other words this method can be used to compress the content of file in memory before being served or written to file. Only file with size greater than 0 will be encoded. List of known encoding is "gzip".
2019-02-19http: add the charset type to content-type "text/plain"Shulhan
2019-02-19http: add method to temporary redirect request to other locationShulhan
The temporary redirect use the HTTP status 307. If redirect URL is empty then its default to root.
2019-01-05lib/http: add parameter http.ResponseWriter to CallbackShulhan
The ResponseWriter can be used to write custom header or to write cookies.
2018-12-17lib/http: export content type constantsShulhan
2018-12-16Add documentation for lib/httpShulhan
2018-12-16lib/http: new package for simplifying writing HTTP serverShulhan