request: Allow User in URLs
This commit is contained in:
		
							parent
							
								
									2157b35c0b
								
							
						
					
					
						commit
						779be8b95b
					
				@ -102,20 +102,12 @@ func ReadRequest(r io.Reader) (*Request, error) {
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return nil, err
 | 
			
		||||
	}
 | 
			
		||||
	if u.User != nil {
 | 
			
		||||
		// User is not allowed
 | 
			
		||||
		return nil, ErrInvalidURL
 | 
			
		||||
	}
 | 
			
		||||
	return &Request{URL: u}, nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// Write writes a Gemini request in wire format.
 | 
			
		||||
// This method consults the request URL only.
 | 
			
		||||
func (r *Request) Write(w *bufio.Writer) error {
 | 
			
		||||
	if r.URL.User != nil {
 | 
			
		||||
		// User is not allowed
 | 
			
		||||
		return ErrInvalidURL
 | 
			
		||||
	}
 | 
			
		||||
	url := r.URL.String()
 | 
			
		||||
	if len(url) > 1024 {
 | 
			
		||||
		return ErrInvalidRequest
 | 
			
		||||
 | 
			
		||||
@ -46,14 +46,6 @@ func TestReadRequest(t *testing.T) {
 | 
			
		||||
			Raw: "gemini://example.com",
 | 
			
		||||
			Err: io.EOF,
 | 
			
		||||
		},
 | 
			
		||||
		{
 | 
			
		||||
			Raw: "gemini://user:password@example.com\r\n",
 | 
			
		||||
			Err: ErrInvalidURL,
 | 
			
		||||
		},
 | 
			
		||||
		{
 | 
			
		||||
			Raw: "https://user:password@example.net\r\n",
 | 
			
		||||
			Err: ErrInvalidURL,
 | 
			
		||||
		},
 | 
			
		||||
		{
 | 
			
		||||
			// 1030 bytes
 | 
			
		||||
			Raw: maxURL + "xxxxxx",
 | 
			
		||||
@ -121,14 +113,6 @@ func TestWriteRequest(t *testing.T) {
 | 
			
		||||
			Req: newRequest(maxURL + "x"),
 | 
			
		||||
			Err: ErrInvalidRequest,
 | 
			
		||||
		},
 | 
			
		||||
		{
 | 
			
		||||
			Req: newRequest("gemini://user:password@example.org"),
 | 
			
		||||
			Err: ErrInvalidURL,
 | 
			
		||||
		},
 | 
			
		||||
		{
 | 
			
		||||
			Req: newRequest("https://user:password@example.org"),
 | 
			
		||||
			Err: ErrInvalidURL,
 | 
			
		||||
		},
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	for _, test := range tests {
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user