Skip to content
Navigation Menu
Sign in
Products
Platform
GitHub
Repository hosting, code review, and collaboration
Copilot
AI coding agent for tasks, projects and automated work
Build & Ship
Actions
CI/CD and automation
Code Quality
Quality analysis, fixes, and enforcement
Codespaces
Cloud development environments
Secure
Code Security
Vulnerability detection and remediation
Secret Protection
Secret scanning and leak prevention
All Features
Developers
Learn
Documentation
Training
Certifications
Build
Build with Copilot
Customize Copilot
Integrations
Explore
Trending repos
GitHub Sponsors
Events
Changelog
Changelog
Your source for the latest features, improvements, and fixes across GitHub products, all in one place.
Businesses
By Stage
Enterprises
Team
Startups
Nonprofits
By Industry
Healthcare
Financial services
Manufacturing
Government
See all industries
Evaluate GitHub
Why GitHub
Customer Stories
Business insights
Trust Center
Add-ons
GitHub Advanced Security
Enterprise-grade code security
Copilot for business
Enterprise-grade AI features
Premium Support
Enterprise-grade 24/7 support
Resources
Learn & Connect
Documentation
Resource center
Blog
Events & webinars
Community Forum
Customer Stories
Integrations
Support
Customer support
Training
GitHub Status
Company
About
Partners
Changelog
GitHub Universe
GitHub Universe
The event for developers, by developers — talks, workshops, and what’s next for GitHub.
Pricing
Search
/
Sign in
Sign up
Appearance settings
You signed in with another tab or window.
Reload
to refresh your session.
You signed out in another tab or window.
Reload
to refresh your session.
You switched accounts on another tab or window.
Reload
to refresh your session.
Dismiss alert
{{ message }}
hawklithm
workbuddy2api
Repository navigation
Code
Issues
Pull requests
Actions
Projects
Security and quality
Insights
More
items
Files
Expand file tree
main
Breadcrumbs
workbuddy2api
/
intercept_headers.py
Copy path
Blame
More file actions
Blame
More file actions
Latest commit
History
History
History
executable file
·
47 lines (37 loc) · 1.39 KB
main
Breadcrumbs
workbuddy2api
/
intercept_headers.py
Copy path
Top
File metadata and controls
Code
Blame
executable file
·
47 lines (37 loc) · 1.39 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#!/usr/bin/env python3
"""拦截并打印实际发送到CodeBuddy的headers"""
import sys
import os
sys.path.insert(0, os.path.join(os.path.dirname(__file__), 'src'))
# Monkey patch httpx to intercept requests
import httpx
from typing import Any
original_stream = httpx.AsyncClient.stream
async def patched_stream(self, method: str, url: Any, **kwargs):
"""拦截stream请求,打印headers"""
headers = kwargs.get('headers', {})
json_body = kwargs.get('json', {})
print("\n" + "=" * 60)
print(f"拦截到请求: {method} {url}")
print("=" * 60)
print("\n发送的Headers:")
for k, v in sorted(headers.items()):
# 隐藏敏感信息
if k.lower() in ('authorization', 'x-refresh-token'):
v = f"{v[:20]}..." if len(v) > 20 else v
print(f" {k}: {v}")
print(f"\nModel: {json_body.get('model', 'N/A')}")
print(f"Stream: {json_body.get('stream', False)}")
print("=" * 60)
# 调用原始方法
return await original_stream(self, method, url, **kwargs)
# 应用补丁
httpx.AsyncClient.stream = patched_stream
# 导入并运行代理
from codebuddy_proxy.__main__ import app
import uvicorn
if __name__ == "__main__":
print("🔍 Headers拦截模式启动")
print("所有发送到CodeBuddy的请求headers都会被打印")
print("-" * 60)
uvicorn.run(app, host="127.0.0.1", port=8787, log_level="warning")
You can’t perform that action at this time.