💾 Archived View for source.community › ckaznocha › gemini › raw › main › geminitest › request.go captured on 2021-12-17 at 13:26:06.

View Raw

More Information

-=-=-=-=-=-=-

package geminitest

import (
	"bufio"
	"strings"

	"source.community/ckaznocha/gemini"
)

// NewRequest returns a Reqaust for use in tests.
func NewRequest(target string) *gemini.Request {
	req, err := gemini.ReadRequest(bufio.NewReader(strings.NewReader(target + "\r\n")))
	if err != nil {
		panic("invalid NewRequest arguments; " + err.Error())
	}

	req.RemoteAddr = "192.0.2.1:1234"

	if req.URI.Host == "" {
		req.URI.Host = "example.com"
	}

	return req
}