Skip to content

Commit 7f3997a

Browse files
Reject 1xx statuses in validateReply; add tests. (#65)
Co-authored-by: opencode-agent[bot] <opencode-agent[bot]@users.noreply.github.com> Co-authored-by: danmoz <danmoz@users.noreply.github.com>
1 parent 3776586 commit 7f3997a

2 files changed

Lines changed: 11 additions & 1 deletion

File tree

‎req_resp.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ func validateReply(reply *Reply) error {
9595
if reply.Meta == nil {
9696
return fmt.Errorf("response is missing metadata")
9797
}
98-
if reply.Meta.Status != 0 && (reply.Meta.Status < 100 || reply.Meta.Status > 599) {
98+
if reply.Meta.Status != 0 && (reply.Meta.Status < 200 || reply.Meta.Status > 599) {
9999
return fmt.Errorf("response has invalid status %d", reply.Meta.Status)
100100
}
101101
if reply.BodyEncoding != "" && reply.BodyEncoding != "base64" {

‎req_resp_test.go‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"context"
55
"encoding/base64"
66
"encoding/json"
7+
"fmt"
78
"io"
89
"net"
910
"net/http"
@@ -290,6 +291,15 @@ func TestValidateReplyRejectsInvalidHTTPJSONResponse(t *testing.T) {
290291
}
291292
}
292293

294+
func TestValidateReplyRejectsInformationalStatus(t *testing.T) {
295+
for _, status := range []int{100, 103, 199} {
296+
reply := &Reply{Type: "HTTPJSON-REP", Meta: &ReplyMeta{Status: status}}
297+
if err := validateReply(reply); err == nil || !strings.Contains(err.Error(), fmt.Sprintf("invalid status %d", status)) {
298+
t.Fatalf("validateReply() error = %v, want invalid status error", err)
299+
}
300+
}
301+
}
302+
293303
func TestValidateReplyRejectsUnknownBodyEncoding(t *testing.T) {
294304
reply := &Reply{Meta: &ReplyMeta{}, BodyEncoding: "base64url"}
295305
if err := validateReply(reply); err == nil || !strings.Contains(err.Error(), "unsupported body encoding") {

0 commit comments

Comments
 (0)