Skip to content

Commit 1e735fc

Browse files
committed
refactor: rename ResponseBodyMode to BodyProcessingMode, values to Full/Chunks/Skip
1 parent de04164 commit 1e735fc

3 files changed

Lines changed: 47 additions & 47 deletions

File tree

pkg/config/loader/configloader.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -323,22 +323,22 @@ func computeResponseBuffering(profiles map[string]*requesthandling.Profile, logg
323323
var chunkProcessors []requesthandling.ChunkProcessor
324324

325325
for _, rp := range profile.ResponsePlugins {
326-
mode := requesthandling.BodyFull
326+
mode := requesthandling.Full
327327
if req, ok := rp.(requesthandling.ResponseBodyRequirement); ok {
328-
mode = req.ResponseBodyMode()
328+
mode = req.BodyProcessingMode()
329329
} else {
330-
logger.Info("Response plugin does not declare ResponseBodyRequirement, defaulting to BodyFull",
330+
logger.Info("Response plugin does not declare ResponseBodyRequirement, defaulting to Full",
331331
"profile", name, "plugin", rp.TypedName())
332332
}
333333

334334
switch mode {
335-
case requesthandling.BodyFull:
335+
case requesthandling.Full:
336336
needsBuffering = true
337337
bufferingPlugins = append(bufferingPlugins, rp.TypedName().Name)
338-
case requesthandling.BodyChunked:
338+
case requesthandling.Chunks:
339339
cp, ok := rp.(requesthandling.ChunkProcessor)
340340
if !ok {
341-
return fmt.Errorf("plugin %q in profile %q declares BodyChunked but does not implement ChunkProcessor",
341+
return fmt.Errorf("plugin %q in profile %q declares Chunks but does not implement ChunkProcessor",
342342
rp.TypedName().Name, name)
343343
}
344344
chunkProcessors = append(chunkProcessors, cp)

pkg/config/loader/response_buffering_test.go

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ import (
3030

3131
type fakeResponsePlugin struct {
3232
name string
33-
mode *requesthandling.ResponseBodyMode
33+
mode *requesthandling.BodyProcessingMode
3434
}
3535

3636
func (p *fakeResponsePlugin) TypedName() plugin.TypedName {
@@ -41,19 +41,19 @@ func (p *fakeResponsePlugin) ProcessResponse(_ context.Context, _ *plugin.CycleS
4141
return nil
4242
}
4343

44-
func (p *fakeResponsePlugin) ResponseBodyMode() requesthandling.ResponseBodyMode {
44+
func (p *fakeResponsePlugin) BodyProcessingMode() requesthandling.BodyProcessingMode {
4545
if p.mode != nil {
4646
return *p.mode
4747
}
48-
return requesthandling.BodyFull
48+
return requesthandling.Full
4949
}
5050

5151
var (
5252
_ requesthandling.ResponseProcessor = &fakeResponsePlugin{}
5353
_ requesthandling.ResponseBodyRequirement = &fakeResponsePlugin{}
5454
)
5555

56-
// fakeChunkPlugin declares BodyChunked and implements ChunkProcessor.
56+
// fakeChunkPlugin declares Chunks and implements ChunkProcessor.
5757
type fakeChunkPlugin struct {
5858
fakeResponsePlugin
5959
}
@@ -64,7 +64,7 @@ func (p *fakeChunkPlugin) ProcessResponseChunk(_ context.Context, _ *plugin.Cycl
6464

6565
var _ requesthandling.ChunkProcessor = &fakeChunkPlugin{}
6666

67-
// badChunkedPlugin declares BodyChunked but does NOT implement ChunkProcessor.
67+
// badChunkedPlugin declares Chunks but does NOT implement ChunkProcessor.
6868
type badChunkedPlugin struct {
6969
fakeResponsePlugin
7070
}
@@ -83,12 +83,12 @@ func (p *legacyResponsePlugin) ProcessResponse(_ context.Context, _ *plugin.Cycl
8383

8484
var _ requesthandling.ResponseProcessor = &legacyResponsePlugin{}
8585

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

8888
func TestComputeResponseBuffering(t *testing.T) {
8989
logger := log.FromContext(logutil.NewTestLoggerIntoContext(context.Background()))
9090

91-
chunkedMode := modePtr(requesthandling.BodyChunked)
91+
chunkedMode := modePtr(requesthandling.Chunks)
9292

9393
tests := []struct {
9494
name string
@@ -102,38 +102,38 @@ func TestComputeResponseBuffering(t *testing.T) {
102102
wantBuffering: false,
103103
},
104104
{
105-
name: "all BodyNotNeeded",
105+
name: "all Skip",
106106
plugins: []requesthandling.ResponseProcessor{
107-
&fakeResponsePlugin{name: "a", mode: modePtr(requesthandling.BodyNotNeeded)},
108-
&fakeResponsePlugin{name: "b", mode: modePtr(requesthandling.BodyNotNeeded)},
107+
&fakeResponsePlugin{name: "a", mode: modePtr(requesthandling.Skip)},
108+
&fakeResponsePlugin{name: "b", mode: modePtr(requesthandling.Skip)},
109109
},
110110
wantBuffering: false,
111111
},
112112
{
113-
name: "BodyChunked with ChunkProcessor",
113+
name: "Chunks with ChunkProcessor",
114114
plugins: []requesthandling.ResponseProcessor{
115115
&fakeChunkPlugin{fakeResponsePlugin{name: "chunker", mode: chunkedMode}},
116116
},
117117
wantBuffering: false,
118118
wantChunkCount: 1,
119119
},
120120
{
121-
name: "one BodyFull forces buffering",
121+
name: "one Full forces buffering",
122122
plugins: []requesthandling.ResponseProcessor{
123-
&fakeResponsePlugin{name: "a", mode: modePtr(requesthandling.BodyNotNeeded)},
124-
&fakeResponsePlugin{name: "b", mode: modePtr(requesthandling.BodyFull)},
123+
&fakeResponsePlugin{name: "a", mode: modePtr(requesthandling.Skip)},
124+
&fakeResponsePlugin{name: "b", mode: modePtr(requesthandling.Full)},
125125
},
126126
wantBuffering: true,
127127
},
128128
{
129-
name: "legacy plugin without ResponseBodyRequirement defaults to BodyFull",
129+
name: "legacy plugin without ResponseBodyRequirement defaults to Full",
130130
plugins: []requesthandling.ResponseProcessor{
131131
&legacyResponsePlugin{name: "old-plugin"},
132132
},
133133
wantBuffering: true,
134134
},
135135
{
136-
name: "mixed: BodyChunked + legacy forces buffering",
136+
name: "mixed: Chunks + legacy forces buffering",
137137
plugins: []requesthandling.ResponseProcessor{
138138
&fakeChunkPlugin{fakeResponsePlugin{name: "a", mode: chunkedMode}},
139139
&legacyResponsePlugin{name: "legacy"},
@@ -142,9 +142,9 @@ func TestComputeResponseBuffering(t *testing.T) {
142142
wantChunkCount: 1,
143143
},
144144
{
145-
name: "mixed: BodyNotNeeded + BodyChunked — no buffering",
145+
name: "mixed: Skip + Chunks — no buffering",
146146
plugins: []requesthandling.ResponseProcessor{
147-
&fakeResponsePlugin{name: "a", mode: modePtr(requesthandling.BodyNotNeeded)},
147+
&fakeResponsePlugin{name: "a", mode: modePtr(requesthandling.Skip)},
148148
&fakeChunkPlugin{fakeResponsePlugin{name: "b", mode: chunkedMode}},
149149
},
150150
wantBuffering: false,
@@ -172,20 +172,20 @@ func TestComputeResponseBuffering(t *testing.T) {
172172
}
173173
}
174174

175-
func TestComputeResponseBuffering_BodyChunkedWithoutChunkProcessor(t *testing.T) {
175+
func TestComputeResponseBuffering_ChunksWithoutChunkProcessor(t *testing.T) {
176176
logger := log.FromContext(logutil.NewTestLoggerIntoContext(context.Background()))
177177

178178
profiles := map[string]*requesthandling.Profile{
179179
"test": {
180180
ResponsePlugins: []requesthandling.ResponseProcessor{
181-
&badChunkedPlugin{fakeResponsePlugin{name: "bad", mode: modePtr(requesthandling.BodyChunked)}},
181+
&badChunkedPlugin{fakeResponsePlugin{name: "bad", mode: modePtr(requesthandling.Chunks)}},
182182
},
183183
},
184184
}
185185

186186
err := computeResponseBuffering(profiles, logger)
187187
if err == nil {
188-
t.Fatal("expected error for BodyChunked plugin without ChunkProcessor")
188+
t.Fatal("expected error for Chunks plugin without ChunkProcessor")
189189
}
190190
if !strings.Contains(err.Error(), "does not implement ChunkProcessor") {
191191
t.Errorf("error message should mention ChunkProcessor, got: %v", err)
@@ -195,12 +195,12 @@ func TestComputeResponseBuffering_BodyChunkedWithoutChunkProcessor(t *testing.T)
195195
func TestComputeResponseBuffering_MultipleProfiles(t *testing.T) {
196196
logger := log.FromContext(logutil.NewTestLoggerIntoContext(context.Background()))
197197

198-
chunkedMode := modePtr(requesthandling.BodyChunked)
198+
chunkedMode := modePtr(requesthandling.Chunks)
199199

200200
profiles := map[string]*requesthandling.Profile{
201201
"streaming": {
202202
ResponsePlugins: []requesthandling.ResponseProcessor{
203-
&fakeResponsePlugin{name: "headers-only", mode: modePtr(requesthandling.BodyNotNeeded)},
203+
&fakeResponsePlugin{name: "headers-only", mode: modePtr(requesthandling.Skip)},
204204
},
205205
},
206206
"chunked": {
@@ -210,7 +210,7 @@ func TestComputeResponseBuffering_MultipleProfiles(t *testing.T) {
210210
},
211211
"full-body": {
212212
ResponsePlugins: []requesthandling.ResponseProcessor{
213-
&fakeResponsePlugin{name: "translator", mode: modePtr(requesthandling.BodyFull)},
213+
&fakeResponsePlugin{name: "translator", mode: modePtr(requesthandling.Full)},
214214
},
215215
},
216216
}

pkg/framework/interface/requesthandling/plugins.go

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -57,37 +57,37 @@ 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
}
9292

9393
// ChunkProcessor allows a response plugin to process individual response body chunks without

0 commit comments

Comments
 (0)