estk

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

  •  
  •   estk · Jul 3, 2022 · 6654 views
    This topic created in 1433 days ago, the information mentioned may be changed or developed.
    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  
       Jul 3, 2022 via iPhone
    https://echo.paw.cloud/
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   918 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 30ms · UTC 22:16 · PVG 06:16 · LAX 15:16 · JFK 18:16
    ♥ Do have faith in what you're doing.