0

我是 kotlin 新手,需要 javalin 将 api 的内容返回给客户端如果我现在运行它,它会返回此 响应

fun main(args: Array<String>) {
val app = Javalin.create().start(7000)
app.get("/:id") { ctx->

    var range = ctx.header("Range")
    var token = "ya29.a0AfH6SMAkpdl2aUJzuTYp698XJ8qYjLA54Dt72locrNB6DLNmvzI5Hf6qLHRBdpHfEx0vHdjYfkNXdWHFHHCPUg9S8cOgm7v3-ddit_oK3DvR_2kxgSFlmymptd_g9BZ13z5Fblzmexv2DX6UltBhT5TQtsqf"
    var headers=mapOf("Authorization" to "Bearer $token")
    if (range != null)
        headers = mapOf("Authorization" to "Bearer $token", "Range" to range)

    var r = get("https://www.googleapis.com/drive/v3/files/" + ctx.pathParam("id") + "?alt=media", headers, stream = true)

    ctx.header("Content-Type", r.headers.get("Content-Type") + "")
    ctx.header("Content-Length", r.headers.get("Content-Length") + "")
    ctx.header("Cache-Control", r.headers.get("Cache-Control") + "")
    ctx.header("Content-Range", r.headers.get("Content-Range") + "")

    while(r.contentIterator(1240).hasNext()) {
        ctx.result(r.contentIterator(1240).next())
    }

}
}
4

0 回答 0