Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Question: Would this work with hdhomerun for cache/cdn? #24

Closed
wazerstar opened this issue Mar 15, 2022 · 2 comments
Closed

Question: Would this work with hdhomerun for cache/cdn? #24

wazerstar opened this issue Mar 15, 2022 · 2 comments

Comments

@wazerstar
Copy link

wazerstar commented Mar 15, 2022

So since you use reverse_proxy with hdhomerun, would this be possible to cache incoming tuners you sent out via dowmstream to share the same data as cdn?

if so how would a caddy config file look like?

My config so far.

{
  order request_id before header
  order rate_limit before basicauth
}

(theheaders) {
	header Strict-Transport-Security "max-age=31536000; includeSubDomains; preload"
	header X-Xss-Protection "1; mode=block"
	header X-Content-Type-Options "nosniff"
	header Cache-Control "no-store, no-cache, must-revalidate, max-age=0"
	header Pragma "no-cache"
	header X-Frame-Options "SAMEORIGIN"
	header Permissions-Policy "accelerometer=(), ambient-light-sensor=(), autoplay=(self), camera=(), encrypted-media=(), fullscreen=(self), geolocation=(), gyroscope=(), magnetometer=(), microphone=(), midi=(), payment=(), picture-in-picture=(*), speaker=(), sync-xhr=(), usb=(), vr=()"
	header Access-Control-Allow-Credentials true {
		defer

		}
	header /* {
        -Server
		}
}

domain {
import theheaders
encode gzip
log {
	format single_field common_log # if getting erros this is removed later on from https://caddyserver.com/docs/caddyfile/directives/log > https://github.com/caddyserver/format-encoder

	output file C:\stuff\caddy\logs\dvr_access.log {
	roll true # Rotate logs, enabled by default
	roll_size_mb 5 # Set max size 5 MB
	roll_gzip true # Whether to compress rolled files
	roll_local_time true # Use localhost time
	roll_keep 2 # Keep at most 2 log files
	roll_keep_days 7 # Keep log files for 7 days
	}
}
rate_limit {
	distributed
	zone dynamic_example {
		key    {remote_host}
		events 2
		window 6s
	}
}
rewrite * /a{path}
	reverse_proxy ip:port ip:port ip:port ip:port {
	# load balancing
	lb_policy least_conn
	lb_try_duration 500ms
	lb_try_interval 250ms
	# passive health checking
	max_fails 2
	transport http {
					dial_timeout 3s
					keepalive_idle_conns_per_host 4
					#keepalive_idle_conns 4
					#max_conns_per_host 2
			}
}
basicauth {
    user phash
	}	
}
@darkweak
Copy link
Collaborator

Hi @wazerstar you can define the cache directive in any blocks you want to cache.

@francislavoie
Copy link
Member

As explained in https://caddy.community/t/add-userinput-in-url-in-between-url-content/15233/17, the answer is somewhere between "no" and "probably not".

The cache plugin is specifically tasked with buffering the entire response and storing it in a cache to save from having to rebuilt the response for subsequent requests.

You're talking about streams, which can't be buffered. That is fundamentally incompatible with response caching, because there's no predictable "end" to the response, since it's a continuous stream.

What you're asking would require a lot of very specific code and handling on both the client and server to deal with. It's not really something that could be done "generally" since it requires understanding of the underlying data being streamed to be done right. The proxy would need to keep a list of streams in memory and somehow "connect" the request to one of the existing streams.

So yeah, you'll have to write your own Caddy plugin if you absolutely need this (or pay someone to do so), but I don't think you'll find a existing solution at this point because your requirement is very unique and specialized.

(I think this can be closed)

@darkweak darkweak closed this as completed Apr 5, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants