💾 Archived View for source.community › ckaznocha › gemini › raw › main › geminitest › request.go captured on 2024-05-26 at 15:09:49.

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
}