1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #include "net/tools/fetch/http_session.h" 6 #include "net/tools/fetch/http_server_response_info.h" 7 8 HttpSession::HttpSession(const std::string& ip, int port) 9 : socket_(HttpListenSocket::CreateAndListen(ip, port, this)) { 10 } 11 12 HttpSession::~HttpSession() { 13 } 14 15 void HttpSession::OnRequest(HttpListenSocket* connection, 16 HttpServerRequestInfo* info) { 17 // TODO(mbelshe): Make this function more interesting. 18 19 // Generate a 10KB sequence of data. 20 CR_DEFINE_STATIC_LOCAL(std::string, data, ()); 21 if (data.length() == 0) { 22 while (data.length() < (10 * 1024)) 23 data += 'a' + (rand() % 26); 24 } 25 26 HttpServerResponseInfo response_info; 27 response_info.protocol = "HTTP/1.1"; 28 response_info.status = 200; 29 response_info.content_type = "text/plain"; 30 response_info.content_length = data.length(); 31 32 connection->Respond(&response_info, data); 33 } 34