blob: 574c9b5c4d3704373191053245f82866614bcc31 [file] [log] [blame]
httprr trace v1
858 3193
POST https://generativelanguage.googleapis.com/v1beta/models/gemini-1.5-pro:generateContent?%24alt=json%3Benum-encoding%3Dint HTTP/1.1
Host: generativelanguage.googleapis.com
User-Agent: Go-http-client/1.1
Content-Length: 540
Content-Type: application/json
x-goog-request-params: model=models%2Fgemini-1.5-pro
{"model":"models/gemini-1.5-pro","contents":[{"parts":[{"text":"CanonicalHeaderKey returns the canonical format of the header key s. The canonicalization converts the first letter and any letter following a hyphen to upper case; the rest are converted to lowercase. For example, the canonical key for 'accept-encoding' is 'Accept-Encoding'. If s contains a space or invalid header field bytes, it is returned without modifications."},{"text":"When should I use CanonicalHeaderKey?"}],"role":"user"}],"generationConfig":{"candidateCount":1}}HTTP/2.0 200 OK
Alt-Svc: h3=":443"; ma=2592000,h3-29=":443"; ma=2592000
Cache-Control: private
Content-Type: application/json; charset=UTF-8
Date: Mon, 28 Oct 2024 18:02:47 GMT
Server: scaffolding on HTTPServer2
Server-Timing: gfet4t7; dur=8601
Vary: Origin
Vary: X-Origin
Vary: Referer
X-Content-Type-Options: nosniff
X-Frame-Options: SAMEORIGIN
X-Xss-Protection: 0
{
"candidates": [
{
"content": {
"parts": [
{
"text": "You should use `CanonicalHeaderKey` **when you need to compare or interact with HTTP headers in a case-insensitive way, ensuring compatibility across different systems and implementations.**\n\nHere's a breakdown of when to use it:\n\n**Situations where `CanonicalHeaderKey` is beneficial:**\n\n* **Comparing HTTP Headers:** Different systems might use varying capitalization for header keys (e.g., \"Content-Type\" vs. \"content-type\"). `CanonicalHeaderKey` provides a standardized format, ensuring consistent comparisons.\n* **Accessing Headers in Maps/Dictionaries:** Many programming languages use case-sensitive keys for maps/dictionaries. Using the canonical form as the key when storing or retrieving headers avoids issues arising from inconsistent capitalization.\n* **Interacting with HTTP Libraries/Frameworks:** Some libraries might have specific requirements or expectations regarding header key capitalization. Using `CanonicalHeaderKey` ensures compliance.\n* **Generating HTTP Messages:** When constructing HTTP requests or responses, using canonicalized header keys promotes consistency and adherence to standards.\n\n**Example:**\n\nImagine you're building an HTTP client library. You want to allow users to access headers case-insensitively:\n\n```python\ndef get_header(headers, key):\n canonical_key = CanonicalHeaderKey(key)\n return headers.get(canonical_key)\n\n# Example usage\nheaders = {'Content-Type': 'application/json'}\ncontent_type = get_header(headers, 'content-type') # Returns 'application/json'\n```\n\n**Points to Note:**\n\n* **Standard Compliance:** The canonicalization process in `CanonicalHeaderKey` typically follows the HTTP standard (RFC 7230) for header key formatting.\n* **Language/Library Specifics:** The availability and exact implementation of `CanonicalHeaderKey` might vary depending on the programming language or HTTP library you're using.\n\nIn summary, **use `CanonicalHeaderKey` whenever you need to handle HTTP header keys in a standardized, case-insensitive manner to ensure interoperability and avoid potential issues due to varying capitalization.** \n"
}
],
"role": "model"
},
"finishReason": 1,
"index": 0,
"safetyRatings": [
{
"category": 9,
"probability": 1
},
{
"category": 8,
"probability": 1
},
{
"category": 7,
"probability": 1
},
{
"category": 10,
"probability": 1
}
]
}
],
"usageMetadata": {
"promptTokenCount": 81,
"candidatesTokenCount": 433,
"totalTokenCount": 514
},
"modelVersion": "gemini-1.5-pro-001"
}