Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1272)

Side by Side Diff: net/http/http_util.cc

Issue 213017: Moving two http utility functions to a separate source file due to dependency... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 11 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | net/http/http_util_icu.cc » ('j') | net/http/http_util_icu.cc » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 // The rules for parsing content-types were borrowed from Firefox: 5 // The rules for parsing content-types were borrowed from Firefox:
6 // http://lxr.mozilla.org/mozilla/source/netwerk/base/src/nsURLHelper.cpp#834 6 // http://lxr.mozilla.org/mozilla/source/netwerk/base/src/nsURLHelper.cpp#834
7 7
8 #include "net/http/http_util.h" 8 #include "net/http/http_util.h"
9 9
10 #include <algorithm> 10 #include <algorithm>
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
47 return end; 47 return end;
48 } 48 }
49 49
50 NOTREACHED(); 50 NOTREACHED();
51 return line.length(); 51 return line.length();
52 } 52 }
53 53
54 //----------------------------------------------------------------------------- 54 //-----------------------------------------------------------------------------
55 55
56 // static 56 // static
57 std::string HttpUtil::PathForRequest(const GURL& url) {
58 DCHECK(url.is_valid() && (url.SchemeIs("http") || url.SchemeIs("https")));
59 if (url.has_query())
60 return url.path() + "?" + url.query();
61 return url.path();
62 }
63
64 // static
65 std::string HttpUtil::SpecForRequest(const GURL& url) {
66 DCHECK(url.is_valid() && (url.SchemeIs("http") || url.SchemeIs("https")));
67 return SimplifyUrlForRequest(url).spec();
68 }
69
70 // static
71 size_t HttpUtil::FindDelimiter(const string& line, size_t search_start, 57 size_t HttpUtil::FindDelimiter(const string& line, size_t search_start,
72 char delimiter) { 58 char delimiter) {
73 do { 59 do {
74 // search_start points to the spot from which we should start looking 60 // search_start points to the spot from which we should start looking
75 // for the delimiter. 61 // for the delimiter.
76 const char delim_str[] = { delimiter, '"', '\'', '\0' }; 62 const char delim_str[] = { delimiter, '"', '\'', '\0' };
77 size_t cur_delim_pos = line.find_first_of(delim_str, search_start); 63 size_t cur_delim_pos = line.find_first_of(delim_str, search_start);
78 if (cur_delim_pos == string::npos) 64 if (cur_delim_pos == string::npos)
79 return line.length(); 65 return line.length();
80 66
(...skipping 365 matching lines...) Expand 10 before | Expand all | Expand 10 after
446 const int slop = 4; 432 const int slop = 4;
447 const int http_len = 4; 433 const int http_len = 4;
448 434
449 if (buf_len >= http_len) { 435 if (buf_len >= http_len) {
450 int i_max = std::min(buf_len - http_len, slop); 436 int i_max = std::min(buf_len - http_len, slop);
451 for (int i = 0; i <= i_max; ++i) { 437 for (int i = 0; i <= i_max; ++i) {
452 if (LowerCaseEqualsASCII(buf + i, buf + i + http_len, "http")) 438 if (LowerCaseEqualsASCII(buf + i, buf + i + http_len, "http"))
453 return i; 439 return i;
454 } 440 }
455 } 441 }
456 return -1; // Not found 442 return -1; // Not found
457 } 443 }
458 444
459 int HttpUtil::LocateEndOfHeaders(const char* buf, int buf_len, int i) { 445 int HttpUtil::LocateEndOfHeaders(const char* buf, int buf_len, int i) {
460 bool was_lf = false; 446 bool was_lf = false;
461 char last_c = '\0'; 447 char last_c = '\0';
462 for (; i < buf_len; ++i) { 448 for (; i < buf_len; ++i) {
463 char c = buf[i]; 449 char c = buf[i];
464 if (c == '\n') { 450 if (c == '\n') {
465 if (was_lf) 451 if (was_lf)
466 return i + 1; 452 return i + 1;
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
505 return end; 491 return end;
506 return begin + i; 492 return begin + i;
507 } 493 }
508 494
509 // Helper used by AssembleRawHeaders, to skip past leading LWS. 495 // Helper used by AssembleRawHeaders, to skip past leading LWS.
510 static const char* FindFirstNonLWS(const char* begin, const char* end) { 496 static const char* FindFirstNonLWS(const char* begin, const char* end) {
511 for (const char* cur = begin; cur != end; ++cur) { 497 for (const char* cur = begin; cur != end; ++cur) {
512 if (!HttpUtil::IsLWS(*cur)) 498 if (!HttpUtil::IsLWS(*cur))
513 return cur; 499 return cur;
514 } 500 }
515 return end; // Not found. 501 return end; // Not found.
516 } 502 }
517 503
518 std::string HttpUtil::AssembleRawHeaders(const char* input_begin, 504 std::string HttpUtil::AssembleRawHeaders(const char* input_begin,
519 int input_len) { 505 int input_len) {
520 std::string raw_headers; 506 std::string raw_headers;
521 raw_headers.reserve(input_len); 507 raw_headers.reserve(input_len);
522 508
523 const char* input_end = input_begin + input_len; 509 const char* input_end = input_begin + input_len;
524 510
525 // Skip any leading slop, since the consumers of this output 511 // Skip any leading slop, since the consumers of this output
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after
671 TrimLWS(&value_begin_, &value_end_); 657 TrimLWS(&value_begin_, &value_end_);
672 658
673 // bypass empty values. 659 // bypass empty values.
674 if (value_begin_ != value_end_) 660 if (value_begin_ != value_end_)
675 return true; 661 return true;
676 } 662 }
677 return false; 663 return false;
678 } 664 }
679 665
680 } // namespace net 666 } // namespace net
OLDNEW
« no previous file with comments | « no previous file | net/http/http_util_icu.cc » ('j') | net/http/http_util_icu.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698