title: How to implement receiving a server push in OkHttp?
body: <p>Following the question <a href="https://stackoverflow.com/questions/40187251/does-okhttp-support-http-2-server-push" title="Does OkHttp support HTTP/2 server push?">Does OkHttp support HTTP/2 server push?</a>, are there any examples available on how receiving pushed content on the client side could be implemented?</p>
  
  <p>How will the interaction of OkHttpClient, Request, Response and Http2Connection be? I understand that the Http2Connection has a PushObserver, but how will it play together with OkHttpClient and Request/Response?</p>
  
  <p>Consider the snippet below. There is a client and a request. How would they come together with the PushObserver? </p>
  
  <pre><code>    OkHttpClient client = getOkHttpClient();
      Request request = new Request.Builder()
              .url("https://nghttp2.org:443") // The Http2Server should be running here.
              .build();
      try {
          Socket socket = client.socketFactory().createSocket();
          Http2Connection con = new Http2Connection.Builder(true)
              .socket(socket)
              .pushObserver(new PushObserver(){
  
              @Override
              public boolean onRequest(int streamId, List&lt;Header&gt; requestHeaders) {
                  // do something here
                  return true;
              }
  
              @Override
              public boolean onHeaders(int streamId,
                  List&lt;Header&gt; responseHeaders, boolean last) {
                  // do something here
                  return true;
              }
  
              @Override
              public boolean onData(int streamId, BufferedSource source,
                  int byteCount, boolean last) throws IOException {
                  // do something here
                  return true;
              }
  
              @Override
              public void onReset(int streamId, ErrorCode errorCode) {
                  // do something
              }
          }).build();
  
      } catch (IOException e) {
          LOG.error("IOException", e);
      }
  </code></pre>