func setContextTimeoutIfRequested()

in funcframework/framework.go [408:420]


func setContextTimeoutIfRequested(r *http.Request) (*http.Request, func()) {
	timeoutStr := os.Getenv("CLOUD_RUN_TIMEOUT_SECONDS")
	if timeoutStr == "" {
		return r, nil
	}
	timeoutSecs, err := strconv.Atoi(timeoutStr)
	if err != nil {
		fmt.Fprintf(os.Stderr, "Could not parse CLOUD_RUN_TIMEOUT_SECONDS as an integer value in seconds: %v\n", err)
		return r, nil
	}
	ctx, cancel := context.WithTimeout(r.Context(), time.Duration(timeoutSecs)*time.Second)
	return r.WithContext(ctx), cancel
}