Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove egctl auto change protocol #1162

Merged

Conversation

suchen-sci
Copy link
Contributor

@suchen-sci suchen-sci commented Dec 7, 2023

For now, egctl automatically update http protocol to https protocol is response status code is 400 and response body contains HTTPS.

This strategy can cause some additional problem. As described in #1161 , if user create/update httpserver with yamls, then easegress-server may return status code of 400 and a response body with https in it (for example, some message about tls config). In this case, egctl will try to update protocol from http to https. Then will cause error of http: server gave HTTP response to HTTPS client.

So, this pr update this protocol change strategy. https://github.com/golang/go/blob/master/src/net/http/server.go#L1922-L1929 based on golang net/http implementation.

if err := tlsConn.HandshakeContext(ctx); err != nil {
	// If the handshake failed due to the client not speaking
	// TLS, assume they're speaking plaintext HTTP and write a
	// 400 response on the TLS conn's underlying net.Conn.
	if re, ok := err.(tls.RecordHeaderError); ok && re.Conn != nil && tlsRecordHeaderLooksLikeHTTP(re.RecordHeader) {
		io.WriteString(re.Conn, "HTTP/1.0 400 Bad Request\r\n\r\nClient sent an HTTP request to an HTTPS server.\n")
		re.Conn.Close()
		return
	}
	c.server.logf("http: TLS handshake error from %s: %v", c.rwc.RemoteAddr(), err)
	return
}

@codecov-commenter
Copy link

codecov-commenter commented Dec 7, 2023

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (9e26c89) 81.18% compared to head (cc21908) 81.35%.

❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1162      +/-   ##
==========================================
+ Coverage   81.18%   81.35%   +0.17%     
==========================================
  Files         149      149              
  Lines       16946    16946              
==========================================
+ Hits        13757    13787      +30     
+ Misses       2532     2508      -24     
+ Partials      657      651       -6     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@xxx7xxxx xxx7xxxx added this pull request to the merge queue Dec 7, 2023
Merged via the queue into easegress-io:main with commit e8dc3e8 Dec 7, 2023
8 checks passed
@suchen-sci suchen-sci deleted the remove-egctl-auto-change-protocol branch December 7, 2023 08:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants