Code Monkey home page Code Monkey logo

replace-response's Introduction

Caddy replace_response handler module

This Caddy module performs substring and regular expression replacements on response bodies, hence the name replace_response.

By default, this module operates in "buffer" mode. This is not very memory-efficient, but it guarantees we can always set the correct Content-Length header because we can buffer the output to know the resulting length before writing the response. If you need higher efficiency, you can enable "streaming" mode. When performing replacements on a stream, the Content-Length header may be removed because it is not always possible to know the correct value, since the results are streamed directly to the client and headers must be written before the body.

Note: This handler cannot perform replacements on compressed content. If your response comes from a proxied backend that supports compression, you will either have to decompress it in a response handler chain before this handler runs, or disable from the backend. One easy way to ask the backend to not compress the response is to set the Accept-Encoding header to identity, for example: header_up Accept-Encoding identity (in your Caddyfile, in the reverse_proxy block).

This module supports the use of placeholders in the search and replace arguments (but not regexes).

Module name: http.handlers.replace_response

JSON examples

Substring substitution:

{
	"handler": "replace_response",
	"replacements": [
		{
			"search": "Foo",
			"replace": "Bar"
		}
	]
}

Regular expression replacement:

{
	"handler": "replace_response",
	"replacements": [
		{
			"search_regexp": "\\s+foo(bar|baz)\\s+",
			"replace": " foo $1 "
		}
	]
}

Same, but with streaming mode (we just set "stream": true in the handler):

{
	"handler": "replace_response",
	"replacements": [
		{
			"search_regexp": "\\s+foo(bar|baz)\\s+",
			"replace": " foo $1 "
		}
	],
	"stream": true
}

Caddyfile

This module has Caddyfile support. It registers the replace directive. Make sure to order the handler directive in the correct place in the middleware chain; usually this works well:

{
	order replace after encode
}

Syntax:

replace [stream | [re] <search> <replace>] {
	stream
	[re] <search> <replace>
}
  • re indicates a regular expression instead of substring.
  • stream enables streaming mode.

Simple substring substitution:

replace Foo Bar

Regex replacement:

replace re "\s+foo(bar|baz)\s+" " foo $1 "

Streaming mode:

replace stream {
	Foo Bar
}

Multiple replacements:

replace {
	Foo Bar
	re "\s+foo(bar|baz)\s+" " foo $1 "
	A B
}

Limitations:

  • Regex matches longer than 2kb will not be replaced.

  • Compressed responses (e.g. from an upstream proxy which gzipped the response body) will not be decoded before attempting to replace. To work around this, you may send the Accept-Encoding: identity request header to the upstream to tell it not to compress the response. For example:

    reverse_proxy localhost:8080 {
        header_up Accept-Encoding identity
    }
    

replace-response's People

Contributors

francislavoie avatar icholy avatar mholt avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

replace-response's Issues

placeholders not support {http.request.host}

Hi,

I have a generic domain name and would like to use the replace-response to reach the replacement of the real domain name requested by the user. But always replace by text:{http.request.host}

As in the following configuration file:

*.example.com:443 {
  replace {
    example.com {http.request.host}
  }

Is there any way to make it happen? Thanks!

Support placeholders

Currently, placeholders are not supported in the search or replacement text. It would be really nice to be able to use them.

Support for Path-Matchers

Let's say I've got an index.html and serveral static JS+CSS files that are served via Caddy's file_server directive.
Is there a way to make sure that the replace directive is only run for my index.html file, e.g. with path matchers? I didn't see any example or documentation about that in this repository.

Just for the record: these are my files

My index.html looks like this:

<meta name="BASE_URL" content="__BASE_URL__" />

And my Caddyfile looks like this:

{
    order replace after encode
}

:80 {
    root * /srv
    file_server

    route {
        try_files {path} /index.html

        header /index.html {
            Cache-Control no-cache
        }

        replace __BASE_URL__ https://example.com
    }
}

Trying to replace host with port (hostname:5555) doesn't match

Hi,
I'm trying to perform the following replace:

replace {
    host1.com:4444 host2.com:5555
}

But it won't match host1.com:4444.
if i match only host1.com, no problem the replace works. if i match only 4444, no problem. If i match them in 2 separate lines it matches correctly:

replace {
    host1.com host2.com
    4444 5555
}

But the moment i have a colon it won't match.
also tried with re "host1.com.4444" "host2.com.5555" or just re ".4444" ".5555" no match.
If it makes a difference, i used the recommended order (order replace after encode), and my reverse_proxy is setup with header_up Accept-Encoding identity, or i wouldn't get any matches.
Any ideas?

Replace with reverse proxy

Trying to make this work for a reverse proxy. It appears this module is specifically designed for the HTTP server (I am new to this project, so please excuse me if I am mistaken). To port this to run "replace" for the reverse proxy, can the transform function be moved into the reverse proxy or do you recommend a new module be created? (I am new here, so please excuse stupid questions, thanks!)

case sensitivity

More a question than an issue.
Is the replace test pattern case sensitive or insensitive ??
Ex:

replace {
  MyWord   bythisword 
}

and

replace {
  MYWORD   bythisword 
} 

returned the same response

And if it's case sensitive, how can i force the INsensitivity

Support Content-Type filtering

Hi. By default, this module make replacement in every single file. I am not sure how far true is that statement, but at least in my case it made replacement in html, css, and js.

Example:

:8081 {
    tls internal

    reverse_proxy https://caddyserver.com {
        header_up Host {upstream_hostport}
        header_up X-Forwarded-Host {host}
        header_up -Accept-Encoding

    }

    replace re "(?i)caddy" "C4DDY"

}

Not only in the webpage, but it made replacement in http://localhost:8081/resources/js/common.js as well.

My request is, let us define the type of file we want to make replacement in.
I am not sure how it affect performance and resources, but this option will be a great one to have.

Thank you!

Behaviour of ^ and $ in regular expressions

The caret (^) and dollar sign ($) in regular expressions seem to match beginning and end of the entire body and not beginning and end of a line, even though the latter might be more intuitive and useful.

It's best seen with an example. Consider this Caddyfile:

{
  order replace after encode
}

:8080 {
  respond 200 {
    body `Line 1
Line 2
Line 3
Line 4`
  }
  replace re ^[A-Za-z]+ foo
  replace re [0-9]+$ bar
}

This is what most people would probably expect the output of a request to be:

foo bar
foo bar
foo bar
foo bar

However, this is what the actual output is:

foo 1
Line 2
Line 3
Line bar

The point is that one often wants to match some pattern relative to the beginning or end of a line, and usually ^ and $ are used for this. Even if it is justified that ^ and $ mean the beginning and end of the entire string, the line-based use case is very common, and as far as I know there is no other robust way to match the beginning and end of a line without ^ and $.

So, is there any possibility to somehow redefine the behaviour of ^ and $ accordingly?

How to replace the content in websock

My caddyfile

a.com {
    import log
    reverse_proxy b.com {
        header_up Accept-Encoding identity
        header_up Host {upstream_hostport}
        header_up X-Forwarded-Host {host}
    }

    replace {
        foo bar
    }
}

It didn't work

Support compression encoding

Unless I am misinterpreting the code and set up my Caddy incorrectly, this module does not support replacing gzip/zstd/etc. compression encoded files. Since most people use Caddyserver as a reverse proxy for services, and many popular services serve gzip-encoded files, this module does not work in the majority of configurations.

Would love if this could be implemented (or even better, if I am misinterpreting the code and this is already supported).

Blank page if using regex more than once in multiple replacement

I got blank page if using regex more than once in multiple replacements.

This is my full config

{
    debug
    admin 0.0.0.0:2020
    order replace after encode
}

:8080 {
    tls internal

    reverse_proxy https://caddyserver.com {
        header_up Host {upstream_hostport}
        header_up X-Forwarded-Host {host}
        header_up -Accept-Encoding

    }

    replace {
        re "<div>" "<div >"
        re "<p>" "<p >"
    }

}

Caddy log:

2021/09/28 13:34:10.972 INFO    using provided configuration    {"config_file": "Caddyfile", "config_adapter": ""}
2021/09/28 13:34:10.974 WARN    input is not formatted with 'caddy fmt' {"adapter": "caddyfile", "file": "Caddyfile", "line": 2}
2021/09/28 13:34:10.976 INFO    admin   admin endpoint started  {"address": "tcp/0.0.0.0:2020", "enforce_origin": false, "origins": ["0.0.0.0:2020"]}
2021/09/28 13:34:10.976 WARN    admin   admin endpoint on open interface; host checking disabled        {"address": "tcp/0.0.0.0:2020"}
2021/09/28 13:34:10.982 INFO    tls.cache.maintenance   started background certificate maintenance      {"cache": "0xc000618ee0"}
2021/09/28 13:34:10.997 INFO    pki.ca.local    root certificate is already trusted by system   {"path": "storage:pki/authorities/local/root.crt"}
2021/09/28 13:34:10.997 DEBUG   http    starting server loop    {"address": "[::]:8080", "http3": false, "tls": false}
2021/09/28 13:34:10.997 INFO    autosaved config (load with --resume flag)      {"file": "/home/myuser/.config/caddy/autosave.json"}
2021/09/28 13:34:10.997 INFO    serving initial configuration
2021/09/28 13:34:10.998 INFO    tls     cleaning storage unit   {"description": "FileStorage:/home/myuser/.local/share/caddy"}
2021/09/28 13:34:10.999 INFO    tls     finished cleaning storage units
2021/09/28 13:34:22.864 DEBUG   http.handlers.reverse_proxy     upstream roundtrip      {"upstream": "caddyserver.com:443", "request": {"remote_addr": "xxx.xxx.xxx.xxx:59613", "proto": "HTTP/1.1", "method": "GET", "host": "caddyserver.com:443", "uri": "/", "headers": {"X-Forwarded-Proto": ["http"], "User-Agent": ["Mozilla/5.0 (X11; Linux x86_64; rv:92.0) Gecko/20100101 Firefox/92.0"], "Accept-Language": ["en-US,en;q=0.5"], "X-Forwarded-For": ["xxx.xxx.xxx.xxx"], "Accept": ["text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8"], "X-Forwarded-Host": ["localhost"], "Upgrade-Insecure-Requests": ["1"]}}, "headers": {"Content-Type": ["text/html; charset=utf-8"], "Server": ["Caddy"], "Vary": ["Accept-Encoding"], "Date": ["Tue, 28 Sep 2021 13:34:22 GMT"]}, "status": 200}
2021/09/28 13:34:23.000 ERROR   http.log.error  transform: short internal buffer        {"request": {"remote_addr": "xxx.xxx.xxx.xxx:59613", "proto": "HTTP/1.1", "method": "GET", "host": "localhost:8080", "uri": "/", "headers": {"User-Agent": ["Mozilla/5.0 (X11; Linux x86_64; rv:92.0) Gecko/20100101 Firefox/92.0"], "Accept": ["text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8"], "Accept-Language": ["en-US,en;q=0.5"], "Accept-Encoding": ["gzip, deflate"], "Connection": ["keep-alive"], "Upgrade-Insecure-Requests": ["1"]}}, "duration": 0.642345481}
2021/09/28 13:34:23.000 DEBUG   http.stdlib     http: superfluous response.WriteHeader call from github.com/caddyserver/caddy/v2/modules/caddyhttp.(*Server).ServeHTTP (server.go:266)

curl output

$ curl localhost:8080 -v
*   Trying ::1:8080...
* TCP_NODELAY set
* Connected to localhost (::1) port 8080 (#0)
> GET / HTTP/1.1
> Host: localhost:8080
> User-Agent: curl/7.68.0
> Accept: */*
> 
* Mark bundle as not supporting multiuse
< HTTP/1.1 200 OK
< Content-Type: text/html; charset=utf-8
< Date: Tue, 28 Sep 2021 13:40:51 GMT
< Server: Caddy
< Server: Caddy
< Vary: Accept-Encoding
< Transfer-Encoding: chunked
< 
* Connection #0 to host localhost left intact

Caddy version

$ caddy version
v2.4.5 h1:P1mRs6V2cMcagSPn+NWpD+OEYUYLIf6ecOa48cFGeUg=

If I make them in separate lines, the page loads fine

    replace re "<div>" "<div >"
    replace re "<p>" "<p >"

I am not sure if it is the same issue with #7.

Thank you.

It doesn't seem to work.

{
        debug
        order replace after encode
}

*.{$DOMAIN}, {$DOMAIN} {
        handle @gg {
                reverse_proxy * https://www.google.com {
                        header_up Accept-Encoding identity
                        header_up Host {http.reverse_proxy.upstream.hostport}
                        header_up X-Real-IP {http.request.remote.host}
                        header_up X-Forwarded-For {http.request.remote.host}
                        header_up X-Forwarded-Port {http.request.port}
                        #header_up X-Forwarded-Proto {http.request.scheme}
                        header_down Set-Cookie google.com {$DOMAIN}
                }
                replace {
                        www.google.com gg.{$DOMAIN}
                        re "(www|ssl)\.gstatic\.com" "gstatic-gg\.host\.xyz"
                }
        }
}
{"level":"error","ts":1632329198.0830786,"logger":"http.log.error","msg":"transform: short internal buffer","request":{"remote_addr":"10.0.2.100:36916","proto":"HTTP/2.0","method":"GET","host":"gg.host.xyz","uri":"/search?q=transform%3A+short+internal+buffer&ei=8VVLYciQNIuzggei44v4Aw&oq=transform%3A+short+internal+buffer&gs_lcp=Cgdnd3Mtd2l6EANKBAhBGABQzKRYWMykWGCAqlhoAHAAeACAAacDiAGnA5IBAzQtMZgBAKABAqABAcABAQ&sclient=gws-wiz&ved=0ahUKEwiIzabB_JLzAhWLmeAKHaLxAj8Q4dUDCA4&uact=5","headers":{"Referer":["https://gg.host.xyz/"],"Sec-Fetch-User":["?1"],"Cf-Connecting-Ip":["240e:381:4572:8600:e8f7:445c:a677:1074"],"Accept-Language":["zh-CN,zh;q=0.8,zh-TW;q=0.7,zh-HK;q=0.5,en-US;q=0.3,en;q=0.2"],"Cf-Ipcountry":["CN"],"X-Forwarded-For":["240e:381:4572:8600:e8f7:445c:a677:1074"],"Pragma":["no-cache"],"Cache-Control":["no-cache"],"Cdn-Loop":["cloudflare"],"Accept-Encoding":["gzip"],"Cf-Ray":["692d02ab1e120560-LAX"],"Sec-Fetch-Mode":["navigate"],"User-Agent":["Mozilla/5.0 (X11; Linux x86_64; rv:92.0) Gecko/20100101 Firefox/92.0"],"Accept":["text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8"],"Upgrade-Insecure-Requests":["1"],"Sec-Fetch-Dest":["document"],"Sec-Fetch-Site":["same-origin"],"Cookie":["1P_JAR=2021-09-22-16; NID=224=DwLXSgDTTy5ZdVh5-2qcNTc1vwsSnl12pFqgvQ9cne1b0Hpr2z7ciLMLQr2XcExrirR2EWm0LZv8bbF2RTWtGSOdJouyycqBgTZFHGd51DJOmPGsc53dXHxsITKjCWjtWtOsbDH70SBt9Ls1qdnxEQBI_XYB5YvputkEX6l7BkQ"],"X-Forwarded-Proto":["https"],"Cf-Visitor":["{\"scheme\":\"https\"}"]},"tls":{"resumed":false,"version":772,"cipher_suite":4865,"proto":"h2","proto_mutual":true,"server_name":"gg.host.xyz"}},"duration":0.575584018}

Podman's fault? Or cloudflare failure?

How to use this plugin, need help!

Hello, this is my Caddyfile:

{
        debug
        order replace after encode
}

domain.com {
#       encode gzip zstd

        reverse_proxy localhost:8080
        replace Foo Bar
}

but I got Error: adapting config using caddyfile: parsing caddyfile tokens for 'order': replace is not a registered directive, at Caddyfile:3, what should I do, thanks a lot!

go: malformed module path "caddyserver/replace-response": missing dot in first path element

Hi,

I am unable to build this module with caddy 2.6

Dockerfile :

FROM caddy:2.6-builder-alpine AS caddy_builder

RUN xcaddy build \
      --with caddyserver/replace-response

FROM caddy:2.6-alpine AS app_caddy

WORKDIR /srv/app

COPY --from=caddy_builder --link /usr/bin/caddy /usr/bin/caddy

Output of docker build . :

#0 5.052 go: added golang.org/x/exp v0.0.0-20221205204356-47842c84f3db
#0 5.052 go: added golang.org/x/mod v0.6.0
#0 5.052 go: added golang.org/x/net v0.7.0
#0 5.052 go: added golang.org/x/sys v0.5.0
#0 5.052 go: added golang.org/x/term v0.5.0
#0 5.052 go: added golang.org/x/text v0.7.0
#0 5.052 go: added golang.org/x/tools v0.2.0
#0 5.052 go: added google.golang.org/protobuf v1.28.1
#0 5.053 2023/04/06 16:05:20 [INFO] exec (timeout=0s): /usr/local/go/bin/go get -d -v caddyserver/replace-response github.com/caddyserver/caddy/[email protected] 
#0 5.104 go: malformed module path "caddyserver/replace-response": missing dot in first path element
#0 5.105 2023/04/06 16:05:20 [FATAL] exit status 1
------
Dockerfile:4
--------------------
   3 |     
   4 | >>> RUN xcaddy build \
   5 | >>>       --with caddyserver/replace-response
   6 |     
--------------------
ERROR: failed to solve: process "/bin/sh -c xcaddy build       --with caddyserver/replace-response" did not complete successfully: exit code: 1

It may not work when response of reserve_proxy is compressed

I used this module with reserve_proxy. It worked when I used curl, but It didn't replace any data when I used chrome. In some times, the module will break encoding. You will get a page with mess chars. I analysed HTTP-HEADER, and I found chrome would send Accept-Encoding but curl didn't. I guess compression will break progress of replacing. I don't know Caddy how to deal with upsteam response when response when response is compressed, but I think Caddy will leave it as it is. May it decompress before replacing

I add header_up -Accept-Endcoding to Caddyfile to make upstream to return original data, and the module work correctly.

Errors after #24

I restarted caddy with the recent changes and now this is the error I'm getting.

{"level":"info","ts":1703113414.5186145,"msg":"using provided configuration","config_file":"/config/caddy.local.json","config_adapter":""}
{"level":"info","ts":1703113414.5215893,"logger":"admin","msg":"admin endpoint started","address":"0.0.0.0:2019","enforce_origin":false,"origins":["//0.0.0.0:2019"]}
{"level":"warn","ts":1703113414.521603,"logger":"admin","msg":"admin endpoint on open interface; host checking disabled","address":"0.0.0.0:2019"}
{"level":"info","ts":1703113414.522009,"logger":"http.auto_https","msg":"server is listening only on the HTTPS port but has no TLS connection policies; adding one to enable TLS","server_name":"server0","https_port":443}
{"level":"info","ts":1703113414.5220327,"logger":"http.auto_https","msg":"enabling automatic HTTP->HTTPS redirects","server_name":"server0"}
{"level":"info","ts":1703113414.5221372,"logger":"tls.cache.maintenance","msg":"started background certificate maintenance","cache":"0x400041aa80"}
panic: interface conversion: interface {} is nil, not *caddy.Replacer

goroutine 1 [running]:
github.com/caddyserver/replace-response.(*Handler).Provision(0x400076b6e0, {{0x1a0f8e0, 0x40002df7d0}, 0x4000220de0, 0x40005d2000, {0x0, 0x0, 0x0}, {0x40003577c0, 0x3, ...}})
        github.com/caddyserver/[email protected]/handler.go:88 +0x2f8
github.com/caddyserver/caddy/v2.Context.LoadModuleByID({{0x1a0f8e0, 0x40002df7d0}, 0x4000220de0, 0x40005d2000, {0x0, 0x0, 0x0}, {0x40003577c0, 0x3, 0x4}}, ...)
        github.com/caddyserver/caddy/[email protected]/context.go:347 +0x41c
github.com/caddyserver/caddy/v2.Context.loadModuleInline({{0x1a0f8e0, 0x40002df7d0}, 0x4000220de0, 0x40005d2000, {0x0, 0x0, 0x0}, {0x40001643a0, 0x2, 0x2}}, ...)
        github.com/caddyserver/caddy/[email protected]/context.go:397 +0x100
github.com/caddyserver/caddy/v2.Context.LoadModule({{0x1a0f8e0, 0x40002df7d0}, 0x4000220de0, 0x40005d2000, {0x0, 0x0, 0x0}, {0x40001643a0, 0x2, 0x2}}, ...)
        github.com/caddyserver/caddy/[email protected]/context.go:176 +0x5c0
github.com/caddyserver/caddy/v2/modules/caddyhttp.(*Route).ProvisionHandlers(0x40007721b0, {{0x1a0f8e0, 0x40002df7d0}, 0x4000220de0, 0x40005d2000, {0x0, 0x0, 0x0}, {0x40001643a0, 0x2, ...}}, ...)
        github.com/caddyserver/caddy/[email protected]/modules/caddyhttp/routes.go:154 +0x98
github.com/caddyserver/caddy/v2/modules/caddyhttp.RouteList.ProvisionHandlers({0x4000772000, 0x4, 0x0?}, {{0x1a0f8e0, 0x40002df7d0}, 0x4000220de0, 0x40005d2000, {0x0, 0x0, 0x0}, ...}, ...)
        github.com/caddyserver/caddy/[email protected]/modules/caddyhttp/routes.go:209 +0xb8
github.com/caddyserver/caddy/v2/modules/caddyhttp.RouteList.Provision({0x4000772000, 0x4, 0x4}, {{0x1a0f8e0, 0x40002df7d0}, 0x4000220de0, 0x40005d2000, {0x0, 0x0, 0x0}, ...})
        github.com/caddyserver/caddy/[email protected]/modules/caddyhttp/routes.go:186 +0xb4
github.com/caddyserver/caddy/v2/modules/caddyhttp.(*Subroute).Provision(0x4000164360, {{0x1a0f8e0, 0x40002df7d0}, 0x4000220de0, 0x40005d2000, {0x0, 0x0, 0x0}, {0x40001643a0, 0x2, ...}})
        github.com/caddyserver/caddy/[email protected]/modules/caddyhttp/subroute.go:58 +0x90
github.com/caddyserver/caddy/v2.Context.LoadModuleByID({{0x1a0f8e0, 0x40002df7d0}, 0x4000220de0, 0x40005d2000, {0x0, 0x0, 0x0}, {0x40001643a0, 0x2, 0x2}}, ...)
        github.com/caddyserver/caddy/[email protected]/context.go:347 +0x41c
github.com/caddyserver/caddy/v2.Context.loadModuleInline({{0x1a0f8e0, 0x40002df7d0}, 0x4000220de0, 0x40005d2000, {0x0, 0x0, 0x0}, {0x40004b28b0, 0x1, 0x1}}, ...)
        github.com/caddyserver/caddy/[email protected]/context.go:397 +0x100
github.com/caddyserver/caddy/v2.Context.LoadModule({{0x1a0f8e0, 0x40002df7d0}, 0x4000220de0, 0x40005d2000, {0x0, 0x0, 0x0}, {0x40004b28b0, 0x1, 0x1}}, ...)
        github.com/caddyserver/caddy/[email protected]/context.go:176 +0x5c0
github.com/caddyserver/caddy/v2/modules/caddyhttp.(*Route).ProvisionHandlers(0x400037bb70, {{0x1a0f8e0, 0x40002df7d0}, 0x4000220de0, 0x40005d2000, {0x0, 0x0, 0x0}, {0x40004b28b0, 0x1, ...}}, ...)
        github.com/caddyserver/caddy/[email protected]/modules/caddyhttp/routes.go:154 +0x98
github.com/caddyserver/caddy/v2/modules/caddyhttp.RouteList.ProvisionHandlers({0x400037b300, 0x19, 0x4?}, {{0x1a0f8e0, 0x40002df7d0}, 0x4000220de0, 0x40005d2000, {0x0, 0x0, 0x0}, ...}, ...)
        github.com/caddyserver/caddy/[email protected]/modules/caddyhttp/routes.go:209 +0xb8
github.com/caddyserver/caddy/v2/modules/caddyhttp.(*App).Provision(0x40006f8000, {{0x1a0f8e0, 0x40002df7d0}, 0x4000220de0, 0x40005d2000, {0x0, 0x0, 0x0}, {0x40004b28b0, 0x1, ...}})
        github.com/caddyserver/caddy/[email protected]/modules/caddyhttp/app.go:287 +0xa3c
github.com/caddyserver/caddy/v2.Context.LoadModuleByID({{0x1a0f918, 0x40005d20a0}, 0x4000220de0, 0x40005d2000, {0x0, 0x0, 0x0}, {0x40004b28b0, 0x1, 0x1}}, ...)
        github.com/caddyserver/caddy/[email protected]/context.go:347 +0x41c
github.com/caddyserver/caddy/v2.Context.App({{0x1a0f918, 0x40005d20a0}, 0x4000220de0, 0x40005d2000, {0x0, 0x0, 0x0}, {0x0, 0x0, 0x0}}, ...)
        github.com/caddyserver/caddy/[email protected]/context.go:423 +0xf4
github.com/caddyserver/caddy/v2.run.func3(...)
        github.com/caddyserver/caddy/[email protected]/caddy.go:480
github.com/caddyserver/caddy/v2.run(0x40006b4000?, 0x1)
        github.com/caddyserver/caddy/[email protected]/caddy.go:485 +0x468
github.com/caddyserver/caddy/v2.unsyncedDecodeAndRun({0x4000466500, 0x2496, 0x2500}, 0x1)
        github.com/caddyserver/caddy/[email protected]/caddy.go:338 +0xe4
github.com/caddyserver/caddy/v2.changeConfig({0x1519a34, 0x4}, {0x1520983, 0x7}, {0x4000664000, 0x7058, 0x7059}, {0x0, 0x0}, 0x1)
        github.com/caddyserver/caddy/[email protected]/caddy.go:229 +0x628
github.com/caddyserver/caddy/v2.Load({0x4000664000, 0x7058, 0x7059}, 0x0?)
        github.com/caddyserver/caddy/[email protected]/caddy.go:128 +0x198
github.com/caddyserver/caddy/v2/cmd.cmdRun({0x0?})
        github.com/caddyserver/caddy/[email protected]/cmd/commandfuncs.go:231 +0x668
github.com/caddyserver/caddy/v2/cmd.init.1.func2.WrapCommandFuncForCobra.func1(0x4000432600, {0x1519a94?, 0x4?, 0x1519a64?})
        github.com/caddyserver/caddy/[email protected]/cmd/cobra.go:137 +0x34
github.com/spf13/cobra.(*Command).execute(0x4000432600, {0x400040e680, 0x2, 0x2})
        github.com/spf13/[email protected]/command.go:940 +0x66c
github.com/spf13/cobra.(*Command).ExecuteC(0x26a1f00)
        github.com/spf13/[email protected]/command.go:1068 +0x320
github.com/spf13/cobra.(*Command).Execute(...)
        github.com/spf13/[email protected]/command.go:992
github.com/caddyserver/caddy/v2/cmd.Main()
        github.com/caddyserver/caddy/[email protected]/cmd/main.go:66 +0x68
main.main()
        caddy/main.go:14 +0x1c

Stuck on caddy v1 because i use http filters in v1 ...

Hello you to let you know you removed the doc of v1 in the website it make it difficult to me to use caddy but i can't migrate i really need this, i think to find a way to go back on nginx because of that, do you have any roadmap for that feature ?

i would like to help, but the only time i try golang i disliked so much that was crazy, i can probaly paid for that one that a current too big pain ๐Ÿ˜ข
my current use :

          naas.ai {
              import basicSnip
              proxy / hub:8000 {
                  transparent
                  websocket
              }
              filter rule {
                  content_type text/html.*
                  search_pattern "</head>"
                  replacement "<script src=\"https://cdn.jsdelivr.net/npm/[email protected]/jupyter.js\"></script></head>"
              }
          }

I add code to have custom css in platform and custom js, like autofill password in iframed.

Replace with environment variables?

I'm trying to do this, but it doesn't seem to use the environment variable.

{
  "handler": "replace_response",
  "replacements": [
    {
      "search_regexp": "PORTAL_ENVIRONMENT_APIS_AUTH",
      "replace": "{env.PORTAL_ENVIRONMENT_APIS_AUTH}"
    }
  ]
},

Environment Variables - Incorrect Replacements

Hi,

I use caddy 2.6.2 with replace-response and noticed some weird replacements. I want to add a webroot/subdirectory to absolute paths which are stored in environment variables DOMAIN=mydomain.com and WEBROOT=/app.

replace https://{$DOMAIN} https://{$DOMAIN}{$WEBROOT} updated response from https://mydomain.com/script.js to https:///appmydomain.com/script.js (incorrect order within environment variable values).

After that I tried replace https://{$DOMAIN} https://before{$DOMAIN}after which results in https://beforeaftermydomain.com/script.js (environment variable values are always suffixed).

I expected https://mydomain.com/app/script.js. The hardcoded workaround replace https://mydomain.com https://mydomain.com/app works as expected.

Greets, ManOki

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.