aboutsummaryrefslogtreecommitdiff
path: root/httpd.go
AgeCommit message (Collapse)Author
2026-01-26all: remove prefix "rescached:" on loggingShulhan
Adding those prefix make the log context redundant in journald.
2025-02-08internal/cmd/gocheck: add internal static analyzersShulhan
Instead of using binary fieldalignment and shadow, run them by creating command that call the same Analyzer internally. This analyzers help finding possible panic on httpd.go.
2024-03-27all: comply with lintersShulhan
Fix the code as recommended by linters, for example using context for HTTP client request, using 0600 for file permission, using string concatenation instead of fmt, using "%w" for error, and reorder defer.
2024-03-21all: replace module "share" with "pakakeh.go"Shulhan
The module "share" has been moved to new repository at SourceHut and we rename it to make it more unique instead of common English words "share".
2024-02-04all: apply recommendation from linter reviveShulhan
2023-09-23go.mod: update all dependencies and set Go mod version to 1.20Shulhan
The update on share module affect the following changes, * lib/dns: removing dns.ZoneRecords, replacing it with map[string][]*dns.ResourceRecord * lib/dns: file Name in Zone renamed to Origin * lib/dns: replace call to Caches.InternalPopulate with InternalPopulateZone that accept zone as parameter
2023-04-01all: update go doc commentsShulhan
While at it, use "_" for unused parameter on methods.
2022-06-12all: un-export HostsFiles and Zones fields on EnvironmentShulhan
Previously those fields exported because web client need it to initialize the content for /hosts.d and /zone.d pages. Since we now have HTTP API for that, web client can call get request to the respective API without depends on the environment.
2022-06-12all: trim the zone's name from request on HTTP API zone.d record deleteShulhan
When calling API for zone.d record delete, client send the fully qualified domain name on record to be deleted, but caches store only the subdomains internally. This cause the delete action fail, because no internal record match with request.
2022-06-12all: make GET /api/hosts.d to return list of hosts.d if name is emptyShulhan
This is to provide an HTTP API to fetch list of hosts.d files on the server.
2022-06-12all: fixes HTTP API for updating environmentShulhan
There are two issues when updating environment. One is on the front, where debug value is send as string. Another one is the back, where new environment overwrite all of options where it should only update only DNS server options and Debug fields.
2022-06-12_www/block.d: fix the variable names on hosts block.dShulhan
In the commit 0b92dbb8463d, we changes the field HostsBlocks in Environment to HostBlockd, but we forgot to changes the code in the web. This changes fix this issue.
2022-06-09go.mod: update to share module v0.38.0Shulhan
This changes affect the dns Server where all caches related methods has been moved to field Caches.
2022-06-09all: change the HTTP API to update hosts in block.dShulhan
We have HTTP API to enable or disable block.d by batch by passing all block.d records. The name of HTTP API is /v2/block.d/update and this is duplicate with API to update the content of hosts in block.d. This changes fix this by creating new HTTP API /v2/block.d/fetch that fetch the latest hosts file from specific block.d by its name. While at it, - reformat html and JavaScript files using js-beautify - rename constants and methods for HTTP APIs - add and update comments for some HTTP APIs
2022-05-22all: implement HTTP API to fetch list of block.dShulhan
Given the following request, GET /api/block.d It will return list of hosts in block.d as JSON format: { "data": { "<name>": <Blockd> ... } }
2022-05-22all: export and rename the hostsBlock type to BlockdShulhan
In the Environment, we have a field HostsBlocks that reference an unexported type hostsFile. In order for any package to be able to use this field, we need to export this type. While at it, we rename the type from hostsBlock to Blockd to make it simple and consistent with name.
2022-05-17cmd/resolver: implement command to delete record on zoneShulhan
Given the following command $ resolver zone.d rr delete <zone> <"@" | subdomain> <type> <class> <value> It will delete the record in zone by given subdomain, type, class, and value.
2022-05-16all: use consistent parameter name for zone nameShulhan
Some zone APIs use "name" and some use "zone" for passing the zone name. This changes made all zone APIs to use "name" as parameter name.
2022-05-16all: implement HTTP API to fetch records in zoneShulhan
Sending the following request to HTTP server: GET /api/zone.d/rr?zone=<string> where zone parameter is the zone name, it will return list of records in that zone.
2022-05-16all: fix comment regarding HTTP path on HTTP handlersShulhan
2022-05-16all: add new HTTP API to get all zonesShulhan
The HTTP API has the following format, GET /api/zone.d On success, it will return HTTP status code 200 with all zone formatted as JSON in the body.
2022-05-15all: split zoneRecordRequest type into separate fileShulhan
2022-05-15all: refactoring the HTTP API for deleting zone recordShulhan
Previously, the HTTP API for deleting a record is by passing the parameters as JSON in the body. This may cause issue if HTTP client does not support sending body in DELETE method. This changes the method to pass the parameters in the query, DELETE /zone.d/rr?zone=<string>&type=<string>&record=<base64 json> Parameters, - zone: the zone name, - type: the record type, - record: the content of record with its domain name and value.
2022-05-14all: refactoring HTTP API for adding new zone.d recordShulhan
Previously, the request for adding new record on zone file is by passing the zone name and type inside the path, /zone.d/:name/rr/:type This commit changes it to pass all parameters inside the request body as JSON, { "zone": <string>, "kind": <string>, "record": <base64 string|base64 JSON> } For example, to add A record for subdomain "www" to zone file "my.zone", the request format would be, { "zone": "my.zone", "kind": "A", "record": "eyJOYW1lIjoid3d3IiwiVmFsdWUiOiIxMjcuMC4wLjEifQ==" } Where "record" value is equal to `{"Name":"www","Value":"127.0.0.1"}`. On the response, we changes it to return only the new record instead of all record in the zone.
2022-05-14cmd/resolver: implement command to create and delete zone fileShulhan
The command to create new zone file has the following signature: zone.d create <name> While command to delete zone file has the following signature: zone.d delete <name>
2022-05-14all: refactor the HTTP API for zone.dShulhan
Previously, the the HTTP API for creating and deleting zone file is by passing the zone file name in path of URL. This changes move the parameter name to POST body when creating new zone file and in the DELETE query when deleting zone file.
2022-05-13cmd/resolver: implement command to delete record on hosts fileShulhan
The command has the following signature, resolver hosts.d rr delete <name> <domain> Given the hosts name "hosts" and domain "my.hosts" it will delete all records that have domain name "my.hosts" inside the file.
2022-04-25all: refactor the APIs to manage hosts.d resource records (RR)Shulhan
There are two APIs to manage hosts.d RR: create and delete. Previously, the create API pass the hosts name inside and values inside the path, POST /hosts.d/<name>/rr?domain=&value= This commit changes the request type to form, so all parameters move to body, POST /hosts.d/rr Content-Type: application/x-www-form-urlencoded name=&domain=&value= On delete API, we changes the name parameter to be send on query parameter along with domain to be deleted. Previously, the delete API was DELETE /hosts.d/<name>/rr?domain= now it become DELETE /hosts.d/rr?name=&domain=
2022-04-24all: return the hosts file in response of hosts.d create and deleteShulhan
Instead of returning empty data, return the affected hosts file when creating a new one or when deleting existing one.
2022-04-23all: change the hosts.d HTTP API request type to form and queryShulhan
Using dynamic value in the URL path is not a good practice, so we move the API for hosts.d to create, delete, and get to form and query parameters.
2022-04-22all: changes the block.d update API request type to x-www-form-urlencodedShulhan
Instead of passing whole block.d object with single field Name set, send the request using urlencoded form.
2022-04-21all: implement HTTP API to enable or disable hosts on block.dShulhan
The URL /api/block.d/enable activate the hosts in block.d, while The URL /api/block.d/disable deactivate the hosts in block.d. Both of this API accept single parameter "name" in the body as application/x-www-form-urlencoded.
2022-04-20all: implement HTTP API to update hosts.dShulhan
The API receive the block.d name and if it valid, the server will fetch latest hosts file from the block provider based on the registered URL.
2022-04-19all: rename the page and HTTP API for hosts_blocks to block.dShulhan
This is to make all terminology to be consistent, from configuration to page URL, and API.
2022-04-19all: add option to set the base directoryShulhan
Previously, running an instance of rescached assume that all configurations and cache are located in /etc/rescached and /var/cache/rescached. It possible that we may want to use different base directory (or $PREFIX, in the auto tools terms), for example "/opt/rescached" or as showed in the "dev" task in the Makefile, we use "_test" as base directory for running test instance. This changes also fix an error when loading hosts file from non-existant hosts.d directory.
2022-04-19all: refactoring the hosts blocks format and locationShulhan
This changes add new directory called "block.d" under rescached. This directory contains hosts file fetched from URL defined in hosts block configuration. In this way, we did not mixed between user created hosts file and external hosts file. In the configuration file, we changes the hosts block format from single line hosts_block = <URL> into subsection with dynamic name, [block.d "<name>"] name = <name> url = <URL>
2022-04-16cmd/resolver: implement sub command to update environmentShulhan
The env command now accept sub command "update" with argument path to the file or "-" for standard input. The content of file is formatted using JSON, the same as output of "env" command. If the content of file is valid, server will be restarted immediately.
2022-04-16all: apply suggestions from linterShulhan
List of changes, * Remove unused constants keyIsEnabled, keyIsSystem, and keyLastUpdated. * Use the method String on instance of Duration instead of fmt.Sprintf. * Replace any usage of io/ioutil package with its replacement. * Check for error from calling Environment.init and Zone.Add. * Prefix all returned error on hostsBlock.update method. * Add "lint" task as part of default target, build.
2022-04-15all: implement API to remove all cachesShulhan
On the HTTP side, if the query parameter "name" for "DELETE /api/caches" is "all" it will remove all caches. On the resolver side, if the parameter for "caches remove" is "all" it will remove all caches. This changes require latest lib/dns on share module.
2022-04-15all: implement sub command to remove caches by domain nameShulhan
The "caches" command accept second sub command "remove" that accept single domain name to be removed from caches. This changes affect the HTTP API for caches delete to return the removed answer on the response data.
2022-04-11all: replace internal response with lib/http.EndpointResponseShulhan
Both types are similar, since the lib/http already imported we replace the internal response to minimize duplicate and confusion later. While at it, use consistent variable naming and declaration using var in all methods.
2022-03-15all: change the rescached license to GPL 3.0 or laterShulhan
See https://kilabit.info/journal/2022/gpl/ for more information.
2021-12-21all: move HTTP server option to EnvironmentShulhan
Previously, the options for HTTP server initialized internally, which make it uneasy to changes the default rescached instance when running in development mode. This commit move the HTTP server initialization inside the Environment init method. If its nil, the init will set the default HTTP server options along with the Memfs.
2021-12-19all: refactoring Server initializationShulhan
Previously, we initialize the rescached Server by passing the path to configuration file and initialize the environment inside the server. This commit changes it to pass the instance of Environment. The idea is to allow creating and running rescached Server without creating configuration file first.
2021-12-04all: sync with latest share moduleShulhan
This changes update the code based on refactoring on lib/dns package on share module.
2021-07-13go.mod: update to latest share moduleShulhan
Changes affected by update, * lib/http: changes on Endpoint.Call function signature * lib/http: changes on CORS configuration * lib/test: changes on the Assert function signature
2021-01-22_www: display the list of caches in front pageShulhan
When user open the rescached web interface, the front page will render and refresh the list of non-local caches per 10 seconds.
2021-01-20all: rewrite the web user interface and the APIsShulhan
2021-01-12all: update with latest share modulesShulhan
This changes affect how the memfs.New and GoGenenerate called, does not affect the user.
2020-09-06all: various changesShulhan
* Add function to search and remove non-local caches * Refactoring no how to create and remove record from hosts file