- Add Context.set_mode method
- Add MODE_RELEASE_BUFFERS and OP_NO_COMPRESSION constants, only if are defined (openssl >= 1.0.0)
diff --git a/OpenSSL/ssl/context.c b/OpenSSL/ssl/context.c
index c2bdcab..4ab024f 100644
--- a/OpenSSL/ssl/context.c
+++ b/OpenSSL/ssl/context.c
@@ -1108,6 +1108,23 @@
     return PyLong_FromLong(SSL_CTX_set_options(self->ctx, options));
 }
 
+static char ssl_Context_set_mode_doc[] = "\n\
+Add modes via bitmask. Modes set before are not cleared!\n\
+\n\
+@param mode: The mode to add.\n\
+@return: The new mode bitmask.\n\
+";
+static PyObject *
+ssl_Context_set_mode(ssl_ContextObj *self, PyObject *args)
+{
+    long mode;
+
+    if (!PyArg_ParseTuple(args, "l:set_mode", &mode))
+        return NULL;
+
+    return PyLong_FromLong(SSL_CTX_set_mode(self->ctx, mode));
+}
+
 static char ssl_Context_set_tlsext_servername_callback_doc[] = "\n\
 Specify a callback function to be called when clients specify a server name.\n\
 \n\
@@ -1174,6 +1191,7 @@
     ADD_METHOD(set_app_data),
     ADD_METHOD(get_cert_store),
     ADD_METHOD(set_options),
+    ADD_METHOD(set_mode),
     ADD_METHOD(set_tlsext_servername_callback),
     { NULL, NULL }
 };
diff --git a/OpenSSL/ssl/ssl.c b/OpenSSL/ssl/ssl.c
index 0dd9871..ce84041 100644
--- a/OpenSSL/ssl/ssl.c
+++ b/OpenSSL/ssl/ssl.c
@@ -224,6 +224,10 @@
     PyModule_AddIntConstant(module, "OP_NETSCAPE_CA_DN_BUG", SSL_OP_NETSCAPE_CA_DN_BUG);
     PyModule_AddIntConstant(module, "OP_NETSCAPE_DEMO_CIPHER_CHANGE_BUG", SSL_OP_NETSCAPE_DEMO_CIPHER_CHANGE_BUG);
 
+#ifdef SSL_OP_NO_COMPRESSION
+    PyModule_AddIntConstant(module, "OP_NO_COMPRESSION", SSL_OP_NO_COMPRESSION);
+#endif
+
     /* DTLS related options.  The first two of these were introduced in
      * 2005, the third in 2007.  To accomodate systems which are still using
      * older versions, make them optional. */
@@ -273,6 +277,11 @@
     /* Straight up version number */
     PyModule_AddIntConstant(module, "OPENSSL_VERSION_NUMBER", OPENSSL_VERSION_NUMBER);
 
+    /* SSL modes constants */
+#ifdef SSL_MODE_RELEASE_BUFFERS
+    PyModule_AddIntConstant(module, "MODE_RELEASE_BUFFERS", SSL_MODE_RELEASE_BUFFERS);
+#endif
+
     if (!init_ssl_context(module))
         goto error;
     if (!init_ssl_connection(module))