//Sends Http GET request to url. Unmarshalling response to the target object.
//Returns error and response code.
//Error returned if non 200 code was returned or unmarshal error occurred.
176476
func (h *Http) GetJson(urlStr string, target interface{}) (error, int) {
	if target == nil {
		return errors.New("Target interface must be specified."), -1
	}

	req := &http.Request{
		Method: "GET",
	}

	resp, err := h.executeRequest(urlStr, req)
	if err != nil {
		statusCode := -1
		if resp != nil {
			statusCode = resp.StatusCode
		}
		return err, statusCode
	}

	defer resp.Body.Close()
	jsonData, err := ioutil.ReadAll(resp.Body)

	logResponse(urlStr, resp, jsonData)

	if resp.StatusCode != http.StatusOK {
		return errors.New(fmt.Sprintf("Expected code %d but got %d,\n response: [%s]",
			http.StatusOK, resp.StatusCode, string(jsonData))), resp.StatusCode
	}

	if err != nil {
		return err, resp.StatusCode
	}

	err = json.Unmarshal(jsonData, target)

	if err != nil {
		return err, resp.StatusCode
	}
	return nil, resp.StatusCode
}
888121
func (c *Client) get(url string) (string, error) {
	resp, err := http.Get(url)
	if err != nil {
		return "", err
	}
	defer resp.Body.Close()

	taskList := new(TaskList)
	if err = json.NewDecoder(resp.Body).Decode(taskList); err != nil {
		return "", err
	}
	return strings.Join(taskList.Tasks, ", "), nil
}
245280
func (e *httpError) UnmarshalJSON(data []byte) error {
	e.goof = newGoof("", nil)
	if err := e.goof.UnmarshalJSON(data); err != nil {
		return err
	}
	if v, ok := e.data["status"].(float64); ok {
		e.data["status"] = int(v)
	}
	return nil
}
196936
func (c *Client) GetHTTPResponse(u *url.URL) (*http.Response, error) {
	resp, err := c.HTTP.Get(u.String())

	if err != nil {
		return nil, err
	}

	return resp, nil
}
108806
func HTTPRequest(url string, method string, body io.Reader, headers map[string]string, failOnError bool) (*HTTPResponse, error) {
	c := &HTTPRequestConfig{
		URL:            url,
		Method:         method,
		Body:           body,
		Headers:        headers,
		FailOnError:    failOnError,
		TimeoutSeconds: 30,
	}
	return HTTPComplexRequest(c)
}
1123052
func get(url string) ([]byte, string) {
	resp, err := http.Get(url)
	if err != nil {
		log.Fatal("Error getting url.")
	}
	defer resp.Body.Close()
	body, err := ioutil.ReadAll(resp.Body)
	ct := resp.Header.Get("Content-Type")

	if resp.StatusCode == 200 && len(body) > 512 {
		return body, ct
	}

	if DefaultImage() == "" {
		return []byte(""), ct
	}

	if url == DefaultImage() {
		panic("Catching an infinite loop! Default Image doesn't exist or is broken. Please rectify!")
	}

	return get(DefaultImage())
}
915196
func (c *Client) SimpleGet(target string) (*http.Response, error) {
	// We parse the URL and then convert it right back to a string
	// later; this just acts as a check that Fastly isn't sending
	// us nonsense.
	url, err := url.Parse(target)
	if err != nil {
		return nil, err
	}

	request, err := http.NewRequest("GET", url.String(), nil)
	if err != nil {
		return nil, err
	}

	if len(c.apiKey) > 0 {
		request.Header.Set(APIKeyHeader, c.apiKey)
	}
	request.Header.Set("User-Agent", UserAgent)

	resp, err := checkResp(c.HTTPClient.Do(request))
	if err != nil {
		return resp, err
	}
	return resp, nil
}
236370
func (bow *Browser) httpGET(u *url.URL, ref *url.URL) error {
	req, err := bow.buildRequest("GET", u.String(), ref, nil)
	if err != nil {
		return err
	}
	return bow.httpRequest(req)
}
169346
func (c *Client) Get(URI string, decoded interface{}) (*http.Response, error) {
	req, err := c.NewJSONRequest("GET", URI, nil)
	if err != nil {
		return nil, err
	}
	resp, err := c.DoRest(req, decoded)
	if err != nil {
		return nil, err
	}
	if resp.StatusCode != http.StatusOK {
		return nil, fmt.Errorf("Unexpected http code %d on URL %v. expecting %d", resp.StatusCode, resp.Request.URL, http.StatusOK)
	}
	return resp, err
}
938593
func (c *Client) request(params *url.Values, v *Response) error {
	var body string
	if params != nil {
		body = params.Encode()
	}

	method := "GET"
	requestURL := fmt.Sprintf("%v/?%s", c.BaseURL, body)
	var requestBody io.Reader
	if c.UsePost {
		method = "POST"
		requestURL = c.BaseURL.String()
		requestBody = strings.NewReader(body)
	}
	request, err := http.NewRequest(method, requestURL, requestBody)
	if err != nil {
		return err
	}

	log.Debugf("HTTP REQUEST: %s %s %s", method, requestURL, body)

	if c.UsePost {
		request.Header.Set("Content-Type", "application/x-www-form-urlencoded")
	}
	request.Header.Add("Accept", "application/json")
	request.Header.Add("User-Agent", "LinodeGo/"+ClientVersion+" Go/"+runtime.Version())

	response, err := c.HTTPClient.Do(request)
	if err != nil {
		log.Errorf("Failed to get API response: %v", err)
		return err
	}

	defer response.Body.Close()

	responseBody, err := ioutil.ReadAll(response.Body)
	if err != nil {
		log.Errorf("Failed to parse API response: %v", err)
		return err
	}

	log.Debugf("HTTP RESPONSE: %s", string(responseBody))

	// Status code 500 is a server error and means nothing can be done at this point.
	if response.StatusCode != 200 {
		return ErrUnexpectedResponse
	}

	if err = json.Unmarshal(responseBody, v); err != nil {
		return err
	}

	if len(v.Errors) > 0 {
		if v.Errors[0].ErrorCode == 4 {
			return ErrAuthentication
		}
		// Need to return all errors to client. Perhaps wrap the error structure as a property for a custom error class
		return errors.New(fmt.Sprintf("API Error: %s, Code %d", v.Errors[0].ErrorMessage, v.Errors[0].ErrorCode))
	}

	return nil
}
369138
func (h *HTTPBin) Get(w http.ResponseWriter, r *http.Request) {
	resp := &getResponse{
		Args:    r.URL.Query(),
		Headers: getRequestHeaders(r),
		Origin:  getOrigin(r),
		URL:     getURL(r).String(),
	}
	body, _ := json.Marshal(resp)
	writeJSON(w, body, http.StatusOK)
}
794928
func Get(ctx context.Context, requester Requester, r GetRequest) error {
	req, err := http.NewRequest("GET", r.URL, nil)
	if err != nil {
		return err
	}

	resp, err := requester(ctx, req)
	if err != nil {
		return err
	}
	_, err = ioutil.ReadAll(resp.Body)
	if err != nil {
		return err
	}
	resp.Body.Close()

	return nil
}
672794
func (f *Request) Get(url string) *Request {
	f.Url(url).Method("GET")
	return f
}
710809
func (l *Client) Get(endpoint string, params url.Values, body interface{}, response, data interface{}) error {
	method := "GET"

	// get the formatted endpoint url
	path, err := l.PrepUrl(endpoint, params, false)
	if err != nil {
		return err
	}

	payload, err := prepRequestBody(body)
	if err != nil {
		return err
	}

	// build the request
	r, _ := http.NewRequest(method, path, payload)

	// execute the request
	err = l.Do(r, response, data)
	if err != nil {
		return err
	}

	return nil
}
1149914
func UnmarshalError(r *request.Request) {
	defer r.HTTPResponse.Body.Close()

	bodyBytes, err := ioutil.ReadAll(r.HTTPResponse.Body)
	if err != nil {
		r.Error = awserr.NewRequestFailure(
			awserr.New("SerializationError", "failed to read from query HTTP response body", err),
			r.HTTPResponse.StatusCode,
			r.RequestID,
		)
		return
	}

	// First check for specific error
	resp := xmlErrorResponse{}
	decodeErr := xml.Unmarshal(bodyBytes, &resp)
	if decodeErr == nil {
		reqID := resp.RequestID
		if reqID == "" {
			reqID = r.RequestID
		}
		r.Error = awserr.NewRequestFailure(
			awserr.New(resp.Code, resp.Message, nil),
			r.HTTPResponse.StatusCode,
			reqID,
		)
		return
	}

	// Check for unhandled error
	servUnavailResp := xmlServiceUnavailableResponse{}
	unavailErr := xml.Unmarshal(bodyBytes, &servUnavailResp)
	if unavailErr == nil {
		r.Error = awserr.NewRequestFailure(
			awserr.New("ServiceUnavailableException", "service is unavailable", nil),
			r.HTTPResponse.StatusCode,
			r.RequestID,
		)
		return
	}

	// Failed to retrieve any error message from the response body
	r.Error = awserr.NewRequestFailure(
		awserr.New("SerializationError",
			"failed to decode query XML error response", decodeErr),
		r.HTTPResponse.StatusCode,
		r.RequestID,
	)
}
1332621
func (c *Client) doHTTPGet(url string, data url.Values) (*http.Response, error) {
	if data != nil {
		url = url + "?" + data.Encode()
	}
	req, err := http.NewRequest("GET", url, nil)
	if err != nil {
		return nil, err
	}

	return c.doHTTP(req)
}
48530
func (de *DefaultExtender) RequestGet(ctx *URLContext, headRes *http.Response) bool {
	return headRes.StatusCode >= 200 && headRes.StatusCode < 300
}