示例#1
0
func ClientNeeded(options *common.CurlOptions) bool {
	if options.Http2Flag || options.Insecure || options.Proxy != "" || options.User != "" || len(options.Cookie) > 0 {
		return true
	}
	if len(options.AWSV2) > 0 {
		return true
	}
	if options.OnlyHasContentTypeHeader() {
		method := options.Method()
		if method != "GET" && method != "POST" {
			return true
		}
		return false
	}
	return true
}
示例#2
0
/*
	Dispatcher function of curl command
	This is an exported function and called from httpgen.
*/
func ProcessCurlCommand(options *common.CurlOptions) (string, interface{}) {

	generator := NewGoGenerator(options)

	if ClientNeeded(options) {
		return processCurlFullFeatureRequest(generator)
	}

	method := options.Method()
	onlyHasContentTypeHeader := options.OnlyHasContentTypeHeader()

	if method == "POST" && onlyHasContentTypeHeader {
		if options.ProcessedData.HasData() {
			if options.Get {
				return processCurlPostDataWithUrl(generator)
			} else if len(options.ProcessedData) == 1 && options.ProcessedData[0].UseExternalFile() {
				return processCurlPostSingleFile(generator)
			} else {
				return processCurlPostData(generator)
			}
		} else if options.ProcessedData.HasForm() {
			return processCurlPostData(generator)
		} else {
			return processCurlSimple(generator)
		}
	}

	if method == "GET" {
		if len(options.ProcessedData) > 0 {
			return processCurlGetDataWithUrl(generator)
		} else {
			return processCurlSimple(generator)
		}
	}

	if !options.ProcessedData.HasData() && !options.ProcessedData.HasForm() {
		return processCurlSimple(generator)
	}

	return "", nil
}