[{"id":"websocketsbeginner-001","courseId":"websockets-beginner","domain":"opening-handshake","topic":"WebSocket URL schemes","prompt":"A teammate's app connects to ws://chat.example.com/room. They want the connection to count as secure. Which URI should the app use instead?","hint":"The secure flag depends on one part of the URI. Look at the scheme.","explain":"A WebSocket URI starts with a scheme, and that part alone decides whether the connection counts as secure. Ports and query strings are other parts of the address and do not set that flag.","source":"https://www.rfc-editor.org/rfc/rfc6455#section-3","interaction":{"type":"single"},"options":[{"id":"a","text":"wss://chat.example.com/room","why":"The wss scheme is the secure form of a WebSocket URI, and matching it sets the secure flag."},{"id":"b","text":"ws://chat.example.com:443/room","whyNot":"Port 443 is the default port for wss, but the port does not set the secure flag; the scheme does."},{"id":"c","text":"https://chat.example.com/room","whyNot":"https is an HTTP scheme; WebSocket URIs are defined with only the ws and wss schemes."},{"id":"d","text":"ws://chat.example.com/room?secure=true","whyNot":"A query component is not the secure flag; the flag is set only when the scheme matches wss."}],"answer":"a","explanation":"A WebSocket URI uses one of two schemes, ws or wss. The secure flag is set when the scheme component matches wss, compared case-insensitively.","concept":"A WebSocket URI uses one of two schemes, ws or wss. The secure flag is set when the scheme component matches wss, compared case-insensitively.","rev":1,"updatedAt":"2026-10-26","kind":"scenario","takeaways":["Security for a WebSocket URI comes from its scheme, wss, not from its port or query."]},{"id":"websocketsbeginner-002","courseId":"websockets-beginner","domain":"opening-handshake","topic":"Default ports for ws and wss","prompt":"The WebSocket URI ws://feed.example.com/prices leaves out its port, so the client connects to port 443, the same default as wss://.","hint":"Compare the default port that each of the two schemes uses.","explain":"A URI can leave out its port, and the client then uses a default. Each scheme defines its own default port, so the answer depends on the specific defaults the schemes set.","source":"https://www.rfc-editor.org/rfc/rfc6455#section-3","interaction":{"type":"true-false"},"options":[{"id":"a","text":"True","whyNot":"ws and wss have different defaults: ws uses port 80 and wss uses port 443."},{"id":"b","text":"False","why":"A ws:// URI without a port uses port 80; port 443 is the default only for wss://."}],"answer":"b","explanation":"The port component of a WebSocket URI is optional. The default is port 80 for ws and port 443 for wss.","concept":"The port component of a WebSocket URI is optional. The default is port 80 for ws and port 443 for wss.","rev":1,"updatedAt":"2026-10-26","kind":"scenario","takeaways":["ws defaults to port 80 and wss defaults to port 443 when the port is left out."]},{"id":"websocketsbeginner-003","courseId":"websockets-beginner","domain":"opening-handshake","topic":"Upgrade request header","prompt":"A client builds a WebSocket handshake by hand over an HTTP/1.1 connection. Which TWO headers ask the server to switch to the WebSocket protocol?","hint":"Two headers work as a pair: one names the target protocol, and the other flags this as a hop-level request.","explain":"An HTTP request can invite a server to change protocol, through a header like any other. Some headers apply to a single network hop only, and a request carrying one must mark it that way.","source":"https://developer.mozilla.org/en-US/docs/Web/HTTP/Guides/Protocol_upgrade_mechanism","interaction":{"type":"multiple","tellCount":true},"options":[{"id":"a","text":"Connection: Upgrade","why":"Upgrade is a hop-by-hop header, so it must be listed in the Connection header; this is one of the two required headers."},{"id":"b","text":"Upgrade: websocket","why":"The Upgrade header names the protocol the client wants to switch to, here websocket."},{"id":"c","text":"Upgrade: HTTP/2.0","whyNot":"The upgrade mechanism is specific to HTTP/1.1, and HTTP/2 explicitly disallows it."},{"id":"d","text":"Connection: keep-alive","whyNot":"keep-alive does not ask for a protocol change; the Connection header must list upgrade for one to happen."},{"id":"e","text":"Cookie: session=abc123","whyNot":"Cookies are common headers that may be present but do not pertain to the WebSocket, so they do not ask for an upgrade."},{"id":"f","text":"Sec-WebSocket-Extensions listing at least one extension","whyNot":"Extensions are optional; asking for them does not trigger the switch to the WebSocket protocol."}],"answer":"ab","explanation":"To request a WebSocket upgrade over HTTP/1.1, the client sends Upgrade: websocket together with Connection: Upgrade, because Upgrade is hop-by-hop.","concept":"To request a WebSocket upgrade over HTTP/1.1, the client sends Upgrade: websocket together with Connection: Upgrade, because Upgrade is hop-by-hop.","rev":1,"updatedAt":"2026-10-26","kind":"scenario","takeaways":["A WebSocket upgrade request needs both Upgrade and Connection: Upgrade."]},{"id":"websocketsbeginner-004","courseId":"websockets-beginner","domain":"opening-handshake","topic":"Sec-WebSocket-Key header","prompt":"A browser opens a WebSocket, and its handshake request carries a Sec-WebSocket-Key header. What is that header for?","hint":"Ask what the header is meant to prevent, and how much protection it offers.","explain":"Some headers exist only to confirm what a sender intends, not to prove who it is or to hide anything. A value built by a fixed rule gives no secrecy, and the browser fills some headers in on its own.","source":"https://www.rfc-editor.org/rfc/rfc6455#section-4.1","interaction":{"type":"single"},"options":[{"id":"a","text":"A check that the client really means to open a WebSocket, with no real security","why":"It helps stop non-WebSocket clients from requesting an upgrade by mistake, but it is not a security feature."},{"id":"b","text":"Strong proof of identity, so the server knows which user is connecting","whyNot":"The key does not provide security, and it is not a login or identity proof."},{"id":"c","text":"A key the browser uses to encrypt every frame that follows","whyNot":"The key is not used for encryption; it is a computed value that confirms a WebSocket request is intended."},{"id":"d","text":"A value a page script can set with fetch() to customise the handshake","whyNot":"The browser adds this header automatically; fetch() and XMLHttpRequest.setRequestHeader() cannot add it."}],"answer":"a","explanation":"Clients that use Sec-WebSocket-Key add it automatically. It helps confirm that a WebSocket upgrade is intended, but it provides no security.","concept":"Clients that use Sec-WebSocket-Key add it automatically. It helps confirm that a WebSocket upgrade is intended, but it provides no security.","rev":1,"updatedAt":"2026-10-26","kind":"scenario","takeaways":["Sec-WebSocket-Key confirms intent to upgrade; it is not authentication or encryption."]},{"id":"websocketsbeginner-005","courseId":"websockets-beginner","domain":"opening-handshake","topic":"Sec-WebSocket-Version header","prompt":"A client sends Sec-WebSocket-Version: 13, and the server does not support that version. The server should reply with a Sec-WebSocket-Version header listing the versions it does understand.","hint":"Think about what the server sends back when it cannot match the version the client asked for.","explain":"Both ends of a handshake must agree on a version before any frames flow. Consider what a server should tell the client when it cannot speak the version the client asked for.","source":"https://www.rfc-editor.org/rfc/rfc6455#section-4.1","interaction":{"type":"true-false"},"options":[{"id":"a","text":"True","why":"The server should send this header back, listing the version or versions it does understand."},{"id":"b","text":"False","whyNot":"A server that does not understand the requested version is supposed to reply with this header, not stay silent."}],"answer":"a","explanation":"If a server does not understand the WebSocket version a client requested, it should send a Sec-WebSocket-Version header listing the versions it does understand.","concept":"If a server does not understand the WebSocket version a client requested, it should send a Sec-WebSocket-Version header listing the versions it does understand.","rev":1,"updatedAt":"2026-10-26","kind":"scenario","takeaways":["Version negotiation uses Sec-WebSocket-Version: the client names one, and the server lists what it supports."]}]