Rename Proxy descr to HttpProxy

This commit is contained in:
Brian Picciano 2023-07-19 21:36:57 +02:00
parent b81b59fc0a
commit f7ecafbc17
8 changed files with 26 additions and 33 deletions

View File

@ -4,9 +4,9 @@ domain:
store_dir_path: /tmp/domani_dev_env/domain store_dir_path: /tmp/domani_dev_env/domain
builtins: builtins:
foo: foo:
kind: proxy kind: http_proxy
url: http://127.0.0.1:9000 url: http://127.0.0.1:9000
request_http_headers: request_headers:
- name: x-foo - name: x-foo
value: BAR value: BAR
- name: host - name: host

View File

@ -63,15 +63,12 @@ domain:
# kind: git # kind: git
# url: "https://somewhere.com/some/repo.git" # url: "https://somewhere.com/some/repo.git"
# branch_name: main # branch_name: main
# public: false
# #
# # Which protocols to serve the domain on. The given list overwrites the # # If true then the built-in will be included in the web interface's
# # default, which is to serve on all available protocols. # # domain list, but will not be configurable in the web interface
# #serve_protocols: # public: false
# #- protocol: http
# #- protocol: https
# An example built-in domain backed by a reverse-proxy to some other # An example built-in domain backed by an HTTP reverse-proxy to some other
# web-service. Requests to the backing service will automatically have # web-service. Requests to the backing service will automatically have
# X-Forwarded-For and (if HTTPS) X-Forwarded-Proto headers added to them. # X-Forwarded-For and (if HTTPS) X-Forwarded-Proto headers added to them.
# #
@ -80,23 +77,19 @@ domain:
# * dns.resolver_addr is ignored and the system-wide dns is used # * dns.resolver_addr is ignored and the system-wide dns is used
# #
#proxy.example.com: #proxy.example.com:
# kind: proxy # kind: http_proxy
# url: "http://some.other.service.com" # url: "http://some.other.service.com"
# #
# # Extra headers to add to requests being proxied # # Extra headers to add to proxied requests
# request_http_headers: # request_headers:
# - name: Host # - name: Host
# value: "yet.another.service.com" # value: "yet.another.service.com"
# - name: X-HEADER-TO-DELETE # - name: X-HEADER-TO-DELETE
# value: "" # value: ""
# #
# # If true then the built-in will be included in the web interface's
# # domain list, but will not be configurable in the web interface
# public: false # public: false
#
# # Which protocols to serve the domain on. The given list overwrites the
# # default, which is to serve on all available protocols.
# #serve_protocols:
# #- protocol: http
# #- protocol: https
service: service:

View File

@ -248,7 +248,7 @@ impl Manager for ManagerImpl {
) -> Result<util::BoxByteStream, GetFileError> { ) -> Result<util::BoxByteStream, GetFileError> {
let settings = self.domain_store.get(domain)?.settings; let settings = self.domain_store.get(domain)?.settings;
if let origin::Descr::Proxy { .. } = settings.origin_descr { if let origin::Descr::HttpProxy { .. } = settings.origin_descr {
return Err(unexpected::Error::from("origin is proxy, can't serve file").into()); return Err(unexpected::Error::from("origin is proxy, can't serve file").into());
} }

View File

@ -79,7 +79,7 @@ async fn main() {
} }
for (domain, builtin_domain) in &config.domain.builtins { for (domain, builtin_domain) in &config.domain.builtins {
if let domani::origin::Descr::Proxy { ref url, .. } = if let domani::origin::Descr::HttpProxy { ref url, .. } =
builtin_domain.settings.origin_descr builtin_domain.settings.origin_descr
{ {
if let Err(e) = domani::origin::proxy::validate_proxy_url(url) { if let Err(e) = domani::origin::proxy::validate_proxy_url(url) {

View File

@ -3,7 +3,7 @@ use serde::{Deserialize, Serialize};
use sha2::{Digest, Sha256}; use sha2::{Digest, Sha256};
#[derive(Clone, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)] #[derive(Clone, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)]
pub struct DescrProxyHttpHeader { pub struct DescrHttpProxyHeader {
pub name: String, pub name: String,
pub value: String, pub value: String,
} }
@ -15,10 +15,10 @@ pub enum Descr {
#[serde(rename = "git")] #[serde(rename = "git")]
Git { url: String, branch_name: String }, Git { url: String, branch_name: String },
#[serde(rename = "proxy")] #[serde(rename = "http_proxy")]
Proxy { HttpProxy {
url: String, url: String,
request_http_headers: Vec<DescrProxyHttpHeader>, request_headers: Vec<DescrHttpProxyHeader>,
}, },
} }
@ -38,13 +38,13 @@ impl Descr {
h_update(url); h_update(url);
h_update(branch_name); h_update(branch_name);
} }
Descr::Proxy { Descr::HttpProxy {
url, url,
request_http_headers, request_headers,
} => { } => {
h_update("proxy"); h_update("proxy");
h_update(url); h_update(url);
for h in request_http_headers { for h in request_headers {
h_update("header"); h_update("header");
h_update(&h.name); h_update(&h.name);
h_update(&h.value); h_update(&h.value);

View File

@ -30,17 +30,17 @@ pub async fn serve_http_request(
mut req: hyper::Request<hyper::Body>, mut req: hyper::Request<hyper::Body>,
req_is_https: bool, req_is_https: bool,
) -> unexpected::Result<hyper::Response<hyper::Body>> { ) -> unexpected::Result<hyper::Response<hyper::Body>> {
let (url, request_http_headers) = if let origin::Descr::Proxy { let (url, request_headers) = if let origin::Descr::HttpProxy {
ref url, ref url,
ref request_http_headers, ref request_headers,
} = settings.origin_descr } = settings.origin_descr
{ {
(url, request_http_headers) (url, request_headers)
} else { } else {
panic!("non-proxy domain settings passed in: {settings:?}") panic!("non-proxy domain settings passed in: {settings:?}")
}; };
for header in request_http_headers { for header in request_headers {
let name: HeaderName = header let name: HeaderName = header
.name .name
.as_str() .as_str()

View File

@ -178,7 +178,7 @@ impl<'svc> Service {
}; };
// if the domain is backed by a proxy then that is handled specially. // if the domain is backed by a proxy then that is handled specially.
if let origin::Descr::Proxy { .. } = settings.origin_descr { if let origin::Descr::HttpProxy { .. } = settings.origin_descr {
return origin::proxy::serve_http_request(&settings, client_ip, req, req_is_https) return origin::proxy::serve_http_request(&settings, client_ip, req, req_is_https)
.await .await
.unwrap_or_else(|e| { .unwrap_or_else(|e| {

View File

@ -56,7 +56,7 @@ impl TryFrom<domain::Settings> for FlatDomainSettings {
res.domain_setting_origin_descr_git_url = Some(url); res.domain_setting_origin_descr_git_url = Some(url);
res.domain_setting_origin_descr_git_branch_name = Some(branch_name); res.domain_setting_origin_descr_git_branch_name = Some(branch_name);
} }
origin::Descr::Proxy { .. } => { origin::Descr::HttpProxy { .. } => {
return Err(unexpected::Error::from( return Err(unexpected::Error::from(
"proxy origins not supported for forms", "proxy origins not supported for forms",
)); ));