1

我想知道如何为我的 REST 调用压缩返回 JSON:

GET /orders HTTP/1.1
Accept: */*
Accept-Encoding: gzip, deflate

但是文档只谈论返回文件

let setJson it =
    it
    |>JsonUtils.toJson
    |> OK
    >=> setMimeType "application/json; charset=utf-8"

let doReq route request action =
    path route >=> setCORSHeaders >=> request (fun r -> action(r) |> setJson)

doReq "/orders" request (fun r -> queryOrders(r |> getTerm, Products.Name))
4

1 回答 1

1

我相信这是通过添加新的 MIME 类型并传递true第二个参数在 MIME 类型映射中配置的,如下所示:

let mimeTypes =
  defaultMimeTypesMap
    @@ (function | ".json" -> createMimeType "application/json" true | _ -> None)

let webConfig = { defaultConfig with mimeTypesMap = mimeTypes }

MIME 类型和压缩的配置记录在此页面上

于 2018-07-06T17:40:04.803 回答