#include "http_status_line.h"
#include "string_util.h"
#include "string_number_conversions.h"
#include <algorithm>
const int http_status_line::kOk = 200;
const int http_status_line::kNoContent = 204;
const int http_status_line::kSeeOther = 303;
const int http_status_line::kNotModified = 304;
const int http_status_line::kBadRequest = 400;
const int http_status_line::kUnauthorized = 401;
const int http_status_line::kNotFound = 404;
const int http_status_line::kMethodNotAllowed = 405;
const int http_status_line::kInternalServerError = 500;
http_status_line::http_status_line(void)
{
}
http_status_line::~http_status_line(void)
{
}
HttpVersion http_status_line::ParseVersion(
std::string::const_iterator line_begin,
std::string::const_iterator line_end)
{
std::string::const_iterator p = line_begin;
// RFC2616 sec 3.1: HTTP-Version = "HTTP" "/" 1*DIGIT "." 1*DIGIT
// TODO: (1*DIGIT apparently means one or more digits, but we only handle 1).
// TODO: handle leading zeros, which is allowed by the rfc1616 sec 3.1.
if ((line_end - p < 4) || !LowerCaseEqualsASCII(p, p + 4, "http")) {
return HttpVersion();
}
p += 4;
if (p >= line_end || *p != '/') {
return HttpVersion();
}
std::string::const_iterator dot = find(p, line_end, '.');
if (dot == line_end) {
return HttpVersion();
}
++p; // from / to first digit.
++dot; // from . to second digit.
if (!(*p >= '0' && *p <= '9' && *dot >= '0' && *dot <= '9')) {
return HttpVersion();
}
uint16 major = *p - '0';
uint16 minor = *dot - '0';
return HttpVersion(major, minor);
}
int http_status_line::ParseStatusLine(const std::string& raw_input)
{
std::string::const_iterator line_begin = raw_input.begin();
std::string::const_iterator line_end = find(line_begin, raw_input.end(),'\0');
// has_headers = true, if there is any data following the status line.
// Used by ParseStatusLine() to decide if a HTTP/0.9 is really a HTTP/1.0.
bool has_headers = (line_end != raw_input.end() &&
(line_end + 1) != raw_input.end() &&
*(line_end + 1) != '\0');
std::string raw_headers_;
int32 response_code_ = 0;
HttpVersion http_version_;
// Extract the version number
HttpVersion parsed_http_version_ = ParseVersion(line_begin, line_end);
// Clamp the version number to one of: {0.9, 1.0, 1.1}
if (parsed_http_version_ == HttpVersion(0, 9) && !has_headers) {
http_version_ = HttpVersion(0, 9);
raw_headers_ = "HTTP/0.9";
} else if (parsed_http_version_ >= HttpVersion(1, 1)) {
http_version_ = HttpVersion(1, 1);
raw_headers_ = "HTTP/1.1";
} else {
// Treat everything else like HTTP 1.0
http_version_ = HttpVersion(1, 0);
raw_headers_ = "HTTP/1.0";
}
if (parsed_http_version_ != http_version_) {
}
// TODO(eroman): this doesn't make sense if ParseVersion failed.
std::string::const_iterator p = find(line_begin, line_end, ' ');
if (p == line_end) {
raw_headers_.append(" 200 OK");
raw_headers_.push_back('\0');
response_code_ = 200;
return response_code_;
}
// Skip whitespace.
while (*p == ' ')
++p;
std::string::const_iterator code = p;
while (*p >= '0' && *p <= '9')
++p;
if (p == code) {
raw_headers_.append(" 200 OK");
response_code_ = 200;
return response_code_;
}
raw_headers_.push_back(' ');
raw_headers_.append(code, p);
raw_headers_.push_back(' ');
StringToInt(code, p, &response_code_);
// Skip whitespace.
while (*p == ' ')
++p;
// Trim trailing whitespace.
while (line_end > p && line_end[-1] == ' ')
--line_end;
if (p == line_end) {
// Not super critical what we put here. Just use "OK"
// even if it isn't descriptive of response_code_.
raw_headers_.append("OK");
} else {
raw_headers_.append(p, line_end);
}
raw_headers_.push_back('\0');
return response_code_;
}
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
chrome中剥出的基础库 (148个子文件)
histogram.cc 41KB
tracked_objects.cc 32KB
file_util.cc 25KB
message_loop.cc 21KB
file_path.cc 17KB
string_number_conversions.cc 16KB
time_win.cc 14KB
escape.cc 14KB
pickle.cc 11KB
icu_utf.cc 7KB
thread_local_storage_win.cc 7KB
string_util.cc 6KB
platform_file.cc 6KB
string_piece.cc 6KB
utf_string_conversions.cc 5KB
stringprintf.cc 5KB
utf_offset_string_conversions.cc 5KB
utf_string_conversion_utils.cc 5KB
thread.cc 5KB
platform_thread_win.cc 5KB
simple_thread.cc 4KB
string_split.cc 4KB
tracked.cc 4KB
message_loop_proxy_impl.cc 3KB
gtime.cc 3KB
cpu.cc 3KB
waitable_event_win.cc 3KB
win32.cc 3KB
windows_version.cc 2KB
sys_string_conversions.cc 2KB
at_exit.cc 2KB
thread_collision_warner.cc 2KB
ref_counted.cc 2KB
message_pump_default.cc 2KB
thread_restrictions.cc 2KB
lazy_instance.cc 2KB
weak_ptr.cc 1KB
lock.cc 1KB
task_queue.cc 1KB
ref_counted_memory.cc 1KB
callback_internal.cc 956B
thread_local_win.cc 915B
wrapped_window_proc.cc 903B
thread_checker_impl.cc 898B
lock_impl_win.cc 854B
timer.cc 706B
task.cc 601B
non_thread_safe_impl.cc 554B
alias.cc 471B
message_loop_proxy.cc 394B
message_pump.cc 306B
http_status_line.cpp 4KB
session_dacl.cpp 2KB
dcheck.cpp 538B
logging.cpp 317B
bind_internal.h 66KB
tuple.h 38KB
histogram.h 30KB
tracked_objects.h 29KB
task.h 20KB
callback.h 20KB
message_loop.h 18KB
gtime.h 17KB
stl_util-inl.h 15KB
basictypes.h 14KB
file_util.h 14KB
scoped_ptr.h 11KB
icu_utf.h 11KB
singleton.h 10KB
pickle.h 9KB
timer.h 8KB
bind_helpers.h 8KB
callback_old.h 8KB
string_tokenizer.h 7KB
thread_collision_warner.h 7KB
weak_ptr.h 7KB
ref_counted.h 7KB
simple_thread.h 7KB
lazy_instance.h 7KB
thread.h 7KB
escape.h 7KB
atomicops.h 7KB
scoped_ptr.h 6KB
observer_list.h 6KB
atomicops_internals_x86_msvc.h 6KB
bind_internal_win.h 5KB
dcheck.h 5KB
tracked.h 5KB
compiler_specific.h 5KB
raw_scoped_refptr_mismatch_checker.h 5KB
string_piece.h 5KB
message_pump.h 5KB
waitable_event.h 5KB
callback_internal.h 5KB
build_config.h 4KB
utf_string_conversion_utils.h 4KB
string_util.h 4KB
thread_local.h 4KB
platform_thread.h 4KB
platform_file.h 4KB
共 148 条
- 1
- 2
木头菇
- 粉丝: 87
- 资源: 6
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
- 1
- 2
- 3
- 4
- 5
- 6
前往页