@@ -44,39 +44,41 @@ object CallServerInterceptor : Interceptor {
4444 try {
4545 exchange.writeRequestHeaders(request)
4646
47- if (hasRequestBody) {
48- // If there's a "Expect: 100-continue" header on the request, wait for a "HTTP/1.1 100
49- // Continue" response before transmitting the request body. If we don't get that, return
50- // what we did get (such as a 4xx response) without ever transmitting the request body.
51- if (" 100-continue" .equals(request.header(" Expect" ), ignoreCase = true )) {
52- exchange.flushRequest()
53- responseBuilder = exchange.readResponseHeaders(expectContinue = true )
54- exchange.responseHeadersStart()
55- invokeStartEvent = false
56- }
57- if (responseBuilder == null ) {
58- if (requestBody.isDuplex()) {
59- // Prepare a duplex body so that the application can send a request body later.
47+ if (! isUpgradeRequest) {
48+ if (hasRequestBody) {
49+ // If there's a "Expect: 100-continue" header on the request, wait for a "HTTP/1.1 100
50+ // Continue" response before transmitting the request body. If we don't get that, return
51+ // what we did get (such as a 4xx response) without ever transmitting the request body.
52+ if (" 100-continue" .equals(request.header(" Expect" ), ignoreCase = true )) {
6053 exchange.flushRequest()
61- val bufferedRequestBody = exchange.createRequestBody(request, true ).buffer()
62- requestBody.writeTo(bufferedRequestBody)
54+ responseBuilder = exchange.readResponseHeaders(expectContinue = true )
55+ exchange.responseHeadersStart()
56+ invokeStartEvent = false
57+ }
58+ if (responseBuilder == null ) {
59+ if (requestBody.isDuplex()) {
60+ // Prepare a duplex body so that the application can send a request body later.
61+ exchange.flushRequest()
62+ val bufferedRequestBody = exchange.createRequestBody(request, true ).buffer()
63+ requestBody.writeTo(bufferedRequestBody)
64+ } else {
65+ // Write the request body if the "Expect: 100-continue" expectation was met.
66+ val bufferedRequestBody = exchange.createRequestBody(request, false ).buffer()
67+ requestBody.writeTo(bufferedRequestBody)
68+ bufferedRequestBody.close()
69+ }
6370 } else {
64- // Write the request body if the "Expect: 100-continue" expectation was met.
65- val bufferedRequestBody = exchange.createRequestBody(request, false ).buffer()
66- requestBody.writeTo(bufferedRequestBody)
67- bufferedRequestBody.close()
71+ exchange.noRequestBody()
72+ if (! exchange.connection.isMultiplexed) {
73+ // If the "Expect: 100-continue" expectation wasn't met, prevent the HTTP/1 connection
74+ // from being reused. Otherwise we're still obligated to transmit the request body to
75+ // leave the connection in a consistent state.
76+ exchange.noNewExchangesOnConnection()
77+ }
6878 }
6979 } else {
7080 exchange.noRequestBody()
71- if (! exchange.connection.isMultiplexed) {
72- // If the "Expect: 100-continue" expectation wasn't met, prevent the HTTP/1 connection
73- // from being reused. Otherwise we're still obligated to transmit the request body to
74- // leave the connection in a consistent state.
75- exchange.noNewExchangesOnConnection()
76- }
7781 }
78- } else if (! isUpgradeRequest) {
79- exchange.noRequestBody()
8082 }
8183
8284 if (requestBody == null || ! requestBody.isDuplex()) {
0 commit comments