Handling Protocol Transformation

1. Converting HTTP to HTTPS

Example: HTTP→HTTPS redirect

server {
  listen 80;
  server_name api.example.com;
  return 301 https://$host$request_uri;
}
StatusWhen
301Permanent redirect
308Preserves method (POST stays POST)
HSTSTells browser to skip redirect next time

2. Configuring HTTP/1.1 to HTTP/2

FeatureHTTP/1.1HTTP/2
MultiplexingNo (1 req/conn)Yes
Header compressionNoneHPACK
Server pushNoDeprecated in Chrome
Binary framingTextBinary
Stream priorityNoYes

3. Implementing gRPC to REST Translation

Example: gRPC-Gateway annotation

service Users {
  rpc GetUser(GetUserRequest) returns (User) {
    option (google.api.http) = {
      get: "/v1/users/{id}"
    };
  }
  rpc CreateUser(User) returns (User) {
    option (google.api.http) = {
      post: "/v1/users"
      body: "*"
    };
  }
}

4. Using SOAP to REST Transformation

AspectSOAPREST
EnvelopeXML requiredNone
ActionSOAPAction headerHTTP verb + path
PayloadXML bodyJSON typically
Faults<Fault> elementHTTP status + JSON
SchemaWSDL/XSDOpenAPI/JSON Schema

5. Implementing WebSocket to HTTP

PatternUse
SSE alternativeOne-way push, plain HTTP
Long pollingLegacy clients
Webhook bridgeWS msg → POST to URL

6. Converting GraphQL to REST

GraphQLREST Equivalent
QueryGET
MutationPOST/PUT/DELETE
SubscriptionSSE / WebSocket
Field selection?fields=id,name (sparse fieldsets)

7. Using Protocol Buffer Transformation

Example: Envoy gRPC-JSON transcoder

http_filters:
- name: envoy.filters.http.grpc_json_transcoder
  typed_config:
    "@type": type.googleapis.com/envoy.extensions.filters.http.grpc_json_transcoder.v3.GrpcJsonTranscoder
    proto_descriptor: /etc/proto/api.pb
    services: ["users.UserService"]
    print_options:
      add_whitespace: false
      always_print_primitive_fields: true

8. Configuring Message Format Conversion

From → ToTool
JSON ↔ XMLjq + xmlstarlet, schema-driven
JSON ↔ Protobufprotoc reflection
JSON ↔ CSVflat structures only
JSON ↔ MsgPackBinary, schema-less

9. Implementing Custom Protocol Handlers

Example: Envoy Wasm filter skeleton

#[no_mangle]
pub fn on_http_request_headers(&mut self, _: usize) -> Action {
    if let Some(p) = self.get_http_request_header(":path") {
        if p.starts_with("/legacy/") {
            self.set_http_request_header(":path", Some(&p.replace("/legacy/", "/v2/")));
        }
    }
    Action::Continue
}

10. Setting Up Protocol Negotiation

MethodDetail
ALPNTLS-level (h2, http/1.1, h3)
Upgrade headerHTTP/1.1 → WS/h2c
Alt-SvcAdvertise HTTP/3 endpoint
Content-TypePick handler by media type