swoole post 請求form-data沒有boundary報錯

最近在遷移一個項目;fpm 模式下得一個接口客戶調用沒有問題;遷移到hyperf 下就發生http 400 錯誤;看錯誤日誌 ··· [2021-11-30 07:38:40 *18.4] WARNING http_request_on_header_value: invalid multipart/form-data body fd:3 [2021-11-30 07:38:40 *18.4] NOTICE request is illegal and it has been discarded, 522 bytes unprocessed [2021-11-30 07:38:40 *18.4] NOTICE send_to_connection (ERRNO 1005): send 166 byte failed, session#3 does not exist [2021-11-30 07:38:40 *18.4] NOTICE end (ERRNO 1005): failed to close connection, session#3 does not exist ···

在通過抓包也發現客戶傳得Content-Type 只傳了一個 multipart/form-data 這樣是不符合http標準, swoole會自動丟棄這個請求 通過nginx 判斷Content-Type 重寫Content-Type 解決

在location裏配置

      set $flag 00;
      set $CT $content_type;
      if ($content_type ~* "multipart/form-data; boundary=.*"){
        set $flag 01;
      }
      if ($content_type !~* "multipart/form-data;"){
        set $flag 10;
      }
      if ($flag = 00){
        set $CT "multipart/form-data; boundary=icsoc";
      }
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章