Skip to content

Commit

Permalink
v0.9.5 修复某些场景下错误设置 status_code 的问题
Browse files Browse the repository at this point in the history
  • Loading branch information
x5iu committed Aug 22, 2024
1 parent b28d8f1 commit d34d16b
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
2 changes: 1 addition & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ func init() {
var (
MoonPalace = &cobra.Command{
Use: "moonpalace",
Version: "v0.9.4",
Version: "v0.9.5",
Short: "MoonPalace is a command-line tool for debugging the Moonshot AI HTTP API",
SilenceErrors: true,
SilenceUsage: true,
Expand Down
8 changes: 4 additions & 4 deletions proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -307,10 +307,11 @@ func buildProxy(
w.Header().Add(header, value)
}
}
if !(forceStream && !requestUseStream) {
responseContentType = filterHeaderFlags(newResponse.Header.Get("Content-Type"))
if !(forceStream && !requestUseStream && responseContentType == "text/event-stream") {
w.WriteHeader(newResponse.StatusCode)
}
if contentType := filterHeaderFlags(newResponse.Header.Get("Content-Type")); contentType == "text/event-stream" {
if responseContentType == "text/event-stream" {
var detectors map[int]*RepeatDetector
if detectRepeat {
detectors = detectorsPool.Get().(map[int]*RepeatDetector)
Expand Down Expand Up @@ -473,7 +474,7 @@ func buildProxy(
return
}
}
if requestPath == "/v1/chat/completions" && contentType == "application/json" {
if requestPath == "/v1/chat/completions" && responseContentType == "application/json" {
var completion MoonshotCompletion
if err = json.Unmarshal(responseBody, &completion); err == nil && completion.ID != "" {
if moonshot == nil {
Expand Down Expand Up @@ -521,7 +522,6 @@ func buildProxy(
moonshotContextCacheID = newResponse.Header.Get("Msh-Context-Cache-Id")
responseStatus = newResponse.Status
responseStatusCode = newResponse.StatusCode
responseContentType = filterHeaderFlags(newResponse.Header.Get("Content-Type"))
if responseStatusCode != http.StatusOK {
err = &moonshotError{message: string(responseBody)}
}
Expand Down

0 comments on commit d34d16b

Please sign in to comment.