【看Chromium源码】之HTTP

  • 本文翻译自编程🐷的这篇文章

  • 博主自己也去看了编程🐷的相关源码(通过vscode查找)

  • Chrome源码官方目录结构

  • 代码版权所有(c)2012 The Chromium Authors

  • 从本文开始,博主将会对前端有关的Chrome源码进行分析,毕竟计网原理和DOM构建之类的学习要是有代码实现就很好了。

HTTP报文格式

在这里插入图片描述

  • Chrome设置UA字段

Chrome的UA字段是这么拼的:

User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/66.0.3345.0 Safari/537.36

UA字段格式

Mozilla/5.0 ([os_info]) AppleWebKit/[webkit_major_version].[webkit_minor_version] (KHTML, like Gecko) [chrome_version] Safari/[webkit_major_version].[webkit_minor_version]

源码

(chromium/src.git-refs_tags_88.0.4322.1/content/common/user_agent.cc):这个文件就是想获取设备信息产品信息添加到UA字段中。

// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
std::string BuildUserAgentFromOSAndProduct(const std::string& os_info,
                                           const std::string& product) {
   
  // Derived from Safari's UA string.
  // This is done to expose our product name in a manner that is maximally
  // compatible with Safari, we hope!!
  std::string user_agent;
  base::StringAppendF(
      &user_agent,
      "Mozilla/5.0 (%s) AppleWebKit/%d.%d (KHTML, like Gecko) %s Safari/%d.%d",
      os_info.c_str(
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值