Skip to content

Commit 381fe43

Browse files
committed
refactor: rename ResponseBodyMode to BodyProcessingMode, values to Full/Chunks/Skip
Signed-off-by: Noy Itzikowitz <nitzikow@redhat.com>
1 parent c1e1ce9 commit 381fe43

3 files changed

Lines changed: 42 additions & 42 deletions

File tree

pkg/config/loader/configloader.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -310,22 +310,22 @@ func buildPostProcessors(rawConfig *configapi.PluginRefList, handle plugin.Handl
310310
}
311311

312312
// computeResponseBuffering pre-computes NeedsResponseBuffering for each profile based on the
313-
// ResponseBodyMode declared by each response plugin. If any response plugin returns BodyFull
313+
// BodyProcessingMode declared by each response plugin. If any response plugin returns Full
314314
// or doesn't implement ResponseBodyRequirement, the profile needs buffering.
315315
func computeResponseBuffering(profiles map[string]*requesthandling.Profile, logger logr.Logger) {
316316
for name, profile := range profiles {
317317
needsBuffering := false
318318
var bufferingPlugins []string
319319

320320
for _, rp := range profile.ResponsePlugins {
321-
mode := requesthandling.BodyFull
321+
mode := requesthandling.Full
322322
if req, ok := rp.(requesthandling.ResponseBodyRequirement); ok {
323-
mode = req.ResponseBodyMode()
323+
mode = req.BodyProcessingMode()
324324
} else {
325-
logger.Info("Response plugin does not declare ResponseBodyRequirement, defaulting to BodyFull",
325+
logger.Info("Response plugin does not declare ResponseBodyRequirement, defaulting to Full",
326326
"profile", name, "plugin", rp.TypedName())
327327
}
328-
if mode == requesthandling.BodyFull {
328+
if mode == requesthandling.Full {
329329
needsBuffering = true
330330
bufferingPlugins = append(bufferingPlugins, rp.TypedName().Name)
331331
}

pkg/config/loader/response_buffering_test.go

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ import (
2929

3030
type fakeResponsePlugin struct {
3131
name string
32-
mode *requesthandling.ResponseBodyMode
32+
mode *requesthandling.BodyProcessingMode
3333
}
3434

3535
func (p *fakeResponsePlugin) TypedName() plugin.TypedName {
@@ -40,11 +40,11 @@ func (p *fakeResponsePlugin) ProcessResponse(_ context.Context, _ *plugin.CycleS
4040
return nil
4141
}
4242

43-
func (p *fakeResponsePlugin) ResponseBodyMode() requesthandling.ResponseBodyMode {
43+
func (p *fakeResponsePlugin) BodyProcessingMode() requesthandling.BodyProcessingMode {
4444
if p.mode != nil {
4545
return *p.mode
4646
}
47-
return requesthandling.BodyFull
47+
return requesthandling.Full
4848
}
4949

5050
var (
@@ -66,7 +66,7 @@ func (p *legacyResponsePlugin) ProcessResponse(_ context.Context, _ *plugin.Cycl
6666

6767
var _ requesthandling.ResponseProcessor = &legacyResponsePlugin{}
6868

69-
func modePtr(m requesthandling.ResponseBodyMode) *requesthandling.ResponseBodyMode { return &m }
69+
func modePtr(m requesthandling.BodyProcessingMode) *requesthandling.BodyProcessingMode { return &m }
7070

7171
func TestComputeResponseBuffering(t *testing.T) {
7272
logger := log.FromContext(logutil.NewTestLoggerIntoContext(context.Background()))
@@ -82,48 +82,48 @@ func TestComputeResponseBuffering(t *testing.T) {
8282
wantBuffering: false,
8383
},
8484
{
85-
name: "all BodyNotNeeded",
85+
name: "all Skip",
8686
plugins: []requesthandling.ResponseProcessor{
87-
&fakeResponsePlugin{name: "a", mode: modePtr(requesthandling.BodyNotNeeded)},
88-
&fakeResponsePlugin{name: "b", mode: modePtr(requesthandling.BodyNotNeeded)},
87+
&fakeResponsePlugin{name: "a", mode: modePtr(requesthandling.Skip)},
88+
&fakeResponsePlugin{name: "b", mode: modePtr(requesthandling.Skip)},
8989
},
9090
wantBuffering: false,
9191
},
9292
{
93-
name: "all BodyChunked",
93+
name: "all Chunks",
9494
plugins: []requesthandling.ResponseProcessor{
95-
&fakeResponsePlugin{name: "a", mode: modePtr(requesthandling.BodyChunked)},
95+
&fakeResponsePlugin{name: "a", mode: modePtr(requesthandling.Chunks)},
9696
},
9797
wantBuffering: false,
9898
},
9999
{
100-
name: "one BodyFull forces buffering",
100+
name: "one Full forces buffering",
101101
plugins: []requesthandling.ResponseProcessor{
102-
&fakeResponsePlugin{name: "a", mode: modePtr(requesthandling.BodyNotNeeded)},
103-
&fakeResponsePlugin{name: "b", mode: modePtr(requesthandling.BodyFull)},
102+
&fakeResponsePlugin{name: "a", mode: modePtr(requesthandling.Skip)},
103+
&fakeResponsePlugin{name: "b", mode: modePtr(requesthandling.Full)},
104104
},
105105
wantBuffering: true,
106106
},
107107
{
108-
name: "legacy plugin without ResponseBodyRequirement defaults to BodyFull",
108+
name: "legacy plugin without ResponseBodyRequirement defaults to Full",
109109
plugins: []requesthandling.ResponseProcessor{
110110
&legacyResponsePlugin{name: "old-plugin"},
111111
},
112112
wantBuffering: true,
113113
},
114114
{
115-
name: "mixed: BodyChunked + legacy forces buffering",
115+
name: "mixed: Chunks + legacy forces buffering",
116116
plugins: []requesthandling.ResponseProcessor{
117-
&fakeResponsePlugin{name: "a", mode: modePtr(requesthandling.BodyChunked)},
117+
&fakeResponsePlugin{name: "a", mode: modePtr(requesthandling.Chunks)},
118118
&legacyResponsePlugin{name: "legacy"},
119119
},
120120
wantBuffering: true,
121121
},
122122
{
123-
name: "mixed: BodyNotNeeded + BodyChunked — no buffering",
123+
name: "mixed: Skip + Chunks — no buffering",
124124
plugins: []requesthandling.ResponseProcessor{
125-
&fakeResponsePlugin{name: "a", mode: modePtr(requesthandling.BodyNotNeeded)},
126-
&fakeResponsePlugin{name: "b", mode: modePtr(requesthandling.BodyChunked)},
125+
&fakeResponsePlugin{name: "a", mode: modePtr(requesthandling.Skip)},
126+
&fakeResponsePlugin{name: "b", mode: modePtr(requesthandling.Chunks)},
127127
},
128128
wantBuffering: false,
129129
},
@@ -150,12 +150,12 @@ func TestComputeResponseBuffering_MultipleProfiles(t *testing.T) {
150150
profiles := map[string]*requesthandling.Profile{
151151
"streaming": {
152152
ResponsePlugins: []requesthandling.ResponseProcessor{
153-
&fakeResponsePlugin{name: "headers-only", mode: modePtr(requesthandling.BodyNotNeeded)},
153+
&fakeResponsePlugin{name: "headers-only", mode: modePtr(requesthandling.Skip)},
154154
},
155155
},
156156
"full-body": {
157157
ResponsePlugins: []requesthandling.ResponseProcessor{
158-
&fakeResponsePlugin{name: "translator", mode: modePtr(requesthandling.BodyFull)},
158+
&fakeResponsePlugin{name: "translator", mode: modePtr(requesthandling.Full)},
159159
},
160160
},
161161
}

pkg/framework/interface/requesthandling/plugins.go

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -57,35 +57,35 @@ type PostProcessor interface {
5757
PostProcess(ctx context.Context, cycleState *plugin.CycleState, response *InferenceResponse) error
5858
}
5959

60-
type ResponseBodyMode int
60+
type BodyProcessingMode int
6161

6262
const (
63-
// BodyNotNeeded indicates the plugin does not need the response body at all (headers-only plugin).
64-
BodyNotNeeded ResponseBodyMode = iota
65-
// BodyChunked indicates the plugin can process individual response body chunks as they stream through.
66-
// Plugins declaring BodyChunked MUST also implement ChunkProcessor (validated at startup).
67-
BodyChunked
68-
// BodyFull indicates the plugin needs the complete response body buffered in memory before processing.
63+
// Skip indicates the plugin does not need the response body at all (headers-only plugin).
64+
Skip BodyProcessingMode = iota
65+
// Chunks indicates the plugin can process individual response body chunks as they stream through.
66+
// Plugins declaring Chunks MUST also implement ChunkProcessor (validated at startup).
67+
Chunks
68+
// Full indicates the plugin needs the complete response body buffered in memory before processing.
6969
// This is the default for plugins that do not implement ResponseBodyRequirement (backward compatible).
70-
BodyFull
70+
Full
7171
)
7272

73-
func (m ResponseBodyMode) String() string {
73+
func (m BodyProcessingMode) String() string {
7474
switch m {
75-
case BodyNotNeeded:
76-
return "BodyNotNeeded"
77-
case BodyChunked:
78-
return "BodyChunked"
79-
case BodyFull:
80-
return "BodyFull"
75+
case Skip:
76+
return "Skip"
77+
case Chunks:
78+
return "Chunks"
79+
case Full:
80+
return "Full"
8181
default:
8282
return "Unknown"
8383
}
8484
}
8585

8686
// ResponseBodyRequirement allows response plugins to declare what level of access they need
87-
// to the response body. Plugins that don't implement this interface default to BodyFull
87+
// to the response body. Plugins that don't implement this interface default to Full
8888
// (backward compatible — the framework buffers the full response before calling ProcessResponse).
8989
type ResponseBodyRequirement interface {
90-
ResponseBodyMode() ResponseBodyMode
90+
BodyProcessingMode() BodyProcessingMode
9191
}

0 commit comments

Comments
 (0)