[server][documentation] Add support for virtual hosts.

This commit is contained in:
Ciprian Dorin Craciun 2022-08-26 14:46:40 +03:00
parent 5482499027
commit ac505b1b65
6 changed files with 133 additions and 57 deletions

View file

@ -74,6 +74,8 @@ kawipiko -- blazingly fast static HTTP server \- kawipiko-server
\-\-index\-data\-meta \-\-index\-data\-meta
\-\-index\-data\-content \-\-index\-data\-content
\-\-hosts\-disable (ignore \(gaHost\(ga header)
\-\-security\-headers\-tls \-\-security\-headers\-tls
\-\-security\-headers\-disable \-\-security\-headers\-disable
@ -208,6 +210,13 @@ it is recommended to use either \fB\-\-archive\-mmap\fP or \fB\-\-archive\-inme
.UNINDENT .UNINDENT
.UNINDENT .UNINDENT
.sp .sp
\fB\-\-hosts\-disable\fP
.INDENT 0.0
.INDENT 3.5
Disables the virtual\-hosts feature by ignoring the \fIHost\fP header.
.UNINDENT
.UNINDENT
.sp
\fB\-\-security\-headers\-tls\fP \fB\-\-security\-headers\-tls\fP
.INDENT 0.0 .INDENT 0.0
.INDENT 3.5 .INDENT 3.5

View file

@ -45,6 +45,8 @@ kawipiko -- blazingly fast static HTTP server
--index-data-meta --index-data-meta
--index-data-content --index-data-content
--hosts-disable (ignore `Host` header)
--security-headers-tls --security-headers-tls
--security-headers-disable --security-headers-disable
@ -144,6 +146,10 @@ Flags
* it is recommended to use either ``--archive-mmap`` or ``--archive-inmem``, else (especially if data is indexed) the resulting effect is that of loading everything in RAM; * it is recommended to use either ``--archive-mmap`` or ``--archive-inmem``, else (especially if data is indexed) the resulting effect is that of loading everything in RAM;
``--hosts-disable``
Disables the virtual-hosts feature by ignoring the `Host` header.
``--security-headers-tls`` ``--security-headers-tls``
Enables adding the following TLS related headers to the response: :: Enables adding the following TLS related headers to the response: ::

View file

@ -36,6 +36,8 @@ NAME
--index-data-meta --index-data-meta
--index-data-content --index-data-content
--hosts-disable (ignore `Host` header)
--security-headers-tls --security-headers-tls
--security-headers-disable --security-headers-disable
@ -175,6 +177,9 @@ FLAGS
--archive-inmem, else (especially if data is indexed) the --archive-inmem, else (especially if data is indexed) the
resulting effect is that of loading everything in RAM; resulting effect is that of loading everything in RAM;
--hosts-disable
Disables the virtual-hosts feature by ignoring the Host header.
--security-headers-tls --security-headers-tls
Enables adding the following TLS related headers to the response: Enables adding the following TLS related headers to the response:

View file

@ -36,6 +36,8 @@ NAME
--index-data-meta --index-data-meta
--index-data-content --index-data-content
--hosts-disable (ignore `Host` header)
--security-headers-tls --security-headers-tls
--security-headers-disable --security-headers-disable
@ -175,6 +177,9 @@ FLAGS
--archive-inmem, else (especially if data is indexed) the --archive-inmem, else (especially if data is indexed) the
resulting effect is that of loading everything in RAM; resulting effect is that of loading everything in RAM;
--hosts-disable
Disables the virtual-hosts feature by ignoring the Host header.
--security-headers-tls --security-headers-tls
Enables adding the following TLS related headers to the response: Enables adding the following TLS related headers to the response:

View file

@ -52,6 +52,7 @@ type server struct {
cachedReferences map[string][2]uint64 cachedReferences map[string][2]uint64
cachedDataMeta map[uint64][]byte cachedDataMeta map[uint64][]byte
cachedDataContent map[uint64][]byte cachedDataContent map[uint64][]byte
hostsDisabled bool
securityHeadersEnabled bool securityHeadersEnabled bool
securityHeadersTls bool securityHeadersTls bool
http1Disabled bool http1Disabled bool
@ -89,6 +90,7 @@ func (_server *server) ServeUnwrapped (_context *fasthttp.RequestCtx) () {
_responseHeaders := (*fasthttp.ResponseHeader) (NoEscape (unsafe.Pointer (&_response.Header))) _responseHeaders := (*fasthttp.ResponseHeader) (NoEscape (unsafe.Pointer (&_response.Header)))
_requestMethod := _requestHeaders.Method () _requestMethod := _requestHeaders.Method ()
_requestHost := _requestHeaders.Host ()
_requestUri := _requestHeaders.RequestURI () _requestUri := _requestHeaders.RequestURI ()
_requestUriString_0 := BytesToString (_requestUri) _requestUriString_0 := BytesToString (_requestUri)
_requestUriString := NoEscapeString (&_requestUriString_0) _requestUriString := NoEscapeString (&_requestUriString_0)
@ -168,6 +170,13 @@ func (_server *server) ServeUnwrapped (_context *fasthttp.RequestCtx) () {
} }
if !_referencesFound { if !_referencesFound {
for _hostIdx := 0; _hostIdx < 2; _hostIdx += 1 {
if (_hostIdx == 0) && (_server.hostsDisabled) {
continue
}
for _namespaceAndPathSuffixIndex := range _namespaceAndPathSuffixes { for _namespaceAndPathSuffixIndex := range _namespaceAndPathSuffixes {
_namespaceAndPathSuffix := _namespaceAndPathSuffixes[_namespaceAndPathSuffixIndex] _namespaceAndPathSuffix := _namespaceAndPathSuffixes[_namespaceAndPathSuffixIndex]
_namespace := _namespaceAndPathSuffix[0] _namespace := _namespaceAndPathSuffix[0]
@ -184,12 +193,20 @@ func (_server *server) ServeUnwrapped (_context *fasthttp.RequestCtx) () {
if _server.cachedReferences != nil { if _server.cachedReferences != nil {
_key := _keyBufferLarge[:0] _key := _keyBufferLarge[:0]
_key = append (_key, KeyNamespacePrefix (_namespace), ':') _key = append (_key, KeyNamespacePrefix (_namespace), ':')
if _hostIdx == 0 {
_key = append (_key, "://" ...)
_key = append (_key, _requestHost ...)
}
_key = append (_key, _path ...) _key = append (_key, _path ...)
_key = append (_key, _pathSuffix ...) _key = append (_key, _pathSuffix ...)
_referencesValues, _referencesFound = _server.cachedReferences[BytesToString (*NoEscapeBytes (&_key))] _referencesValues, _referencesFound = _server.cachedReferences[BytesToString (*NoEscapeBytes (&_key))]
} else { } else {
_key := _keyBufferLarge[:0] _key := _keyBufferLarge[:0]
_key = append (_key, KeyNamespacePrefix (_namespace), ':') _key = append (_key, KeyNamespacePrefix (_namespace), ':')
if _hostIdx == 0 {
_key = append (_key, "://" ...)
_key = append (_key, _requestHost ...)
}
_key = append (_key, _path ...) _key = append (_key, _path ...)
_key = append (_key, _pathSuffix ...) _key = append (_key, _pathSuffix ...)
if _value, _error := _server.cdbReader.GetWithCdbHash (_key); _error == nil { if _value, _error := _server.cdbReader.GetWithCdbHash (_key); _error == nil {
@ -215,6 +232,11 @@ func (_server *server) ServeUnwrapped (_context *fasthttp.RequestCtx) () {
break break
} }
} }
if _referencesFound {
break
}
}
} }
if !_referencesFound { if !_referencesFound {
@ -225,6 +247,13 @@ func (_server *server) ServeUnwrapped (_context *fasthttp.RequestCtx) () {
} }
if !_referencesFound { if !_referencesFound {
for _hostIdx := 0; _hostIdx < 2; _hostIdx += 1 {
if (_hostIdx == 0) && (_server.hostsDisabled) {
continue
}
for for
_pathLimit := bytes.LastIndexByte (_path, '/'); _pathLimit := bytes.LastIndexByte (_path, '/');
_pathLimit >= 0; _pathLimit >= 0;
@ -235,12 +264,20 @@ func (_server *server) ServeUnwrapped (_context *fasthttp.RequestCtx) () {
if _server.cachedReferences != nil { if _server.cachedReferences != nil {
_key := _keyBufferLarge[:0] _key := _keyBufferLarge[:0]
_key = append (_key, KeyNamespacePrefix (_namespace), ':') _key = append (_key, KeyNamespacePrefix (_namespace), ':')
if _hostIdx == 0 {
_key = append (_key, "://" ...)
_key = append (_key, _requestHost ...)
}
_key = append (_key, _path[: _pathLimit] ...) _key = append (_key, _path[: _pathLimit] ...)
_key = append (_key, "/*" ...) _key = append (_key, "/*" ...)
_referencesValues, _referencesFound = _server.cachedReferences[BytesToString (*NoEscapeBytes (&_key))] _referencesValues, _referencesFound = _server.cachedReferences[BytesToString (*NoEscapeBytes (&_key))]
} else { } else {
_key := _keyBufferLarge[:0] _key := _keyBufferLarge[:0]
_key = append (_key, KeyNamespacePrefix (_namespace), ':') _key = append (_key, KeyNamespacePrefix (_namespace), ':')
if _hostIdx == 0 {
_key = append (_key, "://" ...)
_key = append (_key, _requestHost ...)
}
_key = append (_key, _path[: _pathLimit] ...) _key = append (_key, _path[: _pathLimit] ...)
_key = append (_key, "/*" ...) _key = append (_key, "/*" ...)
if _value, _error := _server.cdbReader.GetWithCdbHash (_key); _error == nil { if _value, _error := _server.cdbReader.GetWithCdbHash (_key); _error == nil {
@ -261,6 +298,11 @@ func (_server *server) ServeUnwrapped (_context *fasthttp.RequestCtx) () {
break break
} }
} }
if _referencesFound {
break
}
}
} }
if !_referencesFound { if !_referencesFound {
@ -689,6 +731,7 @@ func main_0 () (error) {
var _indexPaths bool var _indexPaths bool
var _indexDataMeta bool var _indexDataMeta bool
var _indexDataContent bool var _indexDataContent bool
var _hostsDisabled bool
var _securityHeadersEnabled bool var _securityHeadersEnabled bool
var _securityHeadersTls bool var _securityHeadersTls bool
var _timeoutDisabled bool var _timeoutDisabled bool
@ -733,6 +776,7 @@ func main_0 () (error) {
_indexDataMeta_0 := _flags.Bool ("index-data-meta", false, "") _indexDataMeta_0 := _flags.Bool ("index-data-meta", false, "")
_indexDataContent_0 := _flags.Bool ("index-data-content", false, "") _indexDataContent_0 := _flags.Bool ("index-data-content", false, "")
_timeoutDisabled_0 := _flags.Bool ("timeout-disable", false, "") _timeoutDisabled_0 := _flags.Bool ("timeout-disable", false, "")
_hostsDisabled_0 := _flags.Bool ("hosts-disable", false, "")
_securityHeadersTls_0 := _flags.Bool ("security-headers-tls", false, "") _securityHeadersTls_0 := _flags.Bool ("security-headers-tls", false, "")
_securityHeadersDisabled_0 := _flags.Bool ("security-headers-disable", false, "") _securityHeadersDisabled_0 := _flags.Bool ("security-headers-disable", false, "")
_tlsPrivate_0 := _flags.String ("tls-private", "", "") _tlsPrivate_0 := _flags.String ("tls-private", "", "")
@ -771,6 +815,7 @@ func main_0 () (error) {
_indexPaths = _indexAll || *_indexPaths_0 _indexPaths = _indexAll || *_indexPaths_0
_indexDataMeta = _indexAll || *_indexDataMeta_0 _indexDataMeta = _indexAll || *_indexDataMeta_0
_indexDataContent = _indexAll || *_indexDataContent_0 _indexDataContent = _indexAll || *_indexDataContent_0
_hostsDisabled = *_hostsDisabled_0
_securityHeadersTls = *_securityHeadersTls_0 _securityHeadersTls = *_securityHeadersTls_0
_securityHeadersEnabled = ! *_securityHeadersDisabled_0 _securityHeadersEnabled = ! *_securityHeadersDisabled_0
_timeoutDisabled = *_timeoutDisabled_0 _timeoutDisabled = *_timeoutDisabled_0
@ -997,6 +1042,9 @@ func main_0 () (error) {
if _indexDataContent { if _indexDataContent {
_processArguments = append (_processArguments, "--index-data-content") _processArguments = append (_processArguments, "--index-data-content")
} }
if _hostsDisabled {
_processArguments = append (_processArguments, "--hosts-disabled")
}
if _securityHeadersTls { if _securityHeadersTls {
_processArguments = append (_processArguments, "--security-headers-tls") _processArguments = append (_processArguments, "--security-headers-tls")
} }
@ -1476,6 +1524,7 @@ func main_0 () (error) {
cachedReferences : _cachedReferences, cachedReferences : _cachedReferences,
cachedDataMeta : _cachedDataMeta, cachedDataMeta : _cachedDataMeta,
cachedDataContent : _cachedDataContent, cachedDataContent : _cachedDataContent,
hostsDisabled : _hostsDisabled,
securityHeadersTls : _securityHeadersTls, securityHeadersTls : _securityHeadersTls,
securityHeadersEnabled : _securityHeadersEnabled, securityHeadersEnabled : _securityHeadersEnabled,
http1Disabled : _http1Disabled, http1Disabled : _http1Disabled,

View file

@ -30,6 +30,8 @@
--index-data-meta --index-data-meta
--index-data-content --index-data-content
--hosts-disable (ignore `Host` header)
--security-headers-tls --security-headers-tls
--security-headers-disable --security-headers-disable