// NewTakeResponseBodyForInterceptionAsStreamArgs initializes TakeResponseBodyForInterceptionAsStreamArgs with the required arguments.
761057
func NewTakeResponseBodyForInterceptionAsStreamArgs(interceptionID InterceptionID) *TakeResponseBodyForInterceptionAsStreamArgs {
	args := new(TakeResponseBodyForInterceptionAsStreamArgs)
	args.InterceptionID = interceptionID
	return args
}
1082982
func (c *Client) handleResponseStream(resp *http.Response, ch chan *HostData) {
	reader := bufio.NewReader(resp.Body)

	for {
		banner := new(HostData)
		chunk, err := reader.ReadBytes('\n')
		if err != nil {
			resp.Body.Close()
			close(ch)
			break
		}

		chunk = bytes.TrimRight(chunk, "\n\r")
		if len(chunk) == 0 {
			continue
		}

		if err := c.parseResponse(banner, bytes.NewBuffer(chunk)); err != nil {
			resp.Body.Close()
			close(ch)
			break
		}

		ch <- banner
	}
}
89076
func HttpRequestHandler(requestHeader RequestHeader, requestBody interface{}, responseDTO interface{}) (*http.Response, apihelper.ApiErrors) {
	req, err := http.NewRequest(requestHeader.Method, requestHeader.URL, encodeRequestBody(requestBody))
	req.Header.Set("Content-Type", requestHeader.ContentType)
	req.Header.Set("Authorization", requestHeader.Authorization)

	client := &http.Client{}
	resp, err := client.Do(req)
	if err != nil {
		panic(err)
	}

	// read response
	body, _ := ioutil.ReadAll(resp.Body)

	var apiErrors apihelper.ApiErrors
	json.Unmarshal(body, &responseDTO)
	json.Unmarshal(body, &apiErrors)

	if len(apiErrors.Errors) > 0 {
		pretty.Println(apiErrors.Errors)
	}

	return resp, apiErrors
}
376438
func (d *domainClient) CloseTarget(ctx context.Context, args *CloseTargetArgs) (reply *CloseTargetReply, err error) {
	reply = new(CloseTargetReply)
	if args != nil {
		err = rpcc.Invoke(ctx, "Target.closeTarget", args, reply, d.conn)
	} else {
		err = rpcc.Invoke(ctx, "Target.closeTarget", nil, reply, d.conn)
	}
	if err != nil {
		err = &internal.OpError{Domain: "Target", Op: "CloseTarget", Err: err}
	}
	return
}
1175647
func (c *Client) GetBodyOfHTTPResponse(u *url.URL) ([]byte, error) {
	resp, err := c.GetHTTPResponse(u)
	if err != nil {
		return []byte{}, err
	}
	defer resp.Body.Close()

	body, err := ioutil.ReadAll(resp.Body)

	return body, err
}
1212325
func RestHandleResponse(context *gin.Context, body interface{}, err error) {
	if err == nil {
		context.JSON(200, body)
	} else {
		context.String(400, err.Error())
	}
}
997586
func NewRequestBodyOrReference(in interface{}, context *compiler.Context) (*RequestBodyOrReference, error) {
	errors := make([]error, 0)
	x := &RequestBodyOrReference{}
	matched := false
	// RequestBody request_body = 1;
	{
		m, ok := compiler.UnpackMap(in)
		if ok {
			// errors might be ok here, they mean we just don't have the right subtype
			t, matchingError := NewRequestBody(m, compiler.NewContext("requestBody", context))
			if matchingError == nil {
				x.Oneof = &RequestBodyOrReference_RequestBody{RequestBody: t}
				matched = true
			} else {
				errors = append(errors, matchingError)
			}
		}
	}
	// Reference reference = 2;
	{
		m, ok := compiler.UnpackMap(in)
		if ok {
			// errors might be ok here, they mean we just don't have the right subtype
			t, matchingError := NewReference(m, compiler.NewContext("reference", context))
			if matchingError == nil {
				x.Oneof = &RequestBodyOrReference_Reference{Reference: t}
				matched = true
			} else {
				errors = append(errors, matchingError)
			}
		}
	}
	if matched {
		// since the oneof matched one of its possibilities, discard any matching errors
		errors = make([]error, 0)
	}
	return x, compiler.NewErrorGroupOrNil(errors)
}
742808
func (v *Error) ErrorBody() string {
	var s string
	switch v.Type {
	case ErrorTypeRequired, ErrorTypeForbidden, ErrorTypeTooLong, ErrorTypeInternal:
		s = v.Type.String()
	default:
		value := v.BadValue
		valueType := reflect.TypeOf(value)
		if value == nil || valueType == nil {
			value = "null"
		} else if valueType.Kind() == reflect.Ptr {
			if reflectValue := reflect.ValueOf(value); reflectValue.IsNil() {
				value = "null"
			} else {
				value = reflectValue.Elem().Interface()
			}
		}
		switch t := value.(type) {
		case int64, int32, float64, float32, bool:
			// use simple printer for simple types
			s = fmt.Sprintf("%s: %v", v.Type, value)
		case string:
			s = fmt.Sprintf("%s: %q", v.Type, t)
		case fmt.Stringer:
			// anything that defines String() is better than raw struct
			s = fmt.Sprintf("%s: %s", v.Type, t.String())
		default:
			// fallback to raw struct
			// TODO: internal types have panic guards against json.Marshalling to prevent
			// accidental use of internal types in external serialized form.  For now, use
			// %#v, although it would be better to show a more expressive output in the future
			s = fmt.Sprintf("%s: %#v", v.Type, value)
		}
	}
	if len(v.Detail) != 0 {
		s += fmt.Sprintf(": %s", v.Detail)
	}
	return s
}
69028
func (c *HeapProfiler) StartTrackingHeapObjectsWithParams(v *HeapProfilerStartTrackingHeapObjectsParams) (*gcdmessage.ChromeResponse, error) {
	return gcdmessage.SendDefaultRequest(c.target, c.target.GetSendCh(), &gcdmessage.ParamRequest{Id: c.target.GetId(), Method: "HeapProfiler.startTrackingHeapObjects", Params: v})
}
992213
func NewTarget(targetName, targetPath string, targetCustom *canonicaljson.RawMessage) (*Target, error) {
	b, err := ioutil.ReadFile(targetPath)
	if err != nil {
		return nil, err
	}

	meta, err := data.NewFileMeta(bytes.NewBuffer(b), data.NotaryDefaultHashes...)
	if err != nil {
		return nil, err
	}

	return &Target{Name: targetName, Hashes: meta.Hashes, Length: meta.Length, Custom: targetCustom}, nil
}
770367
func (a *AuthServerCodec) WriteResponse(r *rpc.Response, body interface{}) error {
	// We do need a lock here, because the ServerCodec interface specifies
	//  that WriteResponse must be safe for concurrent use by multiple goroutines
	a.wBuffMutex.Lock()
	defer a.wBuffMutex.Unlock()

	a.buff.WriteBuff.Reset()

	// Let the underlying codec write the response to the buffer
	if err := a.wrappedcodec.WriteResponse(r, body); err != nil {
		return err
	}

	// Get the response from the buffer and write it to the actual connection
	response := a.buff.WriteBuff.Bytes()
	if err := auth.WriteLengthAndBytes(response, a.conn); err != nil {
		return err
	}

	return nil
}
1250370
func WriteTextResponse(w http.ResponseWriter, status int, body string) {
	w.Header().Set("Content-Type", "text/plain; charset=utf-8")
	w.Header().Set("X-Content-Type-Options", "nosniff")
	w.WriteHeader(status)
	w.Write([]byte(body))
}
475047
func errorBody(err error, stack Stack) map[string]interface{} {
	message := nilErrTitle
	if err != nil {
		message = err.Error()
	}

	errBody := map[string]interface{}{
		"trace": map[string]interface{}{
			"frames": stack,
			"exception": map[string]interface{}{
				"class":   errorClass(err),
				"message": message,
			},
		},
	}
	return errBody
}
718844
func NewTokenFromOAuth1Arg(Oauth1Token string, Oauth1TokenSecret string) *TokenFromOAuth1Arg {
	s := new(TokenFromOAuth1Arg)
	s.Oauth1Token = Oauth1Token
	s.Oauth1TokenSecret = Oauth1TokenSecret
	return s
}
783554
func (slc *HttpClient) CheckForHttpResponseErrorsSilently(data []byte) error {
	var decodedResponse map[string]interface{}
	parseErr := json.Unmarshal(data, &decodedResponse)
	if parseErr == nil {
		return slc.HasErrors(decodedResponse)
	}

	return nil
}
1195932
func ResponseMapper() MiddlewareFunc {
	return func(b *Bubble) error {
		err := b.Next()

		// first, error handling
		if err != nil {
			return b.writeErrorObject(err)
		}

		// second, error from handlers
		for idx := len(b.Returns) - 1; 0 <= idx; idx-- {
			rv := b.Returns[idx]
			if rv.Type().AssignableTo(errorType) && !rv.IsNil() {
				err := rv.Interface().(error)
				return b.writeErrorObject(err)
			}
		}

		// last, write payload
		for _, rv := range b.Returns {
			if rv.Type().AssignableTo(errorType) {
				continue
			}

			v := rv.Interface()
			if m, ok := v.(HTTPResponseModifier); ok {
				return m.Handle(b)
			} else if !rv.IsNil() {
				var resp []byte
				var err error
				if b.Debug {
					resp, err = json.MarshalIndent(v, "", "  ")
				} else {
					resp, err = json.Marshal(v)
				}
				if err != nil {
					http.Error(b.W, err.Error(), http.StatusInternalServerError)
					return err
				}
				b.W.Header().Set("Content-Type", "application/json; charset=UTF-8")
				b.W.WriteHeader(http.StatusOK)
				b.W.Write(resp)
				return nil
			} else {
				b.W.Header().Set("Content-Type", "application/json; charset=UTF-8")
				b.W.WriteHeader(http.StatusOK)
				if rv.Type().Kind() == reflect.Slice {
					b.W.Write([]byte("[]"))
				} else {
					b.W.Write([]byte("{}"))
				}
				return nil
			}
		}

		return nil
	}
}
749315
func (c *Network) GetResponseBodyWithParams(v *NetworkGetResponseBodyParams) (string, bool, error) {
	resp, err := gcdmessage.SendCustomReturn(c.target, c.target.GetSendCh(), &gcdmessage.ParamRequest{Id: c.target.GetId(), Method: "Network.getResponseBody", Params: v})
	if err != nil {
		return "", false, err
	}

	var chromeData struct {
		Result struct {
			Body          string
			Base64Encoded bool
		}
	}

	if resp == nil {
		return "", false, &gcdmessage.ChromeEmptyResponseErr{}
	}

	// test if error first
	cerr := &gcdmessage.ChromeErrorResponse{}
	json.Unmarshal(resp.Data, cerr)
	if cerr != nil && cerr.Error != nil {
		return "", false, &gcdmessage.ChromeRequestErr{Resp: cerr}
	}

	if err := json.Unmarshal(resp.Data, &chromeData); err != nil {
		return "", false, err
	}

	return chromeData.Result.Body, chromeData.Result.Base64Encoded, nil
}