libHttpClient
Copilot instructions296 starsChanged 8 months agoMITView on GitHub
libHttpClient is a cross-platform C/C++ library providing a platform abstraction layer for HTTP and WebSocket communication. It is used by Xbox Live Service API (XSAPI) and the PlayFab SDK. Each platform implements PlatformInitialize() in Source/Platform/<Platform>/PlatformComponents_<Platform>.cpp, which creates platform-specific IHttpProvider and IWebSocketProvider implementations. Platform selection is controlled by: Sub-namespaces: xbox::httpclient::log, xbox::httpclient::detail, xbox::httpclient::test
The file
We split this copilot-instructions.md into the rules it gives an agent
9 rules. About 0 are common, 1 is distinctive, and 8 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈1
Distinctive · estimate
This author's own choices. Worth a look.
8
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 75
All functions return HRESULT (S_OK on success)
- Very specific: line 77
Use error macros from Source/Common/ResultMacros.h:
- Very specific: line 87
Use custom allocator types from Source/Common/Types.h:
- Very specific: line 96
Use #pragma once (no traditional include guards)
- Very specific: line 166
Test files are in Tests/UnitTests/Tests/:
- Very specific: line 183
Use DEFINE_TEST_CLASS(Name) / DEFINE_TEST_CASE(Name) macros (not raw TEST_CLASS/TEST_METHOD)
- Very specific: line 184
Use VERIFY_ARE_EQUAL, VERIFY_SUCCEEDED(hr), VERIFY_IS_TRUE assertions
- Very specific: line 197
All managed as git submodules in External/:
- Distinctive: line 204
After cloning, run: git submodule update --init --recursive
≈ “Common” is an estimate: at least 1 in 5 of the 1,644 Copilot instructions files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Copilot Instructions — libHttpClient
Project Overview
libHttpClient is a cross-platform C/C++ library providing a platform abstraction layer for HTTP and WebSocket communication. It is used by Xbox Live Service API (XSAPI) and the PlayFab SDK.
- Language: C/C++ (C++17 standard required)
- Public API: Flat C API — all public functions use
HC*prefix with C linkage (STDAPI) - Platforms: Win32, UWP, GDK (Xbox/PC gaming), XDK (legacy Xbox One), iOS, macOS, Android, Linux
- Build systems: MSBuild (Windows), CMake (Linux/Android), Xcode (iOS/macOS)
- CI: Azure DevOps (see
Utilities/Pipelines/libHttpClient.CI.yml)
Architecture
Include/httpClient/ — Public C API headers (httpClient.h, httpProvider.h, mock.h, trace.h, async.h)
Include/ — XAsync.h, XAsyncProvider.h, XTaskQueue.h (async task queue API)
Source/
Common/ — Shared utilities, types, Result<T>, error macros, pch, memory allocator
Global/ — Global state, singleton, custom memory (mem.h)
HTTP/ — Core HTTP call logic, retry, compression
WinHttp/ — Win32/GDK HTTP provider (WinHTTP)
XMLHttp/ — UWP HTTP provider
Curl/ — Linux HTTP provider (libcurl)
Android/ — Android HTTP provider (JNI bridge)
Apple/ — iOS/macOS HTTP provider
WebSocket/ — Core WebSocket logic
Websocketpp/ — Linux WebSocket provider (websocketpp + asio)
Android/ — Android WebSocket provider
Mock/ — Mock HTTP/WebSocket layer for testing
Platform/ — Platform initialization (PlatformComponents pattern)
Win32/, UWP/, GDK/, XDK/, Android/, Apple/, Linux/, Generic/
SSL/ — SSL/TLS support
Task/ — Async task infrastructure
Logger/ — Logging/tracing
Build/ — Platform-specific build projects (.vcxproj, CMakeLists.txt, .xcworkspace)
Tests/UnitTests/ — TAEF/TE unit tests
External/ — Git submodules: openssl, curl, websocketpp, asio, zlib
Samples/ — Sample apps (Win32, UWP, GDK)
Utilities/Pipelines/ — Azure DevOps CI pipeline definitionsPlatform Abstraction Pattern
Each platform implements PlatformInitialize() in Source/Platform/<Platform>/PlatformComponents_<Platform>.cpp, which creates platform-specific IHttpProvider and IWebSocketProvider implementations. Platform selection is controlled by:
- MSBuild:
platform_select.propsauto-detects based onApplicationType/Platform→ setsHC_PLATFORM_MSBUILD_GUESS - Code:
HC_PLATFORMpreprocessor constant (e.g.,HC_PLATFORM_WIN32,HC_PLATFORM_GDK,HC_PLATFORM_ANDROID) - Feature flags:
HC_NOZLIB,HC_NOWEBSOCKETSto exclude optional features
Coding Conventions
Naming
| Element | Convention | Example |
| Public C API functions | HC prefix, PascalCase | HCHttpCallCreate(), HCWebSocketConnectAsync() |
| Internal functions | camelCase | ShouldRetry(), ResetResponseProperties() |
| Member variables | m_ prefix | m_provider, m_refCount |
| Types/Classes | PascalCase | HC_CALL, WinHttpProvider, Result<T> |
| Constants/Macros | UPPER_SNAKE_CASE | MAX_DELAY_TIME_IN_SEC, HC_PLATFORM_WIN32 |
| File names | PascalCase or descriptive | PlatformComponents_Win32.cpp, httpcall.h |
Namespaces
NAMESPACE_XBOX_HTTP_CLIENT_BEGIN // namespace xbox { namespace httpclient {
NAMESPACE_XBOX_HTTP_CLIENT_END // }}Sub-namespaces: xbox::httpclient::log, xbox::httpclient::detail, xbox::httpclient::test
Error Handling
- All functions return
HRESULT(S_OK on success) - No exceptions thrown from public API — all functions are
noexceptwithtry {} CATCH_RETURN()wrapping - Use error macros from
Source/Common/ResultMacros.h:RETURN_IF_FAILED(hr)— early return on failureRETURN_HR_IF(hr, condition)— conditional returnRETURN_IF_NULL_ALLOC(ptr)— returns E_OUTOFMEMORY if nullLOG_IF_FAILED(hr)— log without returning
- Internal result type:
Result<T>(Source/Common/Result.h) — wraps HRESULT + optional payload + error message
Memory Management
- Caller-controlled allocation via
HCMemSetFunctions()callback - Use custom allocator types from
Source/Common/Types.h:http_internal_string,http_internal_vector<T>,http_internal_map<K,V>HC_UNIQUE_PTR<T>,SharedPtr<T>,UniquePtr<T>http_allocate_unique<T>(...)for creating unique_ptr with custom allocator
- Never use raw
new/delete— useMake<T>()/Delete<T>()fromSource/Global/mem.h - RAII patterns for all resource management
Headers
- Use
#pragma once(no traditional include guards) - Include order:
pch.h→ own header → internal headers (quoted) → platform headers (angle brackets) → STL - Public API headers use angle brackets:
#include <httpClient/httpClient.h> - Internal headers use quoted relative paths:
#include "HTTP/httpcall.h"
Other Patterns
- Atomic reference counting for handle types (
std::atomic<int> refCount) - Copy/move constructors deleted on handle types
- Static
CALLBACKfunctions for C-style callback bridges - Conditional compilation via
#if HC_PLATFORM == HC_PLATFORM_* - Compiler warnings: Level 4, warnings as errors
- Security: SDL checks, Control Flow Guard (
/guard:cf), ASLR
Build Commands
Windows (MSBuild)
# VS2022 — Win32 x64 Debug
msbuild libHttpClient.vs2022.sln /p:Configuration=Debug /p:Platform=x64
# VS2022 — Win32 x64 Release
msbuild libHttpClient.vs2022.sln /p:Configuration=Release /p:Platform=x64
# VS2022 — ARM64
msbuild libHttpClient.vs2022.sln /p:Configuration=Debug /p:Platform=ARM64
# GDK target
msbuild libHttpClient.vs2022.sln /p:Configuration=Debug /p:Platform=Gaming.Desktop.x64Or open libHttpClient.vs2022.sln in Visual Studio and build from the IDE.
Build configuration flags (set in hc_settings.props, copy from hc_settings.props.example):
HCNoZlib=true— exclude zlib/compressionHCNoWebSockets=true— exclude WebSocket APIsHCExternalOpenSSL=true— use external OpenSSL binaries instead of bundled
Linux (CMake)
# Uses build scripts in Utilities/Pipelines/Scripts/
# Build OpenSSL, curl, then libHttpClient:
bash Utilities/Pipelines/Scripts/openssl_Linux.bash -c Debug
bash Utilities/Pipelines/Scripts/curl_Linux.bash -c Debug
bash Utilities/Pipelines/Scripts/libHttpClient_Linux.bash -c Debug -st # static lib
bash Utilities/Pipelines/Scripts/libHttpClient_Linux.bash -c Debug # shared libiOS/macOS (Xcode)
# Workspace: Build/libHttpClient.Apple.C/libHttpClient.xcworkspace
# Schemes: libHttpClient, libHttpClient_NOWEBSOCKETS
xcodebuild -workspace Build/libHttpClient.Apple.C/libHttpClient.xcworkspace \
-scheme libHttpClient -sdk iphoneos -configuration Debug clean buildAndroid (Gradle + NDK)
cd Build/libHttpClient.Android.Workspace
./gradlew assembleDebugTesting
Unit Tests (TAEF/TE)
Test files are in Tests/UnitTests/Tests/:
HttpTests.cpp,WebsocketTests.cpp,MockTests.cpp,GlobalTests.cppTaskQueueTests.cpp,AsyncBlockTests.cpp,LocklessQueueTests.cpp,ProxyTests.cppBufferSize/— buffer size unit and E2E tests
Test frameworks: Both TAEF and TE (Visual Studio CppUnitTest) are supported via macro abstraction in Tests/UnitTests/Support/DefineTestMacros.h.
Running tests:
# TAEF from command line (after building the test DLL)
te.exe Out\x64\Debug\libHttpClient.UnitTest.TAEF\libHttpClient.UnitTest.TAEF.dll
# Or use Visual Studio Test Explorer with the TE projectTest patterns:
- Use
DEFINE_TEST_CLASS(Name)/DEFINE_TEST_CASE(Name)macros (not raw TEST_CLASS/TEST_METHOD) - Use
VERIFY_ARE_EQUAL,VERIFY_SUCCEEDED(hr),VERIFY_IS_TRUEassertions - Async tests use
PumpedTaskQueuehelper (creates manual-dispatch XTaskQueue with worker threads) - Mock HTTP responses via
HCMockCallCreate()+HCMockResponseSet*()APIs - Callback bridging via
CallbackThunk<T, R>template
CI Pipeline
Azure DevOps pipeline at Utilities/Pipelines/libHttpClient.CI.yml:
- Triggers: Push to
main, PRs tomain/releases/*, nightly at 8am UTC - Matrix: Win32/UWP VS2022 (x86/x64/ARM64 × Debug/Release), iOS (Debug/Release), Linux (Debug/Release)
External Dependencies
All managed as git submodules in External/:
- openssl — SSL/TLS
- curl — HTTP for Linux
- websocketpp — WebSocket for Linux
- asio — Async I/O for websocketpp
- zlib — Compression
After cloning, run: git submodule update --init --recursive
Key Rules
- All public API functions must be
noexceptwithtry {} CATCH_RETURN()wrapping - Never throw exceptions from public API — use HRESULT error codes
- Use custom allocators — never raw
new/delete; usehttp_internal_*types andMake<T>/Delete<T> - Platform code stays isolated — platform-specific logic goes in
Source/Platform/<Platform>/orSource/HTTP/<Provider>/ - All new functionality needs unit tests — use DEFINE_TEST_CLASS/DEFINE_TEST_CASE macros
- Submit PRs against the development branch, not main
- Keep changes small — avoid unnecessary deltas
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

