Skip to content

Commit

Permalink
Fix missing HTTP/1.0 proto enums
Browse files Browse the repository at this point in the history
  • Loading branch information
dstotijn committed Feb 27, 2022
1 parent c5f76e1 commit 8269af9
Show file tree
Hide file tree
Showing 9 changed files with 40 additions and 28 deletions.
12 changes: 7 additions & 5 deletions admin/src/features/sender/components/EditRequest.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,15 @@ enum HttpMethod {
}

enum HttpProto {
Http1 = "HTTP/1.1",
Http2 = "HTTP/2.0",
Http10 = "HTTP/1.0",
Http11 = "HTTP/1.1",
Http20 = "HTTP/2.0",
}

const httpProtoMap = new Map([
[HttpProto.Http1, HttpProtocol.Http1],
[HttpProto.Http2, HttpProtocol.Http2],
[HttpProto.Http10, HttpProtocol.Http10],
[HttpProto.Http11, HttpProtocol.Http11],
[HttpProto.Http20, HttpProtocol.Http20],
]);

function updateKeyPairItem(key: string, value: string, idx: number, items: KeyValuePair[]): KeyValuePair[] {
Expand Down Expand Up @@ -92,7 +94,7 @@ function EditRequest(): JSX.Element {

const [method, setMethod] = useState(HttpMethod.Get);
const [url, setURL] = useState("");
const [proto, setProto] = useState(HttpProto.Http2);
const [proto, setProto] = useState(HttpProto.Http20);
const [queryParams, setQueryParams] = useState<KeyValuePair[]>([{ key: "", value: "" }]);
const [headers, setHeaders] = useState<KeyValuePair[]>([{ key: "", value: "" }]);
const [body, setBody] = useState("");
Expand Down
6 changes: 4 additions & 2 deletions admin/src/lib/components/ResponseStatus.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,11 @@ type ResponseStatusProps = {

function mapProto(proto: HttpProtocol): string {
switch (proto) {
case HttpProtocol.Http1:
case HttpProtocol.Http10:
return "HTTP/1.0";
case HttpProtocol.Http11:
return "HTTP/1.1";
case HttpProtocol.Http2:
case HttpProtocol.Http20:
return "HTTP/2.0";
default:
return proto;
Expand Down
5 changes: 3 additions & 2 deletions admin/src/lib/graphql/generated.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,9 @@ export enum HttpMethod {
}

export enum HttpProtocol {
Http1 = 'HTTP1',
Http2 = 'HTTP2'
Http10 = 'HTTP10',
Http11 = 'HTTP11',
Http20 = 'HTTP20'
}

export type HttpRequestLog = {
Expand Down
5 changes: 3 additions & 2 deletions pkg/api/generated.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 7 additions & 5 deletions pkg/api/models_gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 6 additions & 4 deletions pkg/api/resolvers.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,15 @@ import (
)

var httpProtocolMap = map[string]HTTPProtocol{
sender.HTTPProto1: HTTPProtocolHTTP1,
sender.HTTPProto2: HTTPProtocolHTTP2,
sender.HTTPProto10: HTTPProtocolHTTP10,
sender.HTTPProto11: HTTPProtocolHTTP11,
sender.HTTPProto20: HTTPProtocolHTTP20,
}

var revHTTPProtocolMap = map[HTTPProtocol]string{
HTTPProtocolHTTP1: sender.HTTPProto1,
HTTPProtocolHTTP2: sender.HTTPProto2,
HTTPProtocolHTTP10: sender.HTTPProto10,
HTTPProtocolHTTP11: sender.HTTPProto11,
HTTPProtocolHTTP20: sender.HTTPProto20,
}

type Resolver struct {
Expand Down
5 changes: 3 additions & 2 deletions pkg/api/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -157,8 +157,9 @@ enum HttpMethod {
}

enum HttpProtocol {
HTTP1
HTTP2
HTTP10
HTTP11
HTTP20
}

scalar Time
Expand Down
4 changes: 2 additions & 2 deletions pkg/sender/sender.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ func (svc *service) CreateOrUpdateRequest(ctx context.Context, req Request) (Req
}

if req.Proto == "" {
req.Proto = HTTPProto2
req.Proto = HTTPProto20
}

if !isValidProto(req.Proto) {
Expand Down Expand Up @@ -157,7 +157,7 @@ func (svc *service) CloneFromRequestLog(ctx context.Context, reqLogID ulid.ULID)
SourceRequestLogID: reqLogID,
Method: reqLog.Method,
URL: reqLog.URL,
Proto: HTTPProto2, // Attempt HTTP/2.
Proto: HTTPProto20, // Attempt HTTP/2.
Header: reqLog.Header,
Body: reqLog.Body,
}
Expand Down
9 changes: 5 additions & 4 deletions pkg/sender/transport.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@ type HTTPTransport struct{}
type protoCtxKey struct{}

const (
HTTPProto1 = "HTTP/1.1"
HTTPProto2 = "HTTP/2.0"
HTTPProto10 = "HTTP/1.0"
HTTPProto11 = "HTTP/1.1"
HTTPProto20 = "HTTP/2.0"
)

// h1OnlyTransport mimics `http.DefaultTransport`, but with HTTP/2 disabled.
Expand All @@ -38,13 +39,13 @@ var h1OnlyTransport = &http.Transport{
func (t *HTTPTransport) RoundTrip(req *http.Request) (*http.Response, error) {
proto, ok := req.Context().Value(protoCtxKey{}).(string)

if ok && proto == HTTPProto1 {
if ok && proto == HTTPProto10 || proto == HTTPProto11 {
return h1OnlyTransport.RoundTrip(req)
}

return http.DefaultTransport.RoundTrip(req)
}

func isValidProto(proto string) bool {
return proto == HTTPProto1 || proto == HTTPProto2
return proto == HTTPProto10 || proto == HTTPProto11 || proto == HTTPProto20
}

0 comments on commit 8269af9

Please sign in to comment.