diff --git a/CHANGELOG.md b/CHANGELOG.md index 5aa0e43..b7138a8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,7 +16,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 providing a Git repository * CLI commands for searching the AUR & directly adding packages * HTTP routes for removing packages, arch-repos & repos -* All endpoints serving files now support HTTP byte range requests ### Changed @@ -26,7 +25,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 * Branch name for 'git' targets is now optional; if not provided, the repository will be cloned with the default branch * Build containers now explicitely set the PATH variable -* Refactor of web framework ### Removed diff --git a/README.md b/README.md index 29ec0f0..5911ea2 100644 --- a/README.md +++ b/README.md @@ -48,8 +48,15 @@ update`. ### Compiler -I used to maintain a mirror that tracked the latest master, but nowadays, I -solely target V 0.3 as a compiler. +Vieter compiles with the standard Vlang compiler. However, I do maintain a +[mirror](https://git.rustybever.be/vieter-v/v). This is to ensure my CI does +not break without reason, as I control when & how frequently the mirror is +updated to reflect the official repository. + +If you encounter issues using the latest V compiler, try using my mirror +instead. `make v` will clone the repository & build the mirror. Afterwards, +prepending any make command with `V_PATH=v/v` tells make to use the locally +compiled mirror instead. ## Contributing diff --git a/src/client/client.v b/src/client/client.v index 24e4444..2bb1ac2 100644 --- a/src/client/client.v +++ b/src/client/client.v @@ -2,7 +2,7 @@ module client import net.http { Method } import net.urllib -import web.response { Response } +import response { Response } import json pub struct Client { diff --git a/src/client/logs.v b/src/client/logs.v index b52c3d0..f242f6e 100644 --- a/src/client/logs.v +++ b/src/client/logs.v @@ -2,7 +2,7 @@ module client import models { BuildLog, BuildLogFilter } import net.http { Method } -import web.response { Response } +import response { Response } import time // get_build_logs returns all build logs. diff --git a/src/client/targets.v b/src/client/targets.v index f5258a4..82c7878 100644 --- a/src/client/targets.v +++ b/src/client/targets.v @@ -2,7 +2,7 @@ module client import models { Target, TargetFilter } import net.http { Method } -import web.response { Response } +import response { Response } // get_targets returns a list of targets, given a filter object. pub fn (c &Client) get_targets(filter TargetFilter) ?[]Target { diff --git a/src/web/response/response.v b/src/response/response.v similarity index 100% rename from src/web/response/response.v rename to src/response/response.v diff --git a/src/server/api_logs.v b/src/server/api_logs.v index 6728392..fa3338e 100644 --- a/src/server/api_logs.v +++ b/src/server/api_logs.v @@ -3,7 +3,7 @@ module server import web import net.http import net.urllib -import web.response { new_data_response, new_response } +import response { new_data_response, new_response } import db import time import os diff --git a/src/server/api_targets.v b/src/server/api_targets.v index 4cc3a58..3867c94 100644 --- a/src/server/api_targets.v +++ b/src/server/api_targets.v @@ -2,7 +2,7 @@ module server import web import net.http -import web.response { new_data_response, new_response } +import response { new_data_response, new_response } import db import models { Target, TargetArch, TargetFilter } diff --git a/src/server/repo.v b/src/server/repo.v index 242fd2d..2253a44 100644 --- a/src/server/repo.v +++ b/src/server/repo.v @@ -7,7 +7,7 @@ import time import rand import util import net.http -import web.response { new_response } +import response { new_response } // healthcheck just returns a string, but can be used to quickly check if the // server is still responsive. diff --git a/src/server/repo_remove.v b/src/server/repo_remove.v index 316b387..642f26f 100644 --- a/src/server/repo_remove.v +++ b/src/server/repo_remove.v @@ -2,13 +2,13 @@ module server import web import net.http -import web.response { new_response } +import response { new_response } // delete_package tries to remove the given package. ['/:repo/:arch/:pkg'; delete] fn (mut app App) delete_package(repo string, arch string, pkg string) web.Result { if !app.is_authorized() { - return app.json(.unauthorized, new_response('Unauthorized.')) + return app.json(http.Status.unauthorized, new_response('Unauthorized.')) } res := app.repo.remove_pkg_from_arch_repo(repo, arch, pkg, true) or { diff --git a/src/web/consts.v b/src/web/consts.v index 1b5bf08..7b1d2b4 100644 --- a/src/web/consts.v +++ b/src/web/consts.v @@ -9,7 +9,7 @@ pub struct Result {} pub const ( methods_with_form = [http.Method.post, .put, .patch] headers_close = http.new_custom_header_from_map({ - 'Server': 'Vieter' + 'Server': 'VWeb' http.CommonHeader.connection.str(): 'close' }) or { panic('should never fail') } diff --git a/src/web/web.v b/src/web/web.v index 8434a80..51acd2f 100644 --- a/src/web/web.v +++ b/src/web/web.v @@ -91,22 +91,15 @@ fn (mut ctx Context) send_reader(mut reader io.Reader, size u64) ? { } } -// send_custom_response sends the given http.Response to the client. It can be -// used to overwrite the Context object & send a completely custom -// http.Response instead. -fn (mut ctx Context) send_custom_response(resp &http.Response) ? { - ctx.send_string(resp.bytestr())? -} - // send_response_header constructs a valid HTTP response with an empty body & // sends it to the client. pub fn (mut ctx Context) send_response_header() ? { mut resp := http.Response{ header: ctx.header.join(headers_close) } + resp.set_version(.v1_1) resp.set_status(ctx.status) - - ctx.send_custom_response(resp)? + ctx.send_string(resp.bytestr())? } // send is a convenience function for sending the HTTP response with an empty @@ -229,8 +222,10 @@ pub fn (mut ctx Context) status(status http.Status) Result { // server_error Response a server error pub fn (mut ctx Context) server_error(ecode int) Result { - ctx.send_custom_response(http_500) or {} - + $if debug { + eprintln('> ctx.server_error ecode: $ecode') + } + ctx.send_string(http_500.bytestr()) or {} return Result{} } @@ -239,17 +234,23 @@ pub fn (mut ctx Context) redirect(url string) Result { mut resp := http_302 resp.header = resp.header.join(ctx.header) resp.header.add(.location, url) - - ctx.send_custom_response(resp) or {} - + ctx.send_string(resp.bytestr()) or { return Result{} } return Result{} } // not_found Send an not_found response pub fn (mut ctx Context) not_found() Result { - ctx.send_custom_response(http_404) or {} + return ctx.status(http.Status.not_found) +} - return Result{} +// add_header Adds an header to the response with key and val +pub fn (mut ctx Context) add_header(key string, val string) { + ctx.header.add_custom(key, val) or {} +} + +// get_header Returns the header data from the key +pub fn (ctx &Context) get_header(key string) string { + return ctx.req.header.get_custom(key) or { '' } } interface DbInterface {