mirror of
https://github.com/vlang/v.git
synced 2025-09-13 14:32:26 +03:00
fmt: fix alignment of struct init fields (#22025)
This commit is contained in:
parent
99da5726db
commit
c51d30bf53
671 changed files with 18817 additions and 18787 deletions
|
@ -116,10 +116,10 @@ pub fn (mut am AssetManager) add(asset_type AssetType, file_path string, include
|
|||
}
|
||||
|
||||
asset := Asset{
|
||||
kind: asset_type
|
||||
file_path: real_path
|
||||
kind: asset_type
|
||||
file_path: real_path
|
||||
last_modified: time.unix(last_modified_unix)
|
||||
include_name: include_name
|
||||
include_name: include_name
|
||||
}
|
||||
|
||||
match asset_type {
|
||||
|
|
|
@ -75,7 +75,7 @@ fn test_add_minify_missing_cache_dir() {
|
|||
|
||||
fn test_add_minified() {
|
||||
mut am := assets.AssetManager{
|
||||
minify: true
|
||||
minify: true
|
||||
cache_dir: cache_dir('test_add_minified')
|
||||
}
|
||||
clean_cache_dir(am.cache_dir)
|
||||
|
@ -108,7 +108,7 @@ fn test_combine_minified() {
|
|||
// minify test is simple for now, because assets are not properly minified yet
|
||||
mut am := assets.AssetManager{
|
||||
cache_dir: cache_dir('test_combine_minified')
|
||||
minify: true
|
||||
minify: true
|
||||
}
|
||||
clean_cache_dir(am.cache_dir)
|
||||
|
||||
|
@ -124,7 +124,7 @@ fn test_combine_minified() {
|
|||
|
||||
fn test_minify_cache_last_modified() {
|
||||
mut am := assets.AssetManager{
|
||||
minify: true
|
||||
minify: true
|
||||
cache_dir: cache_dir('test_cache_last_modified')
|
||||
}
|
||||
clean_cache_dir(am.cache_dir)
|
||||
|
@ -149,7 +149,7 @@ fn test_minify_cache_last_modified() {
|
|||
|
||||
fn test_cleanup_cache() {
|
||||
mut am := assets.AssetManager{
|
||||
minify: true
|
||||
minify: true
|
||||
cache_dir: cache_dir('test_cleanup_cache')
|
||||
}
|
||||
clean_cache_dir(am.cache_dir)
|
||||
|
|
|
@ -34,7 +34,7 @@ pub fn controller[A, X](path string, mut global_app A) !&ControllerPath {
|
|||
// generate struct with closure so the generic type is encapsulated in the closure
|
||||
// no need to type `ControllerHandler` as generic since it's not needed for closures
|
||||
return &ControllerPath{
|
||||
path: path
|
||||
path: path
|
||||
handler: fn [mut global_app, path, routes, controllers_sorted] [A, X](ctx &Context, mut url urllib.URL, host string) &Context {
|
||||
// transform the url
|
||||
url.path = url.path.all_after_first(path)
|
||||
|
|
|
@ -59,8 +59,8 @@ pub fn (mut ctx CsrfContext) set_csrf_token[T](mut user_context T) string {
|
|||
// clear the csrf token and cookie header from the context
|
||||
pub fn (ctx &CsrfContext) clear_csrf_token[T](mut user_context T) {
|
||||
user_context.set_cookie(http.Cookie{
|
||||
name: config.cookie_name
|
||||
value: ''
|
||||
name: config.cookie_name
|
||||
value: ''
|
||||
max_age: 0
|
||||
})
|
||||
}
|
||||
|
@ -73,7 +73,7 @@ pub fn (ctx &CsrfContext) csrf_token_input() vweb.RawHtml {
|
|||
// middleware returns a handler that you can use with vweb's middleware
|
||||
pub fn middleware[T](config CsrfConfig) vweb.MiddlewareOptions[T] {
|
||||
return vweb.MiddlewareOptions[T]{
|
||||
after: false
|
||||
after: false
|
||||
handler: fn [config] [T](mut ctx T) bool {
|
||||
ctx.config = config
|
||||
if ctx.exempt {
|
||||
|
@ -99,14 +99,14 @@ pub fn set_token(mut ctx vweb.Context, config &CsrfConfig) string {
|
|||
// the hmac key is set as a cookie and later validated with `app.token` that must
|
||||
// be in an html form
|
||||
ctx.set_cookie(http.Cookie{
|
||||
name: config.cookie_name
|
||||
value: cookie
|
||||
name: config.cookie_name
|
||||
value: cookie
|
||||
same_site: config.same_site
|
||||
http_only: true
|
||||
secure: config.secure
|
||||
path: config.cookie_path
|
||||
expires: expire_time
|
||||
max_age: config.max_age
|
||||
secure: config.secure
|
||||
path: config.cookie_path
|
||||
expires: expire_time
|
||||
max_age: config.max_age
|
||||
})
|
||||
|
||||
return token
|
||||
|
|
|
@ -11,15 +11,15 @@ const exit_after_time = 12000 // milliseconds
|
|||
|
||||
const session_id_cookie_name = 'session_id'
|
||||
const csrf_config = &csrf.CsrfConfig{
|
||||
secret: 'my-256bit-secret'
|
||||
allowed_hosts: ['*']
|
||||
secret: 'my-256bit-secret'
|
||||
allowed_hosts: ['*']
|
||||
session_cookie: session_id_cookie_name
|
||||
}
|
||||
|
||||
const allowed_origin = 'example.com'
|
||||
const csrf_config_origin = csrf.CsrfConfig{
|
||||
secret: 'my-256bit-secret'
|
||||
allowed_hosts: [allowed_origin]
|
||||
secret: 'my-256bit-secret'
|
||||
allowed_hosts: [allowed_origin]
|
||||
session_cookie: session_id_cookie_name
|
||||
}
|
||||
|
||||
|
@ -50,7 +50,7 @@ fn test_protect() {
|
|||
}
|
||||
ctx = vweb.Context{
|
||||
form: form
|
||||
req: http.Request{
|
||||
req: http.Request{
|
||||
method: .post
|
||||
}
|
||||
}
|
||||
|
@ -63,10 +63,10 @@ fn test_protect() {
|
|||
fn test_timeout() {
|
||||
timeout := 1
|
||||
short_time_config := &csrf.CsrfConfig{
|
||||
secret: 'my-256bit-secret'
|
||||
allowed_hosts: ['*']
|
||||
secret: 'my-256bit-secret'
|
||||
allowed_hosts: ['*']
|
||||
session_cookie: session_id_cookie_name
|
||||
max_age: timeout
|
||||
max_age: timeout
|
||||
}
|
||||
|
||||
mut ctx := vweb.Context{}
|
||||
|
@ -84,7 +84,7 @@ fn test_timeout() {
|
|||
}
|
||||
ctx = vweb.Context{
|
||||
form: form
|
||||
req: http.Request{
|
||||
req: http.Request{
|
||||
method: .post
|
||||
}
|
||||
}
|
||||
|
@ -111,7 +111,7 @@ fn test_valid_origin() {
|
|||
req.add_header(.referer, 'http://${allowed_origin}/test')
|
||||
mut ctx := vweb.Context{
|
||||
form: form
|
||||
req: req
|
||||
req: req
|
||||
}
|
||||
|
||||
mut valid := csrf.protect(mut ctx, csrf_config_origin)
|
||||
|
@ -132,7 +132,7 @@ fn test_invalid_origin() {
|
|||
req.add_header(.origin, 'http://${allowed_origin}')
|
||||
mut ctx := vweb.Context{
|
||||
form: form
|
||||
req: req
|
||||
req: req
|
||||
}
|
||||
|
||||
mut valid := csrf.protect(mut ctx, csrf_config_origin)
|
||||
|
@ -145,7 +145,7 @@ fn test_invalid_origin() {
|
|||
req.add_header(.referer, 'http://${allowed_origin}/test')
|
||||
ctx = vweb.Context{
|
||||
form: form
|
||||
req: req
|
||||
req: req
|
||||
}
|
||||
|
||||
valid = csrf.protect(mut ctx, csrf_config_origin)
|
||||
|
@ -157,7 +157,7 @@ fn test_invalid_origin() {
|
|||
req.add_cookie(name: csrf_config.cookie_name, value: cookie)
|
||||
ctx = vweb.Context{
|
||||
form: form
|
||||
req: req
|
||||
req: req
|
||||
}
|
||||
|
||||
valid = csrf.protect(mut ctx, csrf_config_origin)
|
||||
|
@ -245,7 +245,7 @@ fn test_token_input() {
|
|||
fn protect_route_util(path string) {
|
||||
mut req := http.Request{
|
||||
method: .post
|
||||
url: 'http://${localserver}/${path}'
|
||||
url: 'http://${localserver}/${path}'
|
||||
}
|
||||
mut res := req.do() or { panic(err) }
|
||||
assert res.status() == .forbidden
|
||||
|
@ -273,8 +273,8 @@ fn protect_route_util(path string) {
|
|||
|
||||
req = http.Request{
|
||||
method: .post
|
||||
url: 'http://${localserver}/${path}'
|
||||
data: formdata
|
||||
url: 'http://${localserver}/${path}'
|
||||
data: formdata
|
||||
header: header
|
||||
}
|
||||
req.add_cookie(name: csrf_config.cookie_name, value: cookie)
|
||||
|
@ -285,8 +285,8 @@ fn protect_route_util(path string) {
|
|||
|
||||
req = http.Request{
|
||||
method: .post
|
||||
url: 'http://${localserver}/${path}'
|
||||
data: formdata
|
||||
url: 'http://${localserver}/${path}'
|
||||
data: formdata
|
||||
header: header
|
||||
}
|
||||
req.add_cookie(name: csrf_config.cookie_name, value: cookie)
|
||||
|
|
|
@ -58,7 +58,7 @@ pub fn (mut m Middleware[T]) use(options MiddlewareOptions[T]) {
|
|||
pub fn (mut m Middleware[T]) route_use(route string, options MiddlewareOptions[T]) {
|
||||
middleware := RouteMiddleware{
|
||||
url_parts: route.split('/').filter(it != '')
|
||||
handler: voidptr(options.handler)
|
||||
handler: voidptr(options.handler)
|
||||
}
|
||||
|
||||
if options.after {
|
||||
|
@ -123,7 +123,7 @@ fn validate_middleware[T](mut ctx T, raw_handlers []voidptr) bool {
|
|||
// Example: app.use(vweb.encode_gzip[Context]())
|
||||
pub fn encode_gzip[T]() MiddlewareOptions[T] {
|
||||
return MiddlewareOptions[T]{
|
||||
after: true
|
||||
after: true
|
||||
handler: fn [T](mut ctx T) bool {
|
||||
// TODO: compress file in streaming manner, or precompress them?
|
||||
if ctx.return_type == .file {
|
||||
|
|
|
@ -28,35 +28,35 @@ fn (rp RoutePair) test_param(expected []string) {
|
|||
fn test_route_no_match() {
|
||||
tests := [
|
||||
RoutePair{
|
||||
url: '/a'
|
||||
url: '/a'
|
||||
route: '/a/b/c'
|
||||
},
|
||||
RoutePair{
|
||||
url: '/a/'
|
||||
url: '/a/'
|
||||
route: '/a/b/c'
|
||||
},
|
||||
RoutePair{
|
||||
url: '/a/b'
|
||||
url: '/a/b'
|
||||
route: '/a/b/c'
|
||||
},
|
||||
RoutePair{
|
||||
url: '/a/b/'
|
||||
url: '/a/b/'
|
||||
route: '/a/b/c'
|
||||
},
|
||||
RoutePair{
|
||||
url: '/a/c/b'
|
||||
url: '/a/c/b'
|
||||
route: '/a/b/c'
|
||||
},
|
||||
RoutePair{
|
||||
url: '/a/c/b/'
|
||||
url: '/a/c/b/'
|
||||
route: '/a/b/c'
|
||||
},
|
||||
RoutePair{
|
||||
url: '/a/b/c/d'
|
||||
url: '/a/b/c/d'
|
||||
route: '/a/b/c'
|
||||
},
|
||||
RoutePair{
|
||||
url: '/a/b/c'
|
||||
url: '/a/b/c'
|
||||
route: '/'
|
||||
},
|
||||
]
|
||||
|
@ -68,19 +68,19 @@ fn test_route_no_match() {
|
|||
fn test_route_exact_match() {
|
||||
tests := [
|
||||
RoutePair{
|
||||
url: '/a/b/c'
|
||||
url: '/a/b/c'
|
||||
route: '/a/b/c'
|
||||
},
|
||||
RoutePair{
|
||||
url: '/a/b/c/'
|
||||
url: '/a/b/c/'
|
||||
route: '/a/b/c'
|
||||
},
|
||||
RoutePair{
|
||||
url: '/a'
|
||||
url: '/a'
|
||||
route: '/a'
|
||||
},
|
||||
RoutePair{
|
||||
url: '/'
|
||||
url: '/'
|
||||
route: '/'
|
||||
},
|
||||
]
|
||||
|
@ -91,99 +91,99 @@ fn test_route_exact_match() {
|
|||
|
||||
fn test_route_params_match() {
|
||||
RoutePair{
|
||||
url: '/a/b/c'
|
||||
url: '/a/b/c'
|
||||
route: '/:a/b/c'
|
||||
}.test_match()
|
||||
|
||||
RoutePair{
|
||||
url: '/a/b/c'
|
||||
url: '/a/b/c'
|
||||
route: '/a/:b/c'
|
||||
}.test_match()
|
||||
|
||||
RoutePair{
|
||||
url: '/a/b/c'
|
||||
url: '/a/b/c'
|
||||
route: '/a/b/:c'
|
||||
}.test_match()
|
||||
|
||||
RoutePair{
|
||||
url: '/a/b/c'
|
||||
url: '/a/b/c'
|
||||
route: '/:a/b/:c'
|
||||
}.test_match()
|
||||
|
||||
RoutePair{
|
||||
url: '/a/b/c'
|
||||
url: '/a/b/c'
|
||||
route: '/:a/:b/:c'
|
||||
}.test_match()
|
||||
|
||||
RoutePair{
|
||||
url: '/one/two/three'
|
||||
url: '/one/two/three'
|
||||
route: '/:a/:b/:c'
|
||||
}.test_match()
|
||||
|
||||
RoutePair{
|
||||
url: '/one/b/c'
|
||||
url: '/one/b/c'
|
||||
route: '/:a/b/c'
|
||||
}.test_match()
|
||||
|
||||
RoutePair{
|
||||
url: '/one/two/three'
|
||||
url: '/one/two/three'
|
||||
route: '/:a/b/c'
|
||||
}.test_no_match()
|
||||
|
||||
RoutePair{
|
||||
url: '/one/two/three'
|
||||
url: '/one/two/three'
|
||||
route: '/:a/:b/c'
|
||||
}.test_no_match()
|
||||
|
||||
RoutePair{
|
||||
url: '/one/two/three'
|
||||
url: '/one/two/three'
|
||||
route: '/:a/b/:c'
|
||||
}.test_no_match()
|
||||
|
||||
RoutePair{
|
||||
url: '/a/b/c/d'
|
||||
url: '/a/b/c/d'
|
||||
route: '/:a/:b/:c'
|
||||
}.test_no_match()
|
||||
|
||||
RoutePair{
|
||||
url: '/1/2/3/4'
|
||||
url: '/1/2/3/4'
|
||||
route: '/:a/:b/:c'
|
||||
}.test_no_match()
|
||||
|
||||
RoutePair{
|
||||
url: '/a/b'
|
||||
url: '/a/b'
|
||||
route: '/:a/:b/:c'
|
||||
}.test_no_match()
|
||||
|
||||
RoutePair{
|
||||
url: '/1/2'
|
||||
url: '/1/2'
|
||||
route: '/:a/:b/:c'
|
||||
}.test_no_match()
|
||||
}
|
||||
|
||||
fn test_route_params() {
|
||||
RoutePair{
|
||||
url: '/a/b/c'
|
||||
url: '/a/b/c'
|
||||
route: '/:a/b/c'
|
||||
}.test_param(['a'])
|
||||
|
||||
RoutePair{
|
||||
url: '/one/b/c'
|
||||
url: '/one/b/c'
|
||||
route: '/:a/b/c'
|
||||
}.test_param(['one'])
|
||||
|
||||
RoutePair{
|
||||
url: '/one/two/c'
|
||||
url: '/one/two/c'
|
||||
route: '/:a/:b/c'
|
||||
}.test_param(['one', 'two'])
|
||||
|
||||
RoutePair{
|
||||
url: '/one/two/three'
|
||||
url: '/one/two/three'
|
||||
route: '/:a/:b/:c'
|
||||
}.test_param(['one', 'two', 'three'])
|
||||
|
||||
RoutePair{
|
||||
url: '/one/b/three'
|
||||
url: '/one/b/three'
|
||||
route: '/:a/b/:c'
|
||||
}.test_param(['one', 'three'])
|
||||
}
|
||||
|
@ -192,91 +192,91 @@ fn test_route_params_array_match() {
|
|||
// array can only be used on the last word (TODO: add parsing / tests to ensure this)
|
||||
|
||||
RoutePair{
|
||||
url: '/a/b/c'
|
||||
url: '/a/b/c'
|
||||
route: '/a/b/:c...'
|
||||
}.test_match()
|
||||
|
||||
RoutePair{
|
||||
url: '/a/b/c/d'
|
||||
url: '/a/b/c/d'
|
||||
route: '/a/b/:c...'
|
||||
}.test_match()
|
||||
|
||||
RoutePair{
|
||||
url: '/a/b/c/d/e'
|
||||
url: '/a/b/c/d/e'
|
||||
route: '/a/b/:c...'
|
||||
}.test_match()
|
||||
|
||||
RoutePair{
|
||||
url: '/one/b/c/d/e'
|
||||
url: '/one/b/c/d/e'
|
||||
route: '/:a/b/:c...'
|
||||
}.test_match()
|
||||
|
||||
RoutePair{
|
||||
url: '/one/two/c/d/e'
|
||||
url: '/one/two/c/d/e'
|
||||
route: '/:a/:b/:c...'
|
||||
}.test_match()
|
||||
|
||||
RoutePair{
|
||||
url: '/one/two/three/four/five'
|
||||
url: '/one/two/three/four/five'
|
||||
route: '/:a/:b/:c...'
|
||||
}.test_match()
|
||||
|
||||
RoutePair{
|
||||
url: '/a/b'
|
||||
url: '/a/b'
|
||||
route: '/:a/:b/:c...'
|
||||
}.test_no_match()
|
||||
|
||||
RoutePair{
|
||||
url: '/a/b/'
|
||||
url: '/a/b/'
|
||||
route: '/:a/:b/:c...'
|
||||
}.test_no_match()
|
||||
}
|
||||
|
||||
fn test_route_params_array() {
|
||||
RoutePair{
|
||||
url: '/a/b/c'
|
||||
url: '/a/b/c'
|
||||
route: '/a/b/:c...'
|
||||
}.test_param(['c'])
|
||||
|
||||
RoutePair{
|
||||
url: '/a/b/c/d'
|
||||
url: '/a/b/c/d'
|
||||
route: '/a/b/:c...'
|
||||
}.test_param(['c/d'])
|
||||
|
||||
RoutePair{
|
||||
url: '/a/b/c/d/'
|
||||
url: '/a/b/c/d/'
|
||||
route: '/a/b/:c...'
|
||||
}.test_param(['c/d'])
|
||||
|
||||
RoutePair{
|
||||
url: '/a/b/c/d/e'
|
||||
url: '/a/b/c/d/e'
|
||||
route: '/a/b/:c...'
|
||||
}.test_param(['c/d/e'])
|
||||
|
||||
RoutePair{
|
||||
url: '/one/b/c/d/e'
|
||||
url: '/one/b/c/d/e'
|
||||
route: '/:a/b/:c...'
|
||||
}.test_param(['one', 'c/d/e'])
|
||||
|
||||
RoutePair{
|
||||
url: '/one/two/c/d/e'
|
||||
url: '/one/two/c/d/e'
|
||||
route: '/:a/:b/:c...'
|
||||
}.test_param(['one', 'two', 'c/d/e'])
|
||||
|
||||
RoutePair{
|
||||
url: '/one/two/three/d/e'
|
||||
url: '/one/two/three/d/e'
|
||||
route: '/:a/:b/:c...'
|
||||
}.test_param(['one', 'two', 'three/d/e'])
|
||||
}
|
||||
|
||||
fn test_route_index_path() {
|
||||
RoutePair{
|
||||
url: '/'
|
||||
url: '/'
|
||||
route: '/:path...'
|
||||
}.test_param(['/'])
|
||||
|
||||
RoutePair{
|
||||
url: '/foo/bar'
|
||||
url: '/foo/bar'
|
||||
route: '/:path...'
|
||||
}.test_param(['/foo/bar'])
|
||||
}
|
||||
|
|
|
@ -8,7 +8,7 @@ const localserver = 'http://localhost:${port}'
|
|||
const exit_after = time.second * 10
|
||||
const allowed_origin = 'https://vlang.io'
|
||||
const cors_options = vweb.CorsOptions{
|
||||
origins: [allowed_origin]
|
||||
origins: [allowed_origin]
|
||||
allowed_methods: [.get, .head]
|
||||
}
|
||||
|
||||
|
@ -53,7 +53,7 @@ fn testsuite_begin() {
|
|||
|
||||
fn test_valid_cors() {
|
||||
x := http.fetch(http.FetchConfig{
|
||||
url: localserver
|
||||
url: localserver
|
||||
method: .get
|
||||
header: http.new_header_from_map({
|
||||
.origin: allowed_origin
|
||||
|
@ -66,7 +66,7 @@ fn test_valid_cors() {
|
|||
|
||||
fn test_preflight() {
|
||||
x := http.fetch(http.FetchConfig{
|
||||
url: localserver
|
||||
url: localserver
|
||||
method: .options
|
||||
header: http.new_header_from_map({
|
||||
.origin: allowed_origin
|
||||
|
@ -84,7 +84,7 @@ fn test_preflight() {
|
|||
|
||||
fn test_invalid_origin() {
|
||||
x := http.fetch(http.FetchConfig{
|
||||
url: localserver
|
||||
url: localserver
|
||||
method: .get
|
||||
header: http.new_header_from_map({
|
||||
.origin: 'https://google.com'
|
||||
|
@ -96,7 +96,7 @@ fn test_invalid_origin() {
|
|||
|
||||
fn test_invalid_method() {
|
||||
x := http.fetch(http.FetchConfig{
|
||||
url: '${localserver}/post'
|
||||
url: '${localserver}/post'
|
||||
method: .post
|
||||
header: http.new_header_from_map({
|
||||
.origin: allowed_origin
|
||||
|
|
|
@ -73,7 +73,7 @@ fn test_large_request_header() {
|
|||
str := buf.bytestr()
|
||||
// make 1 header longer than vwebs max read limit
|
||||
mut x := http.fetch(http.FetchConfig{
|
||||
url: localserver
|
||||
url: localserver
|
||||
header: http.new_custom_header_from_map({
|
||||
'X-Overflow-Header': str
|
||||
})!
|
||||
|
@ -86,7 +86,7 @@ fn test_bigger_content_length() {
|
|||
data := '123456789'
|
||||
mut x := http.fetch(http.FetchConfig{
|
||||
method: .post
|
||||
url: '${localserver}/post_request'
|
||||
url: '${localserver}/post_request'
|
||||
header: http.new_header_from_map({
|
||||
.content_length: '10'
|
||||
})
|
||||
|
@ -101,7 +101,7 @@ fn test_smaller_content_length() {
|
|||
data := '123456789'
|
||||
mut x := http.fetch(http.FetchConfig{
|
||||
method: .post
|
||||
url: '${localserver}/post_request'
|
||||
url: '${localserver}/post_request'
|
||||
header: http.new_header_from_map({
|
||||
.content_length: '5'
|
||||
})
|
||||
|
|
|
@ -85,7 +85,7 @@ fn test_support_http_1() {
|
|||
// send the Connection: close header. If that header is present the connection
|
||||
// needs to be closed and a `Connection: close` header needs to be send back
|
||||
mut x := http.fetch(http.FetchConfig{
|
||||
url: 'http://${localserver}/'
|
||||
url: 'http://${localserver}/'
|
||||
header: http.new_header_from_map({
|
||||
.connection: 'close'
|
||||
})
|
||||
|
|
|
@ -50,7 +50,7 @@ pub fn (mut app App) new_article(mut ctx Context) vweb.Result {
|
|||
}
|
||||
article := Article{
|
||||
title: title
|
||||
text: text
|
||||
text: text
|
||||
}
|
||||
println('posting article')
|
||||
println(article)
|
||||
|
@ -85,7 +85,7 @@ struct ApiSuccessResponse[T] {
|
|||
fn (mut app App) json_success[T](mut ctx Context, result T) {
|
||||
response := ApiSuccessResponse[T]{
|
||||
success: true
|
||||
result: result
|
||||
result: result
|
||||
}
|
||||
|
||||
ctx.json(response)
|
||||
|
@ -95,7 +95,7 @@ fn (mut app App) json_success[T](mut ctx Context, result T) {
|
|||
fn (mut app App) some_helper[T](result T) ApiSuccessResponse[T] {
|
||||
response := ApiSuccessResponse[T]{
|
||||
success: true
|
||||
result: result
|
||||
result: result
|
||||
}
|
||||
return response
|
||||
}
|
||||
|
|
|
@ -180,7 +180,7 @@ struct User {
|
|||
fn test_http_client_json_post() {
|
||||
ouser := User{
|
||||
name: 'Bilbo'
|
||||
age: 123
|
||||
age: 123
|
||||
}
|
||||
json_for_ouser := json.encode(ouser)
|
||||
mut x := http.post_json('http://${localserver}/json_echo', json_for_ouser) or { panic(err) }
|
||||
|
@ -218,9 +218,9 @@ fn test_http_client_multipart_form_data() {
|
|||
|
||||
mut files := []http.FileData{}
|
||||
files << http.FileData{
|
||||
filename: 'vweb'
|
||||
filename: 'vweb'
|
||||
content_type: 'text'
|
||||
data: '"vweb test"'
|
||||
data: '"vweb test"'
|
||||
}
|
||||
|
||||
mut form_config_files := http.PostMultipartFormConfig{
|
||||
|
@ -257,7 +257,7 @@ fn test_query_params_are_passed_as_arguments() {
|
|||
|
||||
fn test_host() {
|
||||
mut req := http.Request{
|
||||
url: 'http://${localserver}/with_host'
|
||||
url: 'http://${localserver}/with_host'
|
||||
method: .get
|
||||
}
|
||||
|
||||
|
@ -281,8 +281,8 @@ fn testsuite_end() {
|
|||
// This test is guaranteed to be called last.
|
||||
// It sends a request to the server to shutdown.
|
||||
x := http.fetch(
|
||||
url: 'http://${localserver}/shutdown'
|
||||
method: .get
|
||||
url: 'http://${localserver}/shutdown'
|
||||
method: .get
|
||||
cookies: {
|
||||
'skey': 'superman'
|
||||
}
|
||||
|
|
|
@ -43,8 +43,8 @@ fn main() {
|
|||
spawn exit_after_timeout(timeout)
|
||||
|
||||
mut app := &ServerApp{
|
||||
port: http_port
|
||||
timeout: timeout
|
||||
port: http_port
|
||||
timeout: timeout
|
||||
global_config: Config{
|
||||
max_ping: 50
|
||||
}
|
||||
|
|
|
@ -35,51 +35,51 @@ pub const headers_close = http.new_custom_header_from_map({
|
|||
|
||||
pub const http_302 = http.new_response(
|
||||
status: .found
|
||||
body: '302 Found'
|
||||
body: '302 Found'
|
||||
header: headers_close
|
||||
)
|
||||
|
||||
pub const http_400 = http.new_response(
|
||||
status: .bad_request
|
||||
body: '400 Bad Request'
|
||||
body: '400 Bad Request'
|
||||
header: http.new_header(
|
||||
key: .content_type
|
||||
key: .content_type
|
||||
value: 'text/plain'
|
||||
).join(headers_close)
|
||||
)
|
||||
|
||||
pub const http_404 = http.new_response(
|
||||
status: .not_found
|
||||
body: '404 Not Found'
|
||||
body: '404 Not Found'
|
||||
header: http.new_header(
|
||||
key: .content_type
|
||||
key: .content_type
|
||||
value: 'text/plain'
|
||||
).join(headers_close)
|
||||
)
|
||||
|
||||
pub const http_408 = http.new_response(
|
||||
status: .request_timeout
|
||||
body: '408 Request Timeout'
|
||||
body: '408 Request Timeout'
|
||||
header: http.new_header(
|
||||
key: .content_type
|
||||
key: .content_type
|
||||
value: 'text/plain'
|
||||
).join(headers_close)
|
||||
)
|
||||
|
||||
pub const http_413 = http.new_response(
|
||||
status: .request_entity_too_large
|
||||
body: '413 Request entity is too large'
|
||||
body: '413 Request entity is too large'
|
||||
header: http.new_header(
|
||||
key: .content_type
|
||||
key: .content_type
|
||||
value: 'text/plain'
|
||||
).join(headers_close)
|
||||
)
|
||||
|
||||
pub const http_500 = http.new_response(
|
||||
status: .internal_server_error
|
||||
body: '500 Internal Server Error'
|
||||
body: '500 Internal Server Error'
|
||||
header: http.new_header(
|
||||
key: .content_type
|
||||
key: .content_type
|
||||
value: 'text/plain'
|
||||
).join(headers_close)
|
||||
)
|
||||
|
@ -192,8 +192,8 @@ fn generate_routes[A, X](app &A) !map[string]Route {
|
|||
|
||||
mut route := Route{
|
||||
methods: http_methods
|
||||
path: route_path
|
||||
host: host
|
||||
path: route_path
|
||||
host: host
|
||||
}
|
||||
|
||||
$if A is MiddlewareApp {
|
||||
|
@ -305,9 +305,9 @@ pub fn run_at[A, X](mut global_app A, params RunParams) ! {
|
|||
flush_stdout()
|
||||
|
||||
mut pico_context := &RequestParams{
|
||||
global_app: unsafe { global_app }
|
||||
controllers: controllers_sorted
|
||||
routes: &routes
|
||||
global_app: unsafe { global_app }
|
||||
controllers: controllers_sorted
|
||||
routes: &routes
|
||||
timeout_in_seconds: params.timeout_in_seconds
|
||||
}
|
||||
|
||||
|
@ -322,12 +322,12 @@ pub fn run_at[A, X](mut global_app A, params RunParams) ! {
|
|||
pico_context.string_responses = []StringResponse{len: picoev.max_fds}
|
||||
|
||||
mut pico := picoev.new(
|
||||
port: params.port
|
||||
raw_cb: ev_callback[A, X]
|
||||
user_data: pico_context
|
||||
port: params.port
|
||||
raw_cb: ev_callback[A, X]
|
||||
user_data: pico_context
|
||||
timeout_secs: params.timeout_in_seconds
|
||||
family: params.family
|
||||
host: params.host
|
||||
family: params.family
|
||||
host: params.host
|
||||
)!
|
||||
|
||||
$if A is BeforeAcceptApp {
|
||||
|
@ -379,8 +379,8 @@ fn ev_callback[A, X](mut pv picoev.Picoev, fd int, events int) {
|
|||
|
||||
fn handle_timeout(mut pv picoev.Picoev, mut params RequestParams, fd int) {
|
||||
mut conn := &net.TcpConn{
|
||||
sock: net.tcp_socket_from_handle_raw(fd)
|
||||
handle: fd
|
||||
sock: net.tcp_socket_from_handle_raw(fd)
|
||||
handle: fd
|
||||
is_blocking: false
|
||||
}
|
||||
|
||||
|
@ -409,8 +409,8 @@ fn handle_write_file(mut pv picoev.Picoev, mut params RequestParams, fd int) {
|
|||
}
|
||||
|
||||
mut conn := &net.TcpConn{
|
||||
sock: net.tcp_socket_from_handle_raw(fd)
|
||||
handle: fd
|
||||
sock: net.tcp_socket_from_handle_raw(fd)
|
||||
handle: fd
|
||||
is_blocking: false
|
||||
}
|
||||
|
||||
|
@ -445,8 +445,8 @@ fn handle_write_string(mut pv picoev.Picoev, mut params RequestParams, fd int) {
|
|||
}
|
||||
|
||||
mut conn := &net.TcpConn{
|
||||
sock: net.tcp_socket_from_handle_raw(fd)
|
||||
handle: fd
|
||||
sock: net.tcp_socket_from_handle_raw(fd)
|
||||
handle: fd
|
||||
is_blocking: false
|
||||
}
|
||||
|
||||
|
@ -475,8 +475,8 @@ fn handle_write_string(mut pv picoev.Picoev, mut params RequestParams, fd int) {
|
|||
@[direct_array_access; manualfree]
|
||||
fn handle_read[A, X](mut pv picoev.Picoev, mut params RequestParams, fd int) {
|
||||
mut conn := &net.TcpConn{
|
||||
sock: net.tcp_socket_from_handle_raw(fd)
|
||||
handle: fd
|
||||
sock: net.tcp_socket_from_handle_raw(fd)
|
||||
handle: fd
|
||||
is_blocking: false
|
||||
}
|
||||
|
||||
|
@ -553,9 +553,9 @@ fn handle_read[A, X](mut pv picoev.Picoev, mut params RequestParams, fd int) {
|
|||
if (n == 0 && params.idx[fd] != 0) || params.idx[fd] + n > content_length.int() {
|
||||
fast_send_resp(mut conn, http.new_response(
|
||||
status: .bad_request
|
||||
body: 'Mismatch of body length and Content-Length header'
|
||||
body: 'Mismatch of body length and Content-Length header'
|
||||
header: http.new_header(
|
||||
key: .content_type
|
||||
key: .content_type
|
||||
value: 'text/plain'
|
||||
).join(vweb.headers_close)
|
||||
)) or {}
|
||||
|
@ -700,12 +700,12 @@ fn handle_request[A, X](mut conn net.TcpConn, req http.Request, params &RequestP
|
|||
|
||||
// Create Context with request data
|
||||
mut ctx := &Context{
|
||||
req: req
|
||||
req: req
|
||||
page_gen_start: page_gen_start
|
||||
conn: conn
|
||||
query: query
|
||||
form: form
|
||||
files: files
|
||||
conn: conn
|
||||
query: query
|
||||
form: form
|
||||
files: files
|
||||
}
|
||||
|
||||
if connection_header := req.header.get(.connection) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue