[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\-content
\-\-hosts\-disable (ignore \(gaHost\(ga header)
\-\-security\-headers\-tls
\-\-security\-headers\-disable
@ -208,6 +210,13 @@ it is recommended to use either \fB\-\-archive\-mmap\fP or \fB\-\-archive\-inme
.UNINDENT
.UNINDENT
.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
.INDENT 0.0
.INDENT 3.5

View file

@ -45,6 +45,8 @@ kawipiko -- blazingly fast static HTTP server
--index-data-meta
--index-data-content
--hosts-disable (ignore `Host` header)
--security-headers-tls
--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;
``--hosts-disable``
Disables the virtual-hosts feature by ignoring the `Host` header.
``--security-headers-tls``
Enables adding the following TLS related headers to the response: ::

View file

@ -36,6 +36,8 @@ NAME
--index-data-meta
--index-data-content
--hosts-disable (ignore `Host` header)
--security-headers-tls
--security-headers-disable
@ -175,6 +177,9 @@ FLAGS
--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
Enables adding the following TLS related headers to the response:

View file

@ -36,6 +36,8 @@ NAME
--index-data-meta
--index-data-content
--hosts-disable (ignore `Host` header)
--security-headers-tls
--security-headers-disable
@ -175,6 +177,9 @@ FLAGS
--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
Enables adding the following TLS related headers to the response:

View file

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

View file

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