Reject schemes other than gemini:// in NewRequest
This commit is contained in:
parent
239ec885f7
commit
b84811668c
@ -18,6 +18,7 @@ var (
|
|||||||
ErrCertificateExpired = errors.New("gemini: certificate expired")
|
ErrCertificateExpired = errors.New("gemini: certificate expired")
|
||||||
ErrCertificateNotTrusted = errors.New("gemini: certificate is not trusted")
|
ErrCertificateNotTrusted = errors.New("gemini: certificate is not trusted")
|
||||||
ErrNotAFile = errors.New("gemini: not a file")
|
ErrNotAFile = errors.New("gemini: not a file")
|
||||||
|
ErrNotAGeminiURL = errors.New("gemini: not a Gemini URL")
|
||||||
ErrBodyNotAllowed = errors.New("gemini: response status code does not allow for body")
|
ErrBodyNotAllowed = errors.New("gemini: response status code does not allow for body")
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -45,6 +45,9 @@ func NewRequest(rawurl string) (*Request, error) {
|
|||||||
// NewRequestFromURL returns a new request for the given URL.
|
// NewRequestFromURL returns a new request for the given URL.
|
||||||
// The host is inferred from the URL.
|
// The host is inferred from the URL.
|
||||||
func NewRequestFromURL(url *url.URL) (*Request, error) {
|
func NewRequestFromURL(url *url.URL) (*Request, error) {
|
||||||
|
if url.Scheme != "" && url.Scheme != "gemini" {
|
||||||
|
return nil, ErrNotAGeminiURL
|
||||||
|
}
|
||||||
host := url.Host
|
host := url.Host
|
||||||
if url.Port() == "" {
|
if url.Port() == "" {
|
||||||
host += ":1965"
|
host += ":1965"
|
||||||
|
@ -29,10 +29,8 @@ func (s Status) Class() StatusClass {
|
|||||||
return StatusClass(s / 10)
|
return StatusClass(s / 10)
|
||||||
}
|
}
|
||||||
|
|
||||||
// StatusMessage returns the status message corresponding to the provided
|
// Message returns a status message corresponding to this status code.
|
||||||
// status code.
|
// It returns an empty string for input, successs, and redirect status codes.
|
||||||
// StatusMessage returns an empty string for input, successs, and redirect
|
|
||||||
// status codes.
|
|
||||||
func (s Status) Message() string {
|
func (s Status) Message() string {
|
||||||
switch s {
|
switch s {
|
||||||
case StatusTemporaryFailure:
|
case StatusTemporaryFailure:
|
||||||
|
Loading…
Reference in New Issue
Block a user