V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
海外远程工作指南
最全面的海外远程工作指南,帮你看到更多的可能性、少走弯路,最后找到一份如意的远程工作
Promoted by hlwjia
estk
V2EX  ›  Serverless

Cloudflare Workers 返回 request method、headers、body,用于开发自测请求信息

  •  
  •   estk · 2022-07-03 16:42:00 +08:00 · 2556 次点击
    这是一个创建于 1124 天前的主题,其中的信息可能已经有所发展或是发生改变。
    addEventListener("fetch", event => {
      event.respondWith(handleRequest(event.request))
    })
    
    async function handleRequest(request) {
      let req = '<table>\n'
      req += `<tr>\n  <td>method</td>\n  <td>${request.method}</td>\n</tr>\n`
      request.headers.forEach((value, key)=>{
        req += `<tr>\n  <td>${key}</td>\n  <td>${value}</td>\n</tr>\n`
      })
      req += `<tr>\n  <td>body</td>\n  <td>${await request.text()}</td>\n</tr>\n`
      req += '</table>'
      return new Response(req, {
        headers: {
          'content-type': 'text/html'
        }
      })
    }
    

    patrickyoung
        1
    patrickyoung  
       2022-07-03 20:19:13 +08:00 via iPhone
    https://echo.paw.cloud/
    关于   ·   帮助文档   ·   自助推广系统   ·   博客   ·   API   ·   FAQ   ·   实用小工具   ·   4566 人在线   最高记录 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 21ms · UTC 09:53 · PVG 17:53 · LAX 02:53 · JFK 05:53
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.