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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
|
// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "net/http/http_basic_stream.h"
#include "base/stringprintf.h"
#include "net/base/io_buffer.h"
#include "net/base/net_errors.h"
#include "net/http/http_request_headers.h"
#include "net/http/http_request_info.h"
#include "net/http/http_stream_parser.h"
#include "net/http/http_util.h"
#include "net/socket/client_socket_handle.h"
namespace net {
HttpBasicStream::HttpBasicStream(ClientSocketHandle* connection,
HttpStreamParser* parser,
bool using_proxy)
: read_buf_(new GrowableIOBuffer()),
parser_(parser),
connection_(connection),
using_proxy_(using_proxy),
request_info_(NULL) {
}
HttpBasicStream::~HttpBasicStream() {}
int HttpBasicStream::InitializeStream(const HttpRequestInfo* request_info,
const BoundNetLog& net_log,
CompletionCallback* callback) {
DCHECK(!parser_.get());
request_info_ = request_info;
parser_.reset(new HttpStreamParser(connection_.get(), request_info,
read_buf_, net_log));
return OK;
}
int HttpBasicStream::SendRequest(const HttpRequestHeaders& headers,
UploadDataStream* request_body,
HttpResponseInfo* response,
CompletionCallback* callback) {
DCHECK(parser_.get());
DCHECK(request_info_);
const std::string path = using_proxy_ ?
HttpUtil::SpecForRequest(request_info_->url) :
HttpUtil::PathForRequest(request_info_->url);
request_line_ = base::StringPrintf("%s %s HTTP/1.1\r\n",
request_info_->method.c_str(),
path.c_str());
return parser_->SendRequest(request_line_, headers, request_body, response,
callback);
}
uint64 HttpBasicStream::GetUploadProgress() const {
return parser_->GetUploadProgress();
}
int HttpBasicStream::ReadResponseHeaders(CompletionCallback* callback) {
return parser_->ReadResponseHeaders(callback);
}
const HttpResponseInfo* HttpBasicStream::GetResponseInfo() const {
return parser_->GetResponseInfo();
}
int HttpBasicStream::ReadResponseBody(IOBuffer* buf, int buf_len,
CompletionCallback* callback) {
return parser_->ReadResponseBody(buf, buf_len, callback);
}
void HttpBasicStream::Close(bool not_reusable) {
#ifdef ANDROID
// Disable connection reuse for bug 5226268
// [Browser] http keep-alive packets are sent too frequently to network
parser_->Close(true);
#else
parser_->Close(not_reusable);
#endif
}
HttpStream* HttpBasicStream::RenewStreamForAuth() {
DCHECK(IsResponseBodyComplete());
DCHECK(!IsMoreDataBuffered());
parser_.reset();
return new HttpBasicStream(connection_.release(), NULL, using_proxy_);
}
bool HttpBasicStream::IsResponseBodyComplete() const {
return parser_->IsResponseBodyComplete();
}
bool HttpBasicStream::CanFindEndOfResponse() const {
return parser_->CanFindEndOfResponse();
}
bool HttpBasicStream::IsMoreDataBuffered() const {
return parser_->IsMoreDataBuffered();
}
bool HttpBasicStream::IsConnectionReused() const {
return parser_->IsConnectionReused();
}
void HttpBasicStream::SetConnectionReused() {
parser_->SetConnectionReused();
}
bool HttpBasicStream::IsConnectionReusable() const {
return parser_->IsConnectionReusable();
}
void HttpBasicStream::GetSSLInfo(SSLInfo* ssl_info) {
parser_->GetSSLInfo(ssl_info);
}
void HttpBasicStream::GetSSLCertRequestInfo(
SSLCertRequestInfo* cert_request_info) {
parser_->GetSSLCertRequestInfo(cert_request_info);
}
bool HttpBasicStream::IsSpdyHttpStream() const {
return false;
}
} // namespace net
|