當前位置: 首頁>>代碼示例>>Golang>>正文


Golang Profile.SettingDont302方法代碼示例

本文整理匯總了Golang中github.com/benbearchen/asuran/profile.Profile.SettingDont302方法的典型用法代碼示例。如果您正苦於以下問題:Golang Profile.SettingDont302方法的具體用法?Golang Profile.SettingDont302怎麽用?Golang Profile.SettingDont302使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在github.com/benbearchen/asuran/profile.Profile的用法示例。


在下文中一共展示了Profile.SettingDont302方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: remoteProxyUrl


//.........這裏部分代碼省略.........

		act := p.urlOp.Action(remoteIP, fullUrl)
		//fmt.Println("url act: " + act.String())
		speed := p.urlOp.Speed(remoteIP, fullUrl)
		bodyDelay := p.urlOp.BodyDelay(remoteIP, fullUrl)

		switch act.Act {
		case profile.UrlActCache:
			needCache = true
		case profile.UrlActStatus:
			status := 502
			if c, err := strconv.Atoi(act.ContentValue); err == nil {
				status = c
			}

			w.WriteHeader(status)
			f.Log("proxy " + fullUrl + " status " + strconv.Itoa(status))
			return
		case profile.UrlActMap:
			requestUrl = act.ContentValue
			requestR = nil
			contentSource = "map " + act.ContentValue
		case profile.UrlActRedirect:
			http.Redirect(w, r, act.ContentValue, 302)
			f.Log("proxy " + fullUrl + " redirect " + act.ContentValue)
			return
		case profile.UrlActRewritten:
			fallthrough
		case profile.UrlActRestore:
			fallthrough
		case profile.UrlActTcpWritten:
			if p.rewriteUrl(fullUrl, w, r, rangeInfo, prof, f, act, speed, bodyDelay) {
				return
			}
		}

		switch bodyDelay.Act {
		case profile.DelayActDelayEach:
			fallthrough
		case profile.DelayActTimeout:
			if writeWrap == nil {
				writeWrap = w
			}

			writeWrap = newDelayWriter(bodyDelay, writeWrap, p.r)
		}

		switch speed.Act {
		case profile.SpeedActConstant:
			if writeWrap == nil {
				writeWrap = w
			}

			writeWrap = newSpeedWriter(speed, writeWrap)
		}
	}

	if needCache && r.Method == "GET" && f != nil {
		c := f.CheckCache(fullUrl, rangeInfo)
		if c != nil && c.Error == nil {
			c.Response(w, writeWrap)
			return
		}
	}

	dont302 := true
	settingContentType := "default"
	if prof != nil {
		dont302 = prof.SettingDont302(fullUrl)
		settingContentType = prof.SettingStringDef(fullUrl, "content-type", settingContentType)
		if prof.SettingSwitch(fullUrl, "disable304") {
			p.disable304FromHeader(requestR.Header)
		}
	}

	httpStart := time.Now()
	resp, postBody, redirection, err := net.NewHttp(requestUrl, requestR, p.parseDomainAsDial(target, remoteIP), dont302)
	if err != nil {
		c := cache.NewUrlCache(fullUrl, r, nil, nil, contentSource, nil, rangeInfo, httpStart, time.Now(), err)
		if f != nil {
			go p.saveContentToCache(fullUrl, f, c, false)
		}

		http.Error(w, "Bad Gateway", 502)
	} else if len(redirection) > 0 {
		http.Redirect(w, r, redirection, 302)
		if f != nil {
			f.Log("proxy " + fullUrl + " redirect " + redirection)
		}
	} else {
		defer resp.Close()
		p.procHeader(resp.Header(), settingContentType)
		content, err := resp.ProxyReturn(w, writeWrap)
		httpEnd := time.Now()
		c := cache.NewUrlCache(fullUrl, r, postBody, resp, contentSource, content, rangeInfo, httpStart, httpEnd, err)
		if f != nil {
			go p.saveContentToCache(fullUrl, f, c, needCache)
		}
	}
}
開發者ID:clarelin,項目名稱:asuran,代碼行數:101,代碼來源:proxy.go


注:本文中的github.com/benbearchen/asuran/profile.Profile.SettingDont302方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。