GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — caddy-docker-proxy/push.go at master · lucaslorentz/caddy-docker-proxy

Expand file tree

/

push.go

Copy path
More file actions
More file actions

Latest commit

 

History

History
History
55 lines (46 loc) · 1.62 KB
/

push.go

Copy path

File metadata and controls

55 lines (46 loc) · 1.62 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
package caddydockerproxy
import (
"bytes"
"fmt"
"io"
"net/http"
"github.com/caddyserver/caddy/v2"
)
// pushLocal loads the config into the in-process Caddy via caddy.Load, the same
// function the admin /load handler calls. The loader runs in the same process
// as the local Caddy, so this avoids looping back through the admin API over
// HTTP - dropping the dependency on the local admin endpoint being reachable, or
// even enabled. forceReload is false so an unchanged config is a no-op, matching
// the admin /load default. The recover keeps parity with the HTTP path: the
// admin endpoint's net/http handler recovers panics during provisioning, so a
// poison config must fail the reload here instead of crashing the process.
func pushLocal(postBody []byte) (err error) {
defer func() {
if r := recover(); r != nil {
err = fmt.Errorf("panic loading config locally: %v", r)
}
}()
return caddy.Load(postBody, false)
}
// pushRemoteAdmin POSTs the config to a controlled server's admin API.
func pushRemoteAdmin(server string, postBody []byte) error {
url := "http://" + server + ":2019/load"
req, err := http.NewRequest("POST", url, bytes.NewBuffer(postBody))
if err != nil {
return fmt.Errorf("failed to create request: %w", err)
}
req.Header.Set("Content-Type", "application/json")
resp, err := http.DefaultClient.Do(req)
if err != nil {
return err
}
defer resp.Body.Close()
bodyBytes, err := io.ReadAll(resp.Body)
if err != nil {
return fmt.Errorf("failed to read response: %w", err)
}
if resp.StatusCode != 200 {
return fmt.Errorf("unexpected status %d: %s", resp.StatusCode, bodyBytes)
}
return nil
}
You are visitor 01402520 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.