Permalink
Browse files

added 80 port ersasing to checkHost

git-svn-id: https://svn.opensource.yandex.net/xscript/trunk@703 b01ef89b-65f2-463d-9415-e8412542ae63
  • Loading branch information...
1 parent 5074cc7 commit c8c19f44719efb496dc84d073a685566f30eb2cf golubtsov committed Jan 20, 2009
Showing with 16 additions and 6 deletions.
  1. +1 −1 include/xscript/request_impl.h
  2. +4 −3 library/parser.cpp
  3. +11 −2 library/request_impl.cpp
@@ -130,7 +130,7 @@ class RequestImpl : public Request {
protected:
std::string checkUrlEscaping(const Range &range);
- void checkHost(const Range &range);
+ Range checkHost(const Range &range);
private:
RequestImpl(const RequestImpl &);
View
@@ -125,13 +125,14 @@ void
Parser::addHeader(RequestImpl *req, const Range &key, const Range &value, Encoder *encoder) {
std::string header = normalizeInputHeaderName(key);
+ Range checked_value = value;
if (strcmp(header.c_str(), RequestImpl::HOST_KEY.c_str()) == 0) {
- req->checkHost(value);
+ checked_value = req->checkHost(value);
}
- Range norm_value = value;
+ Range norm_value = checked_value;
std::string result;
- if (req->normalizeHeader(header, value, result)) {
+ if (req->normalizeHeader(header, checked_value, result)) {
norm_value = createRange(result);
}
@@ -451,13 +451,17 @@ RequestImpl::checkUrlEscaping(const Range &range) {
return result;
}
-void
+Range
RequestImpl::checkHost(const Range &range) {
Range host(range);
int length = range.size();
const char *end_pos = range.begin() + length - 1;
+ bool remove_port = false;
for (int i = 0; i < length; ++i) {
if (*(end_pos - i) == ':' && i + 1 != length) {
+ if (i == 3 && *(end_pos - 2) == '8' && *(end_pos - 1) == '0') {
+ remove_port = true;
+ }
host = Range(range.begin(), end_pos - i);
break;
}
@@ -467,8 +471,13 @@ RequestImpl::checkHost(const Range &range) {
if (*it == '/' || *it == ':') {
throw std::runtime_error("Incorrect host");
}
-
}
+
+ if (remove_port) {
+ return host;
+ }
+
+ return range;
}
RequestFactory::RequestFactory() {

0 comments on commit c8c19f4

Please sign in to comment.