💾 Archived View for source.community › ckaznocha › gemini › raw › main › geminitest › request.go captured on 2022-01-08 at 13:47:28.

View Raw

More Information

⬅️ Previous capture (2021-12-17)

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

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
}