Improved URL encode/decode behaviour
This commit is contained in:
		
							parent
							
								
									ff19c9c625
								
							
						
					
					
						commit
						e49f89c782
					
				
					 3 changed files with 8 additions and 12 deletions
				
			
		| 
						 | 
					@ -108,7 +108,7 @@ namespace HTTP{
 | 
				
			||||||
        H.SetHeader("Host", proxyUrl.host);
 | 
					        H.SetHeader("Host", proxyUrl.host);
 | 
				
			||||||
      }
 | 
					      }
 | 
				
			||||||
    }else{
 | 
					    }else{
 | 
				
			||||||
      H.url = "/" + Encodings::URL::encode(link.path);
 | 
					      H.url = "/" + Encodings::URL::encode(link.path, "/:=@[]");
 | 
				
			||||||
      if (link.args.size()){H.url += "?" + link.args;}
 | 
					      if (link.args.size()){H.url += "?" + link.args;}
 | 
				
			||||||
      if (link.port.size()){
 | 
					      if (link.port.size()){
 | 
				
			||||||
        H.SetHeader("Host", link.host + ":" + link.port);
 | 
					        H.SetHeader("Host", link.host + ":" + link.port);
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -97,8 +97,8 @@ namespace Encodings{
 | 
				
			||||||
    for (int i = 0; i < max; i++){
 | 
					    for (int i = 0; i < max; i++){
 | 
				
			||||||
      if (('0' <= c[i] && c[i] <= '9') || ('a' <= c[i] && c[i] <= 'z') ||
 | 
					      if (('0' <= c[i] && c[i] <= '9') || ('a' <= c[i] && c[i] <= 'z') ||
 | 
				
			||||||
          ('A' <= c[i] && c[i] <= 'Z') ||
 | 
					          ('A' <= c[i] && c[i] <= 'Z') ||
 | 
				
			||||||
          (c[i] == '$' || c[i] == '-' || c[i] == '_' || c[i] == '.' || c[i] == ',' || c[i] == '!' ||
 | 
					          (c[i] == '$' || c[i] == '-' || c[i] == '_' || c[i] == '.' || c[i] == ',' || c[i] == '!' || c[i] == '~' || c[i] == ';' ||
 | 
				
			||||||
           c[i] == '*' || c[i] == '(' || c[i] == ')' || c[i] == '/' || c[i] == '\'') || (ign.size() && ign.find(c[i]) != std::string::npos)){
 | 
					           c[i] == '*' || c[i] == '(' || c[i] == ')' || c[i] == '\'') || (ign.size() && ign.find(c[i]) != std::string::npos)){
 | 
				
			||||||
        escaped.append(&c[i], 1);
 | 
					        escaped.append(&c[i], 1);
 | 
				
			||||||
      }else{
 | 
					      }else{
 | 
				
			||||||
        if (c[i] == ' '){
 | 
					        if (c[i] == ' '){
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -135,11 +135,7 @@ HTTP::URL::URL(const std::string &url){
 | 
				
			||||||
    port = host;
 | 
					    port = host;
 | 
				
			||||||
    host = "";
 | 
					    host = "";
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
  EXTREME_MSG("URL host: %s", host.c_str());
 | 
					  EXTREME_MSG("URL: %s", getUrl().c_str());
 | 
				
			||||||
  EXTREME_MSG("URL protocol: %s", protocol.c_str());
 | 
					 | 
				
			||||||
  EXTREME_MSG("URL port: %s", port.c_str());
 | 
					 | 
				
			||||||
  EXTREME_MSG("URL path: %s", path.c_str());
 | 
					 | 
				
			||||||
  EXTREME_MSG("URL args: %s", args.c_str());
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/// Returns the port in numeric format
 | 
					/// Returns the port in numeric format
 | 
				
			||||||
| 
						 | 
					@ -184,9 +180,9 @@ std::string HTTP::URL::getUrl() const{
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
  if (port.size() && getPort() != getDefaultPort()){ret += ":" + port;}
 | 
					  if (port.size() && getPort() != getDefaultPort()){ret += ":" + port;}
 | 
				
			||||||
  ret += "/";
 | 
					  ret += "/";
 | 
				
			||||||
  if (path.size()){ret += Encodings::URL::encode(path, "=");}
 | 
					  if (path.size()){ret += Encodings::URL::encode(path, "/:=@[]");}
 | 
				
			||||||
  if (args.size()){ret += "?" + args;}
 | 
					  if (args.size()){ret += "?" + args;}
 | 
				
			||||||
  if (frag.size()){ret += "#" + Encodings::URL::encode(frag, "=");}
 | 
					  if (frag.size()){ret += "#" + Encodings::URL::encode(frag, "/:=@[]#?&");}
 | 
				
			||||||
  return ret;
 | 
					  return ret;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -210,7 +206,7 @@ std::string HTTP::URL::getProxyUrl() const{
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
  if (port.size() && getPort() != getDefaultPort()){ret += ":" + port;}
 | 
					  if (port.size() && getPort() != getDefaultPort()){ret += ":" + port;}
 | 
				
			||||||
  ret += "/";
 | 
					  ret += "/";
 | 
				
			||||||
  if (path.size()){ret += Encodings::URL::encode(path);}
 | 
					  if (path.size()){ret += Encodings::URL::encode(path, "/:=@[]");}
 | 
				
			||||||
  if (args.size()){ret += "?" + args;}
 | 
					  if (args.size()){ret += "?" + args;}
 | 
				
			||||||
  return ret;
 | 
					  return ret;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					@ -233,7 +229,7 @@ std::string HTTP::URL::getBareUrl() const{
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
  if (port.size() && getPort() != getDefaultPort()){ret += ":" + port;}
 | 
					  if (port.size() && getPort() != getDefaultPort()){ret += ":" + port;}
 | 
				
			||||||
  ret += "/";
 | 
					  ret += "/";
 | 
				
			||||||
  if (path.size()){ret += Encodings::URL::encode(path);}
 | 
					  if (path.size()){ret += Encodings::URL::encode(path, "/:=@[]");}
 | 
				
			||||||
  return ret;
 | 
					  return ret;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue