首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >EO的边缘函数图像处理avoidSizeIncrease导致返回空?

EO的边缘函数图像处理avoidSizeIncrease导致返回空?

提问于 2026-08-13 15:37:43
回答 0关注 0查看 5

函数代码如下, 这里的 avoidSizeIncrease 一旦设置为 true,并且请求头包含 webp 或者 avif,就会返回空

Status

200

Headers

  • accept-ranges: bytes
  • age: 296
  • cache-control: max-age=31536000
  • connection: close
  • content-length: 0
  • content-type: application/octet-stream
  • date: Thu, 13 Aug 2026 07:34:42 GMT
  • eo-cache-status: MISS
  • eo-log-uuid: 16151242162754019088
  • last-modified: Thu, 13 Aug 2026 07:34:42 GMT
  • nel: {"success_fraction":0.1,"report_to":"eo-nel","max_age":604800}
  • report-to: {"endpoints":[{"url":"https://nel.teo-rum.com/eo-cgi/nel"}],"group":"eo-nel","max_age":604800}
  • server: edgeone-pages
  • x-nws-log-uuid: 16151242162754019088

Body

""

代码语言:js
复制
async function handleEvent(event) {
  const { request } = event;
  
  const option = {
    eo: {
      image: {
        avoidSizeIncrease: true,
      }
    }
  };

  // 获取客户端支持的图片类型
  const accept = request.headers.get('Accept');
  if (accept) {
    if (accept.includes('image/avif')) {
      option.eo.image.format = 'avif';
    } else if (accept.includes('image/webp')) {
      option.eo.image.format = 'webp';
    }
  }

 
  try {  
    return fetch(request, option);
  } catch (error) {
    // 如果处理失败,回退到原始请求
    console.error(`Image processing failed: ${error}`);
    return fetch(request);
  }
}


addEventListener('fetch', (event) => {
  event.passThroughOnException();
  event.respondWith(handleEvent(event));
});

回答

和开发者交流更多问题细节吧,去 写回答
相关文章

相似问题

相关问答用户
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档