Skip to content

Commit fffc6fc

Browse files
authored
Merge branch 'main' into dependabot/npm_and_yarn/examples/mail/nodemailer-8.0.4
2 parents 5d64bf1 + 9ce187b commit fffc6fc

96 files changed

Lines changed: 4139 additions & 1026 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,5 @@ node_modules
2525
server/api/dashboard.go
2626
coverage.txt
2727
versioninfo.json
28+
.DS_Store
29+
Icon

.idea/workspace.xml

Lines changed: 644 additions & 640 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

api/handler.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import (
2222
type Handler interface {
2323
http.Handler
2424
RegisterHealthHandler(path string, h http.Handler)
25+
RegisterMcpHandler(path string, h http.Handler)
2526
}
2627

2728
type handler struct {
@@ -33,6 +34,8 @@ type handler struct {
3334
index string
3435
healthPath string
3536
healthHandler http.Handler
37+
mcpPath string
38+
mcpHandler http.Handler
3639
}
3740

3841
type info struct {
@@ -111,6 +114,11 @@ func (h *handler) RegisterHealthHandler(path string, handler http.Handler) {
111114
h.healthHandler = handler
112115
}
113116

117+
func (h *handler) RegisterMcpHandler(path string, handler http.Handler) {
118+
h.mcpPath = path
119+
h.mcpHandler = handler
120+
}
121+
114122
func (h *handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
115123
if r.Method != "GET" && r.Method != "POST" {
116124
http.Error(w, fmt.Sprintf("method %v is not allowed", r.Method), http.StatusMethodNotAllowed)
@@ -154,6 +162,8 @@ func (h *handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
154162
h.getSearchResults(w, r)
155163
case strings.HasPrefix(p, h.healthPath) && h.healthHandler != nil:
156164
h.healthHandler.ServeHTTP(w, r)
165+
case strings.HasPrefix(p, h.mcpPath) && h.mcpHandler != nil:
166+
h.mcpHandler.ServeHTTP(w, r)
157167
case h.fileServer != nil:
158168
if r.Method != "GET" {
159169
http.Error(w, fmt.Sprintf("method %v is not allowed", r.Method), http.StatusMethodNotAllowed)

api/handler_config.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,17 @@ func (h *handler) getConfigData(w http.ResponseWriter, r *http.Request, key stri
7979
ext := filepath.Ext(path)
8080
mt := mime.TypeByExtension(filepath.Ext(ext))
8181
if mt == "" {
82-
mt = "text/plain"
82+
if ext == "" {
83+
values, err := mime.ExtensionsByType(c.Info.Kernel().ContentType)
84+
if err == nil && len(values) > 0 {
85+
ext = values[0]
86+
path += ext
87+
mt = mime.TypeByExtension(filepath.Ext(ext))
88+
}
89+
}
90+
if mt == "" {
91+
mt = "text/plain"
92+
}
8393
}
8494
w.Header().Set("Last-Modified", c.Info.Time.UTC().Format(http.TimeFormat))
8595
w.Header().Set("Content-Type", mt)

api/handler_config_test.go

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,7 @@ func TestHandler_Config(t *testing.T) {
149149
requestUrl: "http://foo.api/api/configs/foo/data",
150150
test: []try.ResponseCondition{
151151
try.HasStatusCode(http.StatusOK),
152+
try.HasHeader("Content-Disposition", "inline; filename=\"foo.yaml\""),
152153
try.HasHeader("Last-Modified", "Wed, 27 Dec 2023 13:01:30 GMT"),
153154
try.HasHeaderXor("Content-Type", "text/plain", "application/yaml"),
154155
try.HasHeader("Cache-Control", "no-cache"),
@@ -173,6 +174,34 @@ func TestHandler_Config(t *testing.T) {
173174
requestUrl: "http://foo.api/api/configs/foo/data",
174175
test: []try.ResponseCondition{
175176
try.HasStatusCode(http.StatusOK),
177+
try.HasHeader("Content-Disposition", "inline; filename=\"foo.json\""),
178+
try.HasHeader("Last-Modified", "Fri, 22 Dec 2023 13:01:30 GMT"),
179+
try.HasHeader("Content-Type", "application/json"),
180+
try.HasHeader("Etag", etag),
181+
try.HasHeader("Cache-Control", "no-cache"),
182+
try.HasBody(`{"foo": "bar"}`),
183+
},
184+
},
185+
{
186+
name: "config data: no extension but ContentType in Info is set",
187+
app: func() *runtime.App {
188+
189+
return &runtime.App{Configs: map[string]*dynamic.Config{
190+
"foo": {
191+
Info: dynamic.ConfigInfo{
192+
Url: mustUrl("https://foo.bar/foo"),
193+
Time: mustTime("2023-12-22T13:01:30+00:00"),
194+
Checksum: checksum,
195+
ContentType: "application/json",
196+
},
197+
Raw: data,
198+
},
199+
}}
200+
},
201+
requestUrl: "http://foo.api/api/configs/foo/data",
202+
test: []try.ResponseCondition{
203+
try.HasStatusCode(http.StatusOK),
204+
try.HasHeader("Content-Disposition", "inline; filename=\"foo.json\""),
176205
try.HasHeader("Last-Modified", "Fri, 22 Dec 2023 13:01:30 GMT"),
177206
try.HasHeader("Content-Type", "application/json"),
178207
try.HasHeader("Etag", etag),

cmd/mokapi/main_test.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,11 @@ health:
8989
path: /health
9090
port: 8080
9191
log: false
92+
mcp:
93+
server:
94+
enabled: false
95+
path: /mcp
96+
port: 8080
9297
rootCaCert: ""
9398
rootCaKey: ""
9499
configs: []

config/dynamic/config_info.go

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,13 @@ import (
1212
)
1313

1414
type ConfigInfo struct {
15-
Provider string
16-
Url *url.URL
17-
Checksum []byte
18-
Time time.Time
19-
inner *ConfigInfo
20-
Tags []string
15+
Provider string
16+
Url *url.URL
17+
Checksum []byte
18+
Time time.Time
19+
inner *ConfigInfo
20+
Tags []string
21+
ContentType string
2122
}
2223

2324
func (ci *ConfigInfo) Path() string {

config/dynamic/parse.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,10 +76,12 @@ func parse(c *Config) (interface{}, error) {
7676
var v interface{}
7777
v, err = parseJson(b, result)
7878
if err == nil {
79+
c.Info.ContentType = "application/json"
7980
return v, nil
8081
}
8182
v, err = parseYaml(b, result)
8283
if v != nil && err == nil {
84+
c.Info.ContentType = "application/yaml"
8385
return v, nil
8486
}
8587
err = nil

config/dynamic/parse_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ func TestParse(t *testing.T) {
107107
err := dynamic.Parse(c, &dynamictest.Reader{})
108108
require.NoError(t, err)
109109
require.Equal(t, "foo", c.Data.(*data).User)
110+
require.Equal(t, "application/json", c.Info.ContentType)
110111
},
111112
},
112113
{
@@ -161,6 +162,7 @@ func TestParse(t *testing.T) {
161162
err := dynamic.Parse(c, &dynamictest.Reader{})
162163
require.NoError(t, err)
163164
require.Equal(t, "foo", c.Data.(*data).User)
165+
require.Equal(t, "application/yaml", c.Info.ContentType)
164166
},
165167
},
166168
{

config/dynamic/provider/http/http.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,10 @@ func (p *Provider) readUrl(u *url.URL) (c *dynamic.Config, changed bool, err err
198198
Raw: b,
199199
}
200200

201+
if ct := res.Header.Get("Content-Type"); ct != "" {
202+
c.Info.ContentType = ct
203+
}
204+
201205
return
202206
}
203207

0 commit comments

Comments
 (0)