You are an expert in writing code in many different languages. Your goal is to perform code completion for the following code, keeping in mind the rest of the code and the file meta data.
    Metadata details:
    filename: request.go
    path of file: ./repos/easegress/pkg/protocols/httpprot
    
    the code of the file until where you have to start completion: /*
 * Copyright (c) 2017, The Easegress Authors
 * All rights reserved.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except
    
func (r *Request) FetchPayload(maxPayloadSize int64) error {
	if maxPayloadSize == 0 {
		maxPayloadSize = DefaultMaxPayloadSize
	}

	stdr := r.Request

	if maxPayloadSize < 0 {
		// For an HTTP request, it is the caller's responsibility to close
		// its body, wrap it with io.NopCloser, so httpprot.Request will
		// never close it.
		r.stream = readers.NewByteCountReader(io.NopCloser(stdr.Body))
		return nil
	}

	if stdr.ContentLength > maxPayloadSize {
		return ErrRequestEntityTooLarge
	}

	if stdr.ContentLength > 0 {
		payload := make([]byte, stdr.ContentLength)
		n, err := io.ReadFull(stdr.Body, payload)
		payload = payload[:n]
		r.SetPayload(payload)
		if err == io.EOF {
			err = io.ErrUnexpectedEOF
		}
		return err
	}

	if stdr.ContentLength == 0 {
		r.SetPayload(nil)
		return nil
	}

	payload, err := io.ReadAll(io.LimitReader(stdr.Body, maxPayloadSize))
	r.SetPayload(payload)
	if err != nil {
		return err
	}

	if len(payload) < int(maxPayloadSize) {
		return nil
	}

	// try read extra bytes to check if the payload is too large.
	n, err := io.Copy(io.Discard, stdr.Body)
	if n > 0 {
		return ErrRequestEntityTooLarge
	}

	return err
}