本文整理汇总了C++中HTTPHeaderMap::set方法的典型用法代码示例。如果您正苦于以下问题:C++ HTTPHeaderMap::set方法的具体用法?C++ HTTPHeaderMap::set怎么用?C++ HTTPHeaderMap::set使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类HTTPHeaderMap
的用法示例。
在下文中一共展示了HTTPHeaderMap::set方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: didReceiveUnrecognizedHTTPRequest
void WebInspectorServer::didReceiveUnrecognizedHTTPRequest(WebSocketServerConnection* connection, PassRefPtr<HTTPRequest> request)
{
// request->url() contains only the path extracted from the HTTP request line
// and URL is poor at parsing incomplete URLs, so extract the interesting parts manually.
String path = request->url();
size_t pathEnd = path.find('?');
if (pathEnd == notFound)
pathEnd = path.find('#');
if (pathEnd != notFound)
path.truncate(pathEnd);
// Ask for the complete payload in memory for the sake of simplicity. A more efficient way would be
// to ask for header data and then let the platform abstraction write the payload straight on the connection.
Vector<char> body;
String contentType;
bool found = platformResourceForPath(path, body, contentType);
HTTPHeaderMap headerFields;
headerFields.set("Connection", "close");
headerFields.set("Content-Length", String::number(body.size()));
if (found)
headerFields.set("Content-Type", contentType);
// Send when ready and close immediately afterwards.
connection->sendHTTPResponseHeader(found ? 200 : 404, found ? "OK" : "Not Found", headerFields);
connection->sendRawData(body.data(), body.size());
connection->shutdownAfterSendOrNow();
}
示例2: newValue
static HTTPHeaderMap parseRFC822HeaderFields(const char* bytes, unsigned length)
{
String lastHeaderKey;
HTTPHeaderMap headerFields;
// Loop over lines until we're past the header, or we can't find any more end-of-lines
while (const char* endOfLine = findEndOfLine(bytes, length)) {
const char* line = bytes;
int lineLength = endOfLine - bytes;
// Move bytes to the character after the terminator as returned by findEndOfLine.
bytes = endOfLine + 1;
if ((*endOfLine == '\r') && (*bytes == '\n'))
bytes++; // Safe since findEndOfLine won't return a spanning CRLF.
length -= (bytes - line);
if (!lineLength) {
// Blank line; we're at the end of the header
break;
}
if (*line == ' ' || *line == '\t') {
// Continuation of the previous header
if (lastHeaderKey.isNull()) {
// malformed header; ignore it and continue
continue;
}
// Merge the continuation of the previous header
String currentValue = headerFields.get(lastHeaderKey);
String newValue(line, lineLength);
headerFields.set(lastHeaderKey, currentValue + newValue);
} else {
// Brand new header
const char* colon = line;
while (*colon != ':' && colon != endOfLine)
colon++;
if (colon == endOfLine) {
// malformed header; ignore it and continue
continue;
}
lastHeaderKey = capitalizeRFC822HeaderFieldName(String(line, colon - line));
String value;
for (colon++; colon != endOfLine; colon++) {
if (*colon != ' ' && *colon != '\t')
break;
}
if (colon == endOfLine)
value = "";
else
value = String(colon, endOfLine - colon);
String oldValue = headerFields.get(lastHeaderKey);
if (!oldValue.isNull())
value = oldValue + ", " + value;
headerFields.set(lastHeaderKey, value);
}
}
return headerFields;
}
示例3: addToHTTPHeaderMap
static void addToHTTPHeaderMap(const void* key, const void* value, void* context)
{
HTTPHeaderMap* httpHeaderMap = (HTTPHeaderMap*)context;
httpHeaderMap->set((CFStringRef)key, (CFStringRef)value);
}
示例4: if
static inline HTTPHeaderMap parseRFC822HeaderFields(const Vector<char>& buffer, unsigned length)
{
const char* bytes = buffer.data();
const char* eol;
String lastKey;
HTTPHeaderMap headerFields;
// Loop ove rlines until we're past the header, or we can't find any more end-of-lines
while ((eol = findEOL(bytes, length))) {
const char* line = bytes;
int lineLength = eol - bytes;
// Move bytes to the character after the terminator as returned by findEOL.
bytes = eol + 1;
if ((*eol == '\r') && (*bytes == '\n'))
bytes++; // Safe since findEOL won't return a spanning CRLF.
length -= (bytes - line);
if (lineLength == 0)
// Blank line; we're at the end of the header
break;
else if (*line == ' ' || *line == '\t') {
// Continuation of the previous header
if (lastKey.isNull()) {
// malformed header; ignore it and continue
continue;
} else {
// Merge the continuation of the previous header
String currentValue = headerFields.get(lastKey);
String newValue(line, lineLength);
headerFields.set(lastKey, currentValue + newValue);
}
} else {
// Brand new header
const char* colon;
for (colon = line; *colon != ':' && colon != eol; colon++) {
// empty loop
}
if (colon == eol)
// malformed header; ignore it and continue
continue;
else {
lastKey = capitalizeRFC822HeaderFieldName(String(line, colon - line));
String value;
for (colon++; colon != eol; colon++) {
if (*colon != ' ' && *colon != '\t')
break;
}
if (colon == eol)
value = "";
else
value = String(colon, eol - colon);
String oldValue = headerFields.get(lastKey);
if (!oldValue.isNull()) {
String tmp = oldValue;
tmp += ", ";
tmp += value;
value = tmp;
}
headerFields.set(lastKey, value);
}
}
}
return headerFields;
}