Example #1
0
//htt
func (this *Tingo) genUrl(url string) string {
	queryParam, fragment := "", "" // 包含?,#
	paramIndex := strings.Index(url, "?")
	if paramIndex != -1 {
		queryParam = com.Substring(url, paramIndex) //"?"后边的参数
		url = com.Substr(url, 0, paramIndex)
	} else {
		paramIndex = strings.Index(url, "#")
		if paramIndex != -1 {
			fragment = com.Substring(url, paramIndex) //"#"后边的参数
			url = com.Substr(url, 0, paramIndex)
		}
	}
	// 如果url == host
	if url == this.host || url == this.agreementAndHost {
		return url + "/" + this.defaultFilename + queryParam + fragment
	}

	genFilename, needApend := this.genFilename(url)
	if genFilename != "" {
		if needApend {
			url += "/" + genFilename + queryParam + fragment
		} else {
			// 是a.php => a.html
			urlArr := strings.Split(url, "/")
			urlArr = urlArr[:len(urlArr)-1]
			url = strings.Join(urlArr, "/") + "/" + genFilename
		}
	}

	return url
}
Example #2
0
func (this *Tingo) trimQueryParams(url string) string {
	pos := strings.Index(url, "?")
	if pos != -1 {
		url = com.Substr(url, 0, pos)
	}

	pos = strings.Index(url, "#")
	if pos != -1 {
		url = com.Substr(url, 0, pos)
	}

	return url
}
Example #3
0
func (this *Tingo) genFilename(url string) (string, bool) {
	urlArr := strings.Split(url, "/")
	if urlArr != nil {
		last := urlArr[len(urlArr)-1]
		ext := strings.ToLower(filepath.Ext(url)) //获取后缀
		if ext == "" {
			return this.defaultFilename, true // 需要append到url后面
		} else if com.InArray([]string{".php", ".jsp", ".asp", ".aspx"}, ext) {
			filename := filepath.Base(last)                            // a.php
			filename = com.Substr(filename, 0, len(filename)-len(ext)) // a
			return filename + ".html", false
		}
	}
	return "", true
}
Example #4
0
//格式化url
func (this *Tingo) parseUrl(url string) {
	if strings.HasPrefix(url, "http://") {
		this.agreement = "http://"
	} else {
		this.agreement = "https://"
	}

	url = strings.Replace(url, this.agreement, "", 1)
	index := strings.Index(url, "/")
	if index == -1 {
		this.host = url
	} else {
		this.host = com.Substr(url, 0, index)
	}
	this.agreementAndHost = this.agreement + this.host
}